1.使R1,R2,R3,R4全网建立BGP,并且互通
(1)将R3加入BGP中
R1:
r1(config)#router bgp 1
r1(config-router)#neighbor 3.3.3.3 remote-as 1
r1(config-router)#neighbor 3.3.3.3 update-source loopback 0
R3:
r3(config)#router bgp 1
r3(config-router)#bgp router-id 3.3.3.3
r3(config-router)#neighbor 1.1.1.1 remote-as 1
r3(config-router)#neighbor 1.1.1.1 update-source loopback 0
r3(config-router)#neighbor 4.4.4.4 remote-as 4
r3(config-router)#neighbor 4.4.4.4 update-source loopback 0
r3(config-router)#neighbor 4.4.4.4 ebgp-multihop
R4:
r4(config)#router bgp 4
r4(config-router)#neighbor 3.3.3.3 remote-as 1
r4(config-router)#neighbor 3.3.3.3 update-source loopback 0
r4(config-router)#neighbor 3.3.3.3 ebgp-multihop
(2)查看R3的BGP邻居
r3#sh ip bg summary
BGP router identifier 3.3.3.3, local AS number 1
BGP table version is 4, main routing table version 4
3 network entries using 351 bytes of memory
3 path entries using 156 bytes of memory
3/2 BGP path/bestpath attribute entries using 372 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 903 total bytes of memory
BGP activity 3/0 prefixes, 3/0 paths, scan interval 60 secs
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
1.1.1.1 4 1 7 7 4 0 0 00:02:08 1
4.4.4.4 4 4 7 5 4 0 0 00:00:08 2
r3#
说明:R3已经与其它路由器建立BGP邻居。
2.改变AS 1内部下一跳
(1)查看R1的BGP路由表
r1#sh ip bgp
BGP table version is 6, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
* i44.4.4.0/24 4.4.4.4 0 100 0 4 i
*>i 4.4.4.4 0 100 0 4 i
r i100.1.1.0/24 4.4.4.4 0 100 0 4 i
r>i 4.4.4.4 0 100 0 4 i
r1#
说明:因为R1都是从iBGP收到的路由,所以到达R4的路由44.4.4.0的下一跳都为4.4.4.4,而没有被R2和R3改变。
(2)改变R2与R3对R1的下一跳为自己
r2(config)#router bgp 1
r2(config-router)#neighbor 1.1.1.1 next-hop-self
r3(config)#router bgp 1
r3(config-router)#neighbor 1.1.1.1 next-hop-self
(3)再次查看R1的BGP路由表
r1#sh ip bgp
BGP table version is 8, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
* i44.4.4.0/24 3.3.3.3 0 100 0 4 i
*>i 2.2.2.2 0 100 0 4 i
r i100.1.1.0/24 3.3.3.3 0 100 0 4 i
r>i 2.2.2.2 0 100 0 4 i
r1#
说明:学习到的路由44.4.4.0/24已经被R2和R3改为自己。
测试选路规则说明:
测试R1通过R2与R3到达R4的网段44.4.4.0/24的选路,
以及测试R4通过R2与R3到达R1的网段11.1.1.0/24的选路,
要测试的选路顺序为
1.最高Weight值
2.最高LOCAL_PREF值
3.本地发起路由
4.最短AS_PATH
5.最低Origin类型
6.最小MED值
7.eBGP优于iBGP
8.最小IGP metric到达下一跳的路由
9.负载均衡(如果开启的话)
10.如果下一跳都为eBGP,则选择最早学习到的路由(即时间最长的路由)
11.最低Router-ID下一跳
12.最短cluster list(如同AS_PATH)
13.最小下一跳的邻居地址
因为选路顺序为由上至下,当上一个属性已经比较出最优路径,则下一属性被忽略,所以我们实验从下往上修改来进行比较,因为改过下面的属性影响选路之后,只要再改上一条,就能再次影响选路,就能证明,上一条是比下一条优先的。
测试第13条 最小下一跳的邻居地址
说明:因为只有下一跳邻居的Router-ID相同的情况下,才会比较下一跳邻居的地址大小,所以先将R2与R3的Router-ID改为相同,以测试比较下一跳地址。
(1)修改R3的Router-ID与R2相同
r3(config)#router bgp 1
r3(config-router)#bgp router-id 2.2.2.2
r3(config-router)#
(2)查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 8, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
* i44.4.4.0/24 3.3.3.3 0 100 0 4 i
*>i 2.2.2.2 0 100 0 4 i
r i100.1.1.0/24 3.3.3.3 0 100 0 4 i
r>i 2.2.2.2 0 100 0 4 i
r1#
说明:R1到达网段44.4.4.0/24选则最小下一跳邻居R2为最优路径。
测试第12条 最短cluster list
说明:因为比较最短cluster list只在BGP Route Reflector (RR)环境中才有,所以此步跳过。
测试第11条 最低Router-ID下一跳
说明:选择下一跳有最小Router-ID的邻居为最优路径。
(1)修改R3的Router-ID
r3(config)#router bgp 1
r3(config-router)#bgp router-id 1.1.1.3
说明:将R3的Router-ID改为1.1.1.3
(2)查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 10, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
*>i44.4.4.0/24 3.3.3.3 0 100 0 4 i
* i 2.2.2.2 0 100 0 4 i
r>i100.1.1.0/24 3.3.3.3 0 100 0 4 i
r i 2.2.2.2 0 100 0 4 i
r1#
说明:因为R2的Router-ID为2.2.2.2,而R3的Router-ID为1.1.1.3,所以最小Router-ID的R3被选为最优路径。
测试第10条 如果下一跳都为eBGP,则选择最早学习到的路由(即时间最长的路由)
说明:因为只有下一跳都为eBGP,才比较选择最早学习到的路由,所以测试R4通过R2与R2到达11.1.1.0/24的选路。
(1)查看R4到达11.1.1.0/24的选路
r4#sh ip bgp
BGP table version is 7, local router ID is 4.4.4.4
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
* 11.1.1.0/24 3.3.3.3 0 1 i
*> 2.2.2.2 0 1 i
*> 22.2.2.0/24 2.2.2.2 0 0 1 ?
*> 44.4.4.0/24 0.0.0.0 0 32768 i
*> 100.1.1.0/24 0.0.0.0 0 32768 i
r4#
说明:R4选择R2到达11.1.1.0/24
(2)查看R2与R3的邻居时间
r4#sh ip bg summary
BGP router identifier 4.4.4.4, local AS number 4
BGP table version is 7, main routing table version 7
4 network entries using 404 bytes of memory
5 path entries using 240 bytes of memory
3 BGP path attribute entries using 180 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 848 total bytes of memory
BGP activity 5/1 prefixes, 8/3 paths, scan interval 60 secs
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
2.2.2.2 4 1 51 49 7 0 0 00:43:27 2
3.3.3.3 4 1 27 33 7 0 0 00:02:23 1
r4#
说明:因为R2的邻居时间比R3长,所以R2为最优路径。
(3)清除R2的邻居,以刷新邻居时间
r4(config)#router bgp 4
r4(config-router)#neighbor 2.2.2.2 shutdown
r4(config-router)#
*Mar 1 01:16:09.823: %BGP-5-ADJCHANGE: neighbor 2.2.2.2 Down Admin. shutdown
r4(config-router)#no neighbor 2.2.2.2 shutdown
r4(config-router)#
*Mar 1 01:16:37.452: %BGP-5-ADJCHANGE: neighbor 2.2.2.2 Up
r4(config-router)#
说明:将邻居R2断开,再建立,从而刷新邻居的建立时间。
(4)再次查看邻居的建立时间
r4#sh ip bg summary
BGP router identifier 4.4.4.4, local AS number 4
BGP table version is 10, main routing table version 10
4 network entries using 404 bytes of memory
5 path entries using 240 bytes of memory
3 BGP path attribute entries using 180 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 848 total bytes of memory
BGP activity 5/1 prefixes, 10/5 paths, scan interval 60 secs
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
2.2.2.2 4 1 57 55 10 0 0 00:00:27 2
3.3.3.3 4 1 28 36 10 0 0 00:03:45 1
r4#
说明:R3的邻居时间比R2长。
(5)再次查看R4到达11.1.1.0/24的选路
r4#sh ip bgp
BGP table version is 10, local router ID is 4.4.4.4
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
* 11.1.1.0/24 2.2.2.2 0 1 i
*> 3.3.3.3 0 1 i
*> 22.2.2.0/24 2.2.2.2 0 0 1 ?
*> 44.4.4.0/24 0.0.0.0 0 32768 i
*> 100.1.1.0/24 0.0.0.0 0 32768 i
r4#
说明:因为R3的邻居时间比R2长,所以选择了R3为最优路径。
测试第9条 BGP负载均衡
说明:只有在前面8条属性都相同的话,才能开启BGP的负载功能,前8条属性任何一条不同,都不能负载。
(1)查看R1到达44.4.4.0/24的选路
r1#sh ip route bgp
22.0.0.0/24 is subnetted, 1 subnets
B 22.2.2.0 [200/0] via 2.2.2.2, 00:38:33
44.0.0.0/24 is subnetted, 1 subnets
B 44.4.4.0 [200/0] via 3.3.3.3, 00:05:12
r1#
说明:R1到达44.4.0/24只走R3,默认没有负载。
(2)开启BGP负载功能
r1(config)#router bgp 1
r1(config-router)#maximum-paths ibgp 2
说明:因为两个下一跳都为iBGP,所以开启iBGP的负载功能。
(3)再次查看R1到达44.4.0/24的选路
r1#sh ip route bgp
22.0.0.0/24 is subnetted, 1 subnets
B 22.2.2.0 [200/0] via 2.2.2.2, 00:39:16
44.0.0.0/24 is subnetted, 1 subnets
B 44.4.4.0 [200/0] via 2.2.2.2, 00:00:18
[200/0] via 3.3.3.3, 00:00:18
r1#
说明:R1到达44.4.4.0/24已经执行负载。
(4)查看R4到达11.1.1.0/24的选路
r4#sh ip route bgp
22.0.0.0/24 is subnetted, 1 subnets
B 22.2.2.0 [20/0] via 2.2.2.2, 00:03:03
11.0.0.0/24 is subnetted, 1 subnets
B 11.1.1.0 [20/0] via 3.3.3.3, 00:03:31
r4#
说明:R4到达11.1.1.0/24没有负载。
(5)开启R4到达11.1.1.0/24的负载
r4(config)#router bgp 4
r4(config-router)#maximum-paths 2
说明:因为两个下一跳都为eBGP,所以开启eBGP的负载。
(6)再次查看R4到达11.1.1.0/24的选路
r4#sh ip route bgp
22.0.0.0/24 is subnetted, 1 subnets
B 22.2.2.0 [20/0] via 2.2.2.2, 00:03:33
11.0.0.0/24 is subnetted, 1 subnets
B 11.1.1.0 [20/0] via 2.2.2.2, 00:00:15
[20/0] via 3.3.3.3, 00:00:15
r4#
说明:R4到达11.1.1.0/24已经执行负载。
测试第8条 最小IGP metric到达下一跳的路由
说明:拥有最小IGP metric到达下一跳的路由为最优路径。
(1)查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 14, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
* i44.4.4.0/24 2.2.2.2 0 100 0 4 i
*>i 3.3.3.3 0 100 0 4 i
r i100.1.1.0/24 2.2.2.2 0 100 0 4 i
r>i 3.3.3.3 0 100 0 4 i
r1#
说明:R1选择R3到达44.4.0/24,但并不是因为IGP metric。
(2)查看到达两个下一跳R2与R3的IGP metric值
r1#sh 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, 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
34.0.0.0/24 is subnetted, 1 subnets
O 34.1.1.0 [110/2] via 13.1.1.3, 00:28:17, FastEthernet0/1
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/2] via 12.1.1.2, 00:28:17, FastEthernet0/0
100.0.0.0/24 is subnetted, 1 subnets
O 100.1.1.0 [110/3] via 12.1.1.2, 00:28:17, FastEthernet0/0
[110/3] via 13.1.1.3, 00:28:17, FastEthernet0/1
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/2] via 13.1.1.3, 00:28:18, FastEthernet0/1
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/3] via 12.1.1.2, 00:28:18, FastEthernet0/0
[110/3] via 13.1.1.3, 00:28:18, FastEthernet0/1
22.0.0.0/24 is subnetted, 1 subnets
B 22.2.2.0 [200/0] via 2.2.2.2, 00:41:12
24.0.0.0/24 is subnetted, 1 subnets
O 24.1.1.0 [110/2] via 12.1.1.2, 00:28:21, FastEthernet0/0
11.0.0.0/24 is subnetted, 1 subnets
C 11.1.1.0 is directly connected, Loopback11
12.0.0.0/24 is subnetted, 1 subnets
C 12.1.1.0 is directly connected, FastEthernet0/0
13.0.0.0/24 is subnetted, 1 subnets
C 13.1.1.0 is directly connected, FastEthernet0/1
44.0.0.0/24 is subnetted, 1 subnets
B 44.4.4.0 [200/0] via 2.2.2.2, 00:02:14
[200/0] via 3.3.3.3, 00:02:14
r1#
说明:到达两个下一跳R2与R3的IGP metric值相同。
(3)改大到达下一跳R3的IGP metric值,使最优路径走R2
r1(config)#int f0/1
r1(config-if)#ip ospf cost 2
(4)再次查看到达两个下一跳R2与R3的IGP metric值
r1#sh 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, 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
34.0.0.0/24 is subnetted, 1 subnets
O 34.1.1.0 [110/3] via 13.1.1.3, 00:01:10, FastEthernet0/1
[110/3] via 12.1.1.2, 00:01:10, FastEthernet0/0
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/2] via 12.1.1.2, 00:01:10, FastEthernet0/0
100.0.0.0/24 is subnetted, 1 subnets
O 100.1.1.0 [110/3] via 12.1.1.2, 00:01:10, FastEthernet0/0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/3] via 13.1.1.3, 00:01:11, FastEthernet0/1
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/3] via 12.1.1.2, 00:01:11, FastEthernet0/0
22.0.0.0/24 is subnetted, 1 subnets
B 22.2.2.0 [200/0] via 2.2.2.2, 00:43:18
24.0.0.0/24 is subnetted, 1 subnets
O 24.1.1.0 [110/2] via 12.1.1.2, 00:01:11, FastEthernet0/0
11.0.0.0/24 is subnetted, 1 subnets
C 11.1.1.0 is directly connected, Loopback11
12.0.0.0/24 is subnetted, 1 subnets
C 12.1.1.0 is directly connected, FastEthernet0/0
13.0.0.0/24 is subnetted, 1 subnets
C 13.1.1.0 is directly connected, FastEthernet0/1
44.0.0.0/24 is subnetted, 1 subnets
B 44.4.4.0 [200/0] via 2.2.2.2, 00:00:14
r1#
说明:到达R2的metric值为2,到达R3的metric值为3,大于R2。
(5)再次查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 16, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
*>i44.4.4.0/24 2.2.2.2 0 100 0 4 i
* i 3.3.3.3 0 100 0 4 i
r>i100.1.1.0/24 2.2.2.2 0 100 0 4 i
r i 3.3.3.3 0 100 0 4 i
r1#
说明:因为到达R2的IGP metric值比R3小,所以最优路径为R2。
测试第7条 eBGP优于iBGP
说明:因为没有两个下一跳同时存在eBGP和iBGP的,所以此步跳过。
测试第6条 最小MED值
说明:最小MED值的路由为最优路径,一条没有MED的路由,默认为0。
因为MED希望是在下一跳都为eBGP,也就是出AS时比较,但现在要证明,只要有MED值存在,无论邻居是何类型,都将比较MED值,所以选择比较R1到达44.4.4.0/24的选路。
(1)查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 16, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
*>i44.4.4.0/24 2.2.2.2 0 100 0 4 i
* i 3.3.3.3 0 100 0 4 i
r>i100.1.1.0/24 2.2.2.2 0 100 0 4 i
r i 3.3.3.3 0 100 0 4 i
r1#
说明:R2和R3的MED默认为0,相同。
(2)加大R2的MED值,使其走R3
r1(config)#access-list 44 permit 44.4.4.0
r1(config)#route-map med permit 10
r1(config-route-map)#match ip address 44
r1(config-route-map)#set metric 44
r1(config-route-map)#exit
r1(config)#route-map med permit 20
r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 route-map med in
自动刷新:
r1(config)#router bgp 1
r1(config-router)#neighbor 2.2.2.2 soft-reconfiguration inbound
说明:修改属性后,BGP无法得知,所以配置自动刷新策略,只能为in方向。
(3)再次查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 17, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
* i44.4.4.0/24 2.2.2.2 44 100 0 4 i
*>i 3.3.3.3 0 100 0 4 i
r>i100.1.1.0/24 2.2.2.2 0 100 0 4 i
r i 3.3.3.3 0 100 0 4 i
r1#
说明:因为R3的MED小于R2,所以R3为最优路径。
注:在R4上修改MED影响选路的方法不再举例。
测试第5条 最低Origin类型
说明:优先级为IGP优于EGP,EGP优于Incomplete,即IGP>EGP>Incomplete。
(1)查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 17, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
* i44.4.4.0/24 2.2.2.2 44 100 0 4 i
*>i 3.3.3.3 0 100 0 4 i
r>i100.1.1.0/24 2.2.2.2 0 100 0 4 i
r i 3.3.3.3 0 100 0 4 i
r1#
说明:两个下一跳邻居的origin属性都为IGP。
(2)将R3的origin属性改为incomplete,使其走R2
r1(config)#route-map ori permit 10
r1(config-route-map)#match ip address 44
r1(config-route-map)#set origin incomplete
r1(config)#route-map ori permit 20
r1(config)#router bgp 1
r1(config-router)#neighbor 3.3.3.3 route-map ori in
r1(config-router)#neighbor 3.3.3.3 soft-reconfiguration inbound
(3)再次查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 18, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
*>i44.4.4.0/24 2.2.2.2 44 100 0 4 i
* i 3.3.3.3 0 100 0 4 ?
r>i100.1.1.0/24 2.2.2.2 0 100 0 4 i
r i 3.3.3.3 0 100 0 4 i
r1#
说明:因为R3的origin属性为为incomplete,R2的origin属性为IGP,所以选R2为最优路径。
测试第4条最短AS_PATH
说明:修改AS_Path只能在eBGP邻居之间,iBGP邻居是不能改动AS_Path,所以测试R4通过eBGP邻居R2和R3到达11.1.1.0的选路。
(1)查看R4到达11.1.1.0/24的选路
r4#sh ip bgp
BGP table version is 14, local router ID is 4.4.4.4
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
* 11.1.1.0/24 2.2.2.2 0 1 i
*> 3.3.3.3 0 1 i
*> 22.2.2.0/24 2.2.2.2 0 0 1 ?
*> 44.4.4.0/24 0.0.0.0 0 32768 i
*> 100.1.1.0/24 0.0.0.0 0 32768 i
r4#
说明:R2与R3的AS_Path长短相同。
(2)加长R3路径上的AS_Path,使其走R2
r4(config)#access-list 3 permit 11.1.1.0
r4(config)#route-map as permit 10
r4(config-route-map)#match ip address 3
r4(config-route-map)#set as-path prepend 3
r4(config-route-map)#exit
r4(config)#route-map as permit 20
r4(config)#router bgp 4
r4(config-router)#neighbor 3.3.3.3 route-map as in
r4(config-router)#neighbor 3.3.3.3 soft-reconfiguration inbound
(3)再次查看R4到达11.1.1.0/24的选路
r4#sh ip bgp
BGP table version is 15, local router ID is 4.4.4.4
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
*> 11.1.1.0/24 2.2.2.2 0 1 i
* 3.3.3.3 0 3 1 i
*> 22.2.2.0/24 2.2.2.2 0 0 1 ?
*> 44.4.4.0/24 0.0.0.0 0 32768 i
*> 100.1.1.0/24 0.0.0.0 0 32768 i
r4#
说明:因为R3的AS_Path比R2长,所以最优路径选择R2。
测试第3条 本地发起路由
说明:因为一条路由是不是由本地引入BGP,无法修改,所以此步跳过。
测试第2条 最高LOCAL_PREF值
因为LOCAL_PREF希望是在下一跳都为iBGP,也就是AS内部比较,但现在要证明,只要有LOCAL_PREF值存在,无论邻居是何类型,都将比较LOCAL_PREF值,所以选择比较R4到达11.1.1.0/24的选路。
(1) 查看R4到达11.1.1.0/24的选路
r4#sh ip bgp
BGP table version is 15, local router ID is 4.4.4.4
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
*> 11.1.1.0/24 2.2.2.2 0 1 i
* 3.3.3.3 0 3 1 i
*> 22.2.2.0/24 2.2.2.2 0 0 1 ?
*> 44.4.4.0/24 0.0.0.0 0 32768 i
*> 100.1.1.0/24 0.0.0.0 0 32768 i
r4#
说明:R2为最优路径。
(2)改R3的LOCAL_PREF值比R2大,让其走R3
r4(config)#access-list 11 permit 11.1.1.0
r4(config)#route-map r3 permit 10
r4(config-route-map)#match ip address 11
r4(config-route-map)#set local-preference 3
r4(config-route-map)#exit
r4(config)#route-map r3 permit 20
r4(config)#route-map r2 permit 10
r4(config-route-map)#match ip address 11
r4(config-route-map)#set local-preference 2
r4(config-route-map)#exit
r4(config)#route-map r2 permit 20
r4(config)#router bgp 4
r4(config-router)#neighbor 3.3.3.3 route-map r3 in
r4(config-router)#neighbor 2.2.2.2 route-map r2 in
r4(config-router)#neighbor 2.2.2.2 soft-reconfiguration inbound
(3)再次查看R4到达11.1.1.0/24的选路
r4#sh ip bgp
BGP table version is 5, local router ID is 4.4.4.4
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
* 11.1.1.0/24 2.2.2.2 2 0 1 i
*> 3.3.3.3 3 0 1 i
*> 22.2.2.0/24 2.2.2.2 0 0 1 ?
*> 44.4.4.0/24 0.0.0.0 0 32768 i
*> 100.1.1.0/24 0.0.0.0 0 32768 i
r4#
说明:因为R3的LOCAL_PREF值比R2大,所以最优路径为R3。
注:在R1上修改LOCAL_PREF影响选路的方法不再举例。
测试第1条 最高Weight值
说明:可针对路由修改Weight值,也可针对整个邻居修改Weight值。
(1)查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 23, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
* i44.4.4.0/24 3.3.3.3 0 100 0 4 ?
*>i 2.2.2.2 44 100 0 4 i
r i100.1.1.0/24 3.3.3.3 0 100 0 4 i
r>i 2.2.2.2 0 100 0 4 i
r1#
说明:R2为最优路径。
(2)改大R3的weight值,使其走R3
r1(config)#router bgp 1
r1(config-router)#neighbor 3.3.3.3 weight 3
(3)再次查看R1到达44.4.4.0/24的选路
r1#sh ip bgp
BGP table version is 6, local router ID is 1.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
*> 11.1.1.0/24 0.0.0.0 0 32768 i
*>i22.2.2.0/24 2.2.2.2 0 100 0 ?
* i44.4.4.0/24 2.2.2.2 44 100 0 4 i
*>i 3.3.3.3 0 100 3 4 ?
r i100.1.1.0/24 2.2.2.2 0 100 0 4 i
r>i 3.3.3.3 0 100 3 4 i
r1#
说明:因为R3的weight值大于R2,所以R3为最优路径。
结论:可以证明,按照选路顺序,虽然改变了某个属性,从而改变了选路,但是前一个属性的改变,再次影响了选路,就表示顺序必须是由前往后,只有在前一个属性无法比出结果,才会比较后面一个,如果前面的属性已经比出结果,则后面的属性已经无关紧要了,所以以上选路规则顺序成立。
文章目录
- 1 1.使R1,R2,R3,R4全网建立BGP,并且互通
- 2 2.改变AS 1内部下一跳
- 3 测试选路规则说明:
- 4 测试第13条 最小下一跳的邻居地址
- 5 测试第12条 最短cluster list
- 6 测试第11条 最低Router-ID下一跳
- 7 测试第10条 如果下一跳都为eBGP,则选择最早学习到的路由(即时间最长的路由)
- 8 测试第9条 BGP负载均衡
- 9 测试第8条 最小IGP metric到达下一跳的路由
- 10 测试第7条 eBGP优于iBGP
- 11 测试第6条 最小MED值
- 12 测试第5条 最低Origin类型
- 13 测试第4条最短AS_PATH
- 14 测试第3条 本地发起路由
- 15 测试第2条 最高LOCAL_PREF值
- 16 测试第1条 最高Weight值
评论抢沙发