本节书摘来自异步社区《CCIE路由和交换认证考试指南(第5版) (第2卷)》一书中的第1章,第1.2节构建BGP邻居关系,作者 【美】那比克 科查理安(Narbik Kocharians) , 特里 文森(Terry Vinson) , 瑞克 格拉齐亚尼(Rick Graziani),更多章节内容可以访问云栖社区“异步社区”公众号查看

1.2 构建BGP邻居关系
BGP邻居之间需要构建TCP连接,并通过TCP连接发送BGP消息,特别是通过TCP连接发送包含路由信息的BGP更新(Update)消息。每台路由器都要显式配置邻居的IP地址,目的是通过这些定义来告诉邻居路由器将与哪个IP地址建立TCP连接。如果路由器收到了从非BGP邻居的源IP地址发送的TCP连接请求(BGP端口179),那么就会拒绝该请求。

建立了TCP连接之后,BGP就开始发送BGP打开(Open)消息。交换了一对BGP 打开消息之后,邻居就可以进入建立(established)状态,该状态是两个活跃BGP对等体所处的一种稳定状态,此时就可以交换BGP更新消息了。

本节将详细介绍BGP邻居建立过程中涉及的协议及配置信息,如果大家已经熟悉了这部分内容,那么就可以直接查看表1-2列出的一些关键知识点。

关键

表1-2 BGP邻居汇总表


7faf9ae4b03836ca0ab961219d28adf72531de57

1.2.1 内部BGP邻居
BGP路由器将每个邻居均视为iBGP对等体或eBGP对等体,由于每台BGP路由器都位于单个AS中,因而相应的邻居关系要么是与相同AS中的路由器建立的(iBGP邻居),要么是与其他AS中的路由器建立的(eBGP邻居)。这两种邻居关系的建立方式并无多大区别,但不同类型的邻居(iBGP或eBGP)在BGP更新进程以及向路由表添加路由的方式上存在较大差别。

iBGP对等体通常使用环回接口IP地址来建立BGP对等关系,从而获得更高的可用性。对于单个AS来说,其物理拓扑结构通常在每对路由器之间最少包含两条路由。如果BGP对等体使用接口IP地址来建立TCP连接,那么在该接口出现故障后,虽然两台路由器之间可能还有一条路由,但是低层的BGP TCP连接已经中断。只要两个BGP对等体之间拥有一条以上的路由,且通过这些路由均能到达对端路由器,那么使用环回接口IP地址建立对等关系将是最佳选择。

下面将通过一些案例来解释BGP邻居的配置方式以及相应的协议信息。首先来看例1-1,该例显示了一些基本的BGP配置信息,AS 123中的R1、R2及R3是iBGP对等体(如图1-2所示),本例配置了如下功能特性:

AS 123中的三台路由器之间将建立iBGP邻居关系(全网状连接);
R1将使用bgp router-id命令来配置其RID,而不是使用环回接口地址;
R3使用peer-group命令来配置邻居R1和R2,由于只要为对等体组(peer group)准备一套出站更新消息(向对等体组中的所有对等体发送相同的更新消息),因而能够大大减少配置命令并提高处理效率;
R1-R3之间的对等关系使用BGP MD5认证,该认证方式是Cisco IOS支持的唯一一种BGP认证方式。


82fea154aba7ded73f2489a298401cf42f5c3381

例1-1 基本的iBGP邻居配置

! R1 Config—R1 correctly sets its update-source to 1.1.1.1 for both R2 and R3,
! in order to match the R2 and R3 neighbor commands. The first three highlighted
! commands below were not typed, but added automatically as defaults by IOS 12.3
! in fact, IOS 12.3 docs imply that the defaults of sync and auto-summary at
! IOS 12.2 has changed to no sync and no auto-summary as of IOS 12.3. Also, R1
! knows that neighbors 2.2.2.2 and 3.3.3.3 are iBGP because their remote-as values
! match R1’s router BGP command.
interface Loopback1
 ip address 1.1.1.1 255.255.255.255
!
router bgp 123
 no synchronization
 bgp router-id 111.111.111.111
 bgp log-neighbor-changes
 neighbor 2.2.2.2 remote-as 123
 neighbor 2.2.2.2 update-source Loopback1
 neighbor 3.3.3.3 remote-as 123
 neighbor 3.3.3.3 password secret-pw
 neighbor 3.3.3.3 update-source Loopback1
 no auto-summary
