且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CCNP-33 BGP 3

更新时间:2022-10-03 19:50:02

CCNP-33 BGP 3

实验拓扑:
CCNP-33 BGP 3
实验要求:按照拓扑图将三台路由器分别放置在AS 100/200/300中,首先配置R1R2 R3成为EBGP PEER,观察BGP路由表中的AS PATH属性,然后再将R2R3也配置为EBGP PEER,再观察BGP路由表中的AS PATH属性,看看有什么变化。
试验目的:掌握AS PATH属性在BGP路由选择中的作用。

试验配置:
R1
R1(config)#int f0/0
R1(config-if)#ip add 192.1.1.1 255.255.255.0
R1(config-if)#no shu
R1(config-if)#exit
R1(config)#int loop0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#exit
R1(config-if)#ip add 10.1.1.1 255.255.255.0
R1(config-if)#exit
R1(config)#router bgp 100
R1(config-router)#nei
R1(config-router)#neighbor 192.1.1.2 remote-as 200
R1(config-router)#network 10.1.1.0 mask 255.255.255.0
R1(config-router)#exit
 
R2
R2(config-if)#no shu
R2(config-if)#exit
R2(config)#int f1/0
R2(config-if)#ip add 193.1.1.1 255.255.255.0
R2(config-if)#no shu
R2(config-if)#exit
R2(config)#int loop0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config-if)#exit
R2(config)#router bgp 200
R2(config-router)#neighbor 192.1.1.1 remote-as 100
R2(config-router)#neighbor 193.1.1.2 remote-as 300
R2(config-router)#network 192.1.1.0
R2(config-router)#network 193.1.1.0
R2(config-router)#exit
 
R3
R3(config)#int f1/0
R3(config-if)#ip add 193.1.1.2 255.255.255.0
R3(config-if)#no shu
R3(config-if)#exit
R3(config)#int loop0
R3(config-if)#ip add 3.3.3.3 255.255.255.0
R3(config-if)#exit
R3(config)#router bgp 300
R3(config-router)#neighbor 193.1.1.1 remote-as 200
R3(config-router)#exit
好了,配置完成,然后我们在R3上查看BGP路由表:
R3#show ip bgp
BGP table version is 5, local router ID is 3.3.3.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
 
   Network          Next Hop            Metric LocPrf Weight Path
*> 10.1.1.0/24      193.1.1.1                              0 200 100 i
*> 192.1.1.0        193.1.1.1                0             0 200 i
r> 193.1.1.0        193.1.1.1                0             0 200 i
观察第一行我们发现在Path这一列有200 100的标示,说明学习这条路由的路径是       AS 100----AS 200----AS 300
通过AS PATH属性,明白的表示出一条路由传播路径,这也是BGP预防环路发生的一种
法,如果发现传播过来的路由的AS PATH属性里面列出了本地的AS号,路由器就认为这条路由已经学习过了,并且形成了一个环,然后这条路由信息将被丢弃。
上面第三行有”r”标志的路由信息说明这条路又没有被写入路由表,原因可以通过命令
show ip bgp rib-failure来查看:
R3#show ip bgp rib-failure
Network            Next Hop                      RIB-failure   RIB-NH Matches
193.1.1.0          193.1.1.1           Higher admin distance              n/a
 
Higher admin distance表示较高的管理距离,因为193.1.1.0这个网段是直连网段,管理距离为0,而EBGP的管理距离为20,在路由表选择写入的路由的时候如果有两种路由协议都有到达某个网段的信息,那么选择管理距离较低的写入路由表,这里是将直连路由写入了路由表,R3的路由表为:
R3#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
 
Gateway of last resort is not set
 
     3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, Loopback0
     10.0.0.0/24 is subnetted, 1 subnets
B       10.1.1.0 [20/0] via 193.1.1.1, 00:02:02
C    193.1.1.0/24 is directly connected, FastEthernet1/0
B    192.1.1.0/24 [20/0] via 193.1.1.1, 00:00:59
有两条以B表示的路由,这表示是从BGP学习到的,我们可以ping测试一下:
R3#p 10.1.1.1
 
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 96/182/276 ms
好的,通了。
下面我们配置R1,R3,使之也成为EBGP PEER
R1(config)#int f1/0
R1(config-if)#ip add 194.1.1.1 255.255.255.0
R1(config-if)#no shu
R1(config-if)#exit
R1(config)#router bgp 100
R1(config-router)#neighbor 194.1.1.2 remote-as 300
R1(config-router)#exit
 
R3(config)#int f0/0
R3(config-if)#ip add 194.1.1.2 255.255.255.0
R3(config-if)#no shu
R3(config-if)#exit
R3(config)#router bgp 300
R3(config-router)#neighbor 194.1.1.1 remote-as 100
R3(config-router)#exit
好了,我们clear ip bgp *强制重起一下BGP进程,再观察R3上的BGP路由表:
R3#show ip bgp
BGP table version is 6, local router ID is 3.3.3.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
 
   Network          Next Hop            Metric LocPrf Weight Path