! R3 Config—R3 uses a peer group called "my-as" for combining commands related
! to R1 and R2. Note that not all parameters must be in the peer group: R3-R2 does
! not use authentication, but R3-R1 does, so the neighbor password command was
! not placed inside the peer group, but instead on a neighbor 1.1.1.1 command.
interface Loopback1
 ip address 3.3.3.3 255.255.255.255
!
router bgp 123
 no synchronization
 bgp log-neighbor-changes
 neighbor my-as peer-group
 neighbor my-as remote-as 123
 neighbor my-as update-source Loopback1
 neighbor 1.1.1.1 peer-group my-as
 neighbor 1.1.1.1 password secret-pw
 neighbor 2.2.2.2 peer-group my-as
 no auto-summary
! Next, R1 has two established peers, but the fact that the status is "established"
! is implied by not having the state listed on the right side of the output, under
! the heading State/PfxRcd. Once established, that column lists the number of
! prefixes learned via BGP Updates received from each peer. Note also R1’s
! configured RID, and the fact that it is not used as the update source.
R1# show ip bgp summary
BGP router identifier 111.111.111.111 , local AS number 123
BGP table version is 1, main routing table version 1
Neighbor  V   AS   MsgRcvd    MsgSent  TblVer   InQ   OutQ  Up/Down     State/PfxRcd
2.2.2.2   4  123        59        59        0    0       0  00:56:52          0
3.3.3.3   4  123        64        64        0    0       0  00:11:14          0

例1-1给出了一些非常重要的功能特性。首先,该配置并没有显式地将对等体定义为iBGP对等体或eBGP对等体,而是由每台路由器检查自己的ASN(定义在router bgp命令中),并与neighbor remote-as命令中列出的邻居ASN进行比较,如果匹配,那么就是iBGP对等体,否则就是eBGP对等体。

例1-1中的R3显示了利用peer-group命令建立对等体组以减少配置命令的配置方式。请注意,不能在BGP对等体组中设置任何新的BGP配置,只能简单地将这些BGP邻居配置组合为一个组,然后利用neighbor peer-group命令将该组设置应用到邻居上。此外,BGP会为对等体组构建一套更新消息,并将路由策略应用到整个对等体组上(而不是每次仅用于一台路由器),因而能够大大减轻BGP的处理压力及内存开销。

1.2.2 外部BGP邻居
eBGP对等体之间的物理拓扑结构通常都是单链路,主要原因在于该连接是不同自治系统中的不同企业之间的连接,因而eBGP对等关系可以简单地使用接口IP地址来实现冗余性,这是因为链路失效后,TCP连接也将中断(因为此时的对等体之间已经没有IP路由了)。例如,图1-2中的R1-R6 eBGP对等关系使用的就是neighbor命令中定义的接口IP地址。

如果两个eBGP对等体之间拥有冗余连接,那么eBGP neighbor命令就应该使用环回IP地址以充分利用冗余连接。例如,R3和R4之间拥有两条并行链路,如果在neighbor命令中使用环回地址,那么即使这两条链路中有一条出现了故障,TCP连接仍然能够保持正常运行。例1-2给出了图1-2所示网络的额外配置信息,即在R3与R4之间使用环回接口地址,而在R1与R6之间使用接口地址。

例1-2 基本的eBGP邻居配置

! R1 Config -This example shows only commands added since Example 1-1 .
router bgp 123
 neighbor 172.16.16.6 remote-as 678
! R1 does not have a neighbor 172.16.16.6 update-source command configured. R1
! uses its s0/0/0.6 IP address, 172.16.16.1, because R1’s route to 172.16.16.6
! uses s0/0/0.6 as the outgoing interface, as seen below.
R1# show ip route 172.16.16.6
Routing entry for 172.16.16.0/24
  Known via "connected", distance 0, metric 0 (connected, via interface)
  Routing Descriptor Blocks:
  * directly connected, via Serial0/0/0.6
     Route metric is 0, traffic share count is 1
R1# show ip int brief | include 0/0/0.6
Serial0/0/0.6               172.16.16.1                    YES manual up           up
! R3 Config—Because R3 refers to R4’s loopback (4.4.4.4), and R4 is an eBGP
! peer, R3 and R4 have added the neighbor ebgp-multihop command to set TTL to 2.
! R3’s update source must be identified as its loopback in order to match
! R4’s neighbor 3.3.3.3 commands.
router bgp 123
 neighbor 4.4.4.4 remote-as 45
 neighbor 4.4.4.4 update-source loopback1
 neighbor 4.4.4.4 ebgp-multihop 2
! R3 now has three working neighbors. Also note the three TCP connections, one for
! each BGP peer. Note that because R3 is listed using a dynamic port number, and
! R4 as using port 179, R3 actually initiated the TCP connection to R4.
R3# show ip bgp summary
BGP router identifier 3.3.3.3, local AS number 123
BGP table version is 1, main routing table version 1
Neighbor  V   AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
1.1.1.1   4  123     247      247       0     0    0  03:14:49         0
2.2.2.2   4  123     263      263       0     0    0  03:15:07         0
4.4.4.4   4  45       17       17       0     0    0  00:00:11         0
R3# show tcp brief
TCB       Local Address      Foreign Address        (state)
649DD08C 3.3.3.3.179         2.2.2.2.43521          ESTAB
649DD550 3.3.3.3.179         1.1.1.1.27222          ESTAB
647D928C 3.3.3.3.21449      4.4.4.4.179             ESTAB

从例1-2可以看出,eBGP配置与iBGP配置之间存在一些细微差别。首先,与route bgp命令不同,neighbor remote-as命令引用的是不同的AS,因而意味着对等体是eBGP对等体。其次,R3必须配置neighbor 4.4.4.4 ebgp-multihop 2命令(R4的命令相似),否则将无法建立对等连接。对于eBGP连接来说,Cisco IOS默认将IP包的TTL字段设置为数值1,其依据是假定使用接口IP地址建立对等连接(如例1-2中的R1-R6所示)。对于本例来说,如果R3没有使用多跳特性,那么就会以TTL 1向R4发送数据包,R4收到数据包之后(此时TTL为1),会将数据包路由到自己的环回接口,该过程会将TTL递减至0,导致R4丢弃该数据包。因此,即使路由器仅在一跳之外,也要将环回接口视为位于路由器的另一端,需要额外的跳数。

1.2.3 成为BGP邻居之前的检查操作
与IGP相似,在其他路由器成为邻居(进入BGP建立状态)之前,BGP也要执行一些必要的检查操作,此时大多数设置都比较直观,唯一容易出错的地方就是IP地址问题。下面列出了BGP构建邻居关系时需要执行的一些检查操作。

关键

1.路由器必须收到一条TCP连接请求,且路由器必须在BGP neighbor命令中能够发现该请求的源地址。

2.路由器的ASN(位于router bgp asn命令中)必须与邻居路由器在其neighbor remote-as asn命令中引用的ASN相匹配(联盟配置无此要求)。

3.两台路由器的BGP RID必须相同。

4.如果配置了认证机制,那么还必须通过MD5认证。

图1-3给出了上述检查操作中前3项的检查过程,R3向R1发起BGP TCP连接请求,带圆圈的数字1、2、3分别对应于上述检查操作中的前3项。请注意,R1在第2步检查操作中使用的neighbor命令是R1在第1步中确定的。


1dd89b5c9f4c236342f7edfd46a1045295bca21c

图1-3中的R3以其更新源IP地址(3.3.3.3)为数据包的源地址发起了一条TCP连接请求,第一项检查操作发生在R1收到第一个数据包的时候,需要查看数据包的源IP地址(3.3.3.3),发现该地址位于neighbor命令中。第二项检查是R1将R3宣称的ASN(位于R3的BGP打开消息中)与R1的neighbor命令(在第1步中确定的)进行对比。第三项检查的目的是确定BGP RID的唯一性,利用BGP打开消息来宣告发送端的BGP RID。

虽然第1步检查操作看起来很直观,但有趣的是,即使反向检查操作通不过,也能建立邻居关系。例如,即使R1没有配置neighbor 3.3.3.3 update-source 1.1.1.1命令,图1-3所示的进程也能正常运行。也就是说,只要两台路由器的更新源IP地址中有一个位于对端路由器的neighbor命令中,就能建立邻居关系。例1-1和例1-2显示了这两台路由器正确的更新源地址,这种情况当然没问题,只要其中一个正确就可以建立邻居关系。

关键