*> 10.1.1.0/24      194.1.1.1                0             0 100 i
*                   193.1.1.1                              0 200 100 i
*  192.1.1.0        194.1.1.1                              0 100 200 i
*>                  193.1.1.1                0             0 200 i
r  193.1.1.0        194.1.1.1                              0 100 200 i
r>                  193.1.1.1                0             0 200 i
看到变化了吧!我们来逐条进行分析:
*> 10.1.1.0/24      194.1.1.1                0             0 100 i
*                   193.1.1.1                              0 200 100 i
首先看前两行都是到10.1.1.0/24的路由,但是***路由是从194.1.1.1学到的,因为它的AS PATH只经过AS 100这一个自治系统,但是从193.1.1.1学到的要经过AS 100/200两个自治系统,也就是说BGP在选路的时候选择经过的AS最少的那条路由作为***路由;
*  192.1.1.0        194.1.1.1                              0 100 200 i
*>                  193.1.1.1                0             0 200 i
然后再来比较这两条路由,同样都是到达192.1.1.0的路由,也同样是选择了AS PATH最少的作为***路由写入路由表;
r  193.1.1.0        194.1.1.1                              0 100 200 i
r>                  193.1.1.1                0             0 200 i
最后的这两条都是标记了r的,也就是没有写入路由表,是因为193.1.1.0这个网段是自己直连的网段,不管从哪个AS中学到的,因为管理距离的原因,都会将直连路由写入路由表,放弃从BGP学到的相同网段的路由。
我们再来看一下R1BGP路由表和IP路由表:
R1#show ip bgp
BGP table version is 5, local router ID is 10.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
 
   Network          Next Hop            Metric LocPrf Weight Path
*> 10.1.1.0/24      0.0.0.0                  0         32768 i
r  192.1.1.0        194.1.1.2                              0 300 200 i
r>                  192.1.1.2                0             0 200 i
*  193.1.1.0        194.1.1.2                              0 300 200 i
*>                  192.1.1.2                0             0 200 i
 
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
 
Gateway of last resort is not set
 
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     10.0.0.0/24 is subnetted, 1 subnets
C       10.1.1.0 is directly connected, Loopback1
B    193.1.1.0/24 [20/0] via 192.1.1.2, 00:37:21
C    192.1.1.0/24 is directly connected, FastEthernet0/0
C    194.1.1.0/24 is directly connected, FastEthernet1/0
我们只看最后到193.1.1.0这个网段的路由,下一条属性为192.1.1.2,这是因为我们向BGP通告193.1.1.0这个网段是在R2上做的,如果我们取消这条路由在R2上的通告,而在R3上通告这条路由的话,R1BGP路由表和IP路由表又会是什么样子的呢?
我们可以根据BGP选路的特点来假想一下,如果在R3上通告193.1.1.0/24这条路由的话,那么R1BGP路由表有关这条路由的下一跳属性将会变为194.1.1.2AS PATH属性AS 300,并且路由表也将随之变化,还有R2上的BGP路由表也将发生变化,会有一条到193.1.1.0被标记为”r”的路由,AS PATH属性为AS 300我们可以来做一下试验,验证一下我们的猜测是否正确:
作更改前R2BGP路由表:
R2#show ip bgp
BGP table version is 4, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
 
   Network          Next Hop            Metric LocPrf Weight Path
*> 10.1.1.0/24      192.1.1.1                0             0 100 i
*> 192.1.1.0        0.0.0.0                  0         32768 i
*> 193.1.1.0        0.0.0.0                  0         32768 i
193.1.1.0是自己产生的路由,然后开始更改R2R3的配置:
R1#show ip bgp
BGP table version is 8, local router ID is 10.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
 
   Network          Next Hop            Metric LocPrf Weight Path
*> 10.1.1.0/24      0.0.0.0                  0         32768 i
r  192.1.1.0        194.1.1.2                              0 300 200 i
r>                  192.1.1.2                0             0 200 i
*  193.1.1.0        192.1.1.2                              0 200 300 i
*>                  194.1.1.2                0             0 300 i
以上为R1BGP路由表;
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
 
Gateway of last resort is not set
 
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     10.0.0.0/24 is subnetted, 1 subnets
C       10.1.1.0 is directly connected, Loopback1
B    193.1.1.0/24 [20/0] via 194.1.1.2, 00:04:59
C    192.1.1.0/24 is directly connected, FastEthernet0/0
C    194.1.1.0/24 is directly connected, FastEthernet1/0
以上为R1的路由表;
R2#show ip bgp
BGP table version is 5, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
 
   Network          Next Hop            Metric LocPrf Weight Path
*  10.1.1.0/24      193.1.1.2                              0 300 100 i
*>                  192.1.1.1                0             0 100 i
*> 192.1.1.0        0.0.0.0                  0         32768 i
r> 193.1.1.0        193.1.1.2                0             0 300 i
r                   192.1.1.1                              0 100 300 i
以上为R2BGP路由表。
上面的输出显示和我们根据BGP选路的条件推断出来的是一样的。

实验总结:掌握AS PATH属性在BGP路由选择时的作用。



























本文转自loveme2351CTO博客,原文链接:http://blog.51cto.com/loveme23/54224 ,如需转载请自行联系原作者