BGP利用保持激活定时器来定义路由器发送保持激活消息的频率,利用保持定时器(Hold timer)来定义路由器在重置邻居连接之前等待接收保持激活消息的时间。打开消息包含了每台路由器宣称的保持激活定时器,如果不匹配,那么每台路由器都将为这两个定时器使用较小值。参数设置不匹配不会妨碍路由器成为邻居。

1.2.4 BGP消息与邻居状态
BGP邻居的期望状态是建立状态,此状态下的路由器已经建立了TCP连接,交换了打开消息,而且参数检查也全部通过,此时可以利用更新消息交换拓扑结构信息。表1-3列出了可能的BGP邻居状态及相应的状态特性。请注意,如果IP地址不匹配,那么邻居将进入Active(激活)状态。


d925476dffd729ec2f0b75c3d1e4ceec91db3bc4

1.BGP消息类型
BGP使用4种基本消息,表1-4列出了这些消息类型并给出了相应的描述信息。


6f0b0a04030139092a4db41e5e7406b69db10fb5

2.主动重置BGP对等连接
例1-3显示了利用neighbor shutdown命令重置邻居连接的方式,同时给出了各种BGP邻居状态。本例中的路由器R1和R6来自图1-2,相应的配置信息见例1-2。

例1-3 邻居状态示例

! R1 shuts down R6’s peer connection. debug ip bgp shows moving to a down state,
! which shows as "Idle (Admin)" under show ip bgp summary .
R1# debug ip bgp
BGP debugging is on for address family: BGP IPv4
R1# conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)# router bgp 123
R1(config-router)# neigh 172.16.16.6 shutdown
R1#
*Mar 4 21:01:45.946: BGP: 172.16.16.6 went from Established to Idle
*Mar 4 21:01:45.946: %BGP-5-ADJCHANGE: neighbor 172.16.16.6 Down Admin. shutdown
*Mar 4 21:01:45.946: BGP: 172.16.16.6 closing
R1# show ip bgp summary | include 172.16.16.6
172.16.16.6    4     678     353     353     0  0  0  00:00:06 Idle (Admin)
! Next, the no neighbor shutdown command reverses the admin state. The various
! debug messages (with some omitted) list the various states. Also note that the
! final message is the one log message in this example that occurs due to the
! default configuration of bgp log-neighbor-changes . The rest are the result of
! a debug ip bgp command.
R1# conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)# router bgp 123
R1(config-router)# no neigh 172.16.16.6 shutdown
*Mar 4 21:02:16.958: BGP: 172.16.16.6 went from Idle to Active
*Mar 4 21:02:16.958: BGP: 172.16.16.6 open active , delay 15571ms
*Mar 4 21:02:29.378: BGP: 172.16.16.6 went from Idle to Connect
*Mar 4 21:02:29.382: BGP: 172.16.16.6 rcv message type 1, length (excl. header) 26
*Mar 4 21:02:29.382: BGP: 172.16.16.6 rcv OPEN , version 4, holdtime 180 seconds
*Mar 4 21:02:29.382: BGP: 172.16.16.6 went from Connect to OpenSent
*Mar 4 21:02:29.382: BGP: 172.16.16.6 sending OPEN , version 4, my as: 123 ,
  holdtime 180 seconds
*Mar 4 21:02:29.382: BGP: 172.16.16.6 rcv OPEN w/ OPTION parameter len: 16
BGP: 172.16.16.6 rcvd OPEN w/ remote AS 678
*Mar 4 21:02:29.382: BGP: 172.16.16.6 went from OpenSent to OpenConfirm
*Mar 4 21:02:29.382: BGP: 172.16.16.6 send message type 1, length (incl. header)
  45
*Mar 4 21:02:29.394: BGP: 172.16.16.6 went from OpenConfirm to Established
*Mar 4 21:02:29.398: %BGP-5-ADJCHANGE: neighbor 10.16.16.6 Up

与neighbor shutdown命令相似,EXEC命令clear ip bgp *也能重置所有BGP邻居,该命令可以重置邻居连接、关闭与该邻居之间的TCP连接并删除BGP表中学自该邻居的所有表项。本章还会在后面显示clear命令的其他使用方式,包括同时清除多个邻居的方式。

注:

利用软重配(soft reconfiguration)特性,clear命令可以在不完全重置邻居的情况下实现路由策略的变更操作。有关软重配特性的详细信息,请参见第2章的“软重配”一节。

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