R1#ping 2.2.2.2 so 1.1.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds: Packet sent with a source address of 1.1.1.1 !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
R5#sh ip bgp Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 2.2.2.2 0 100 0 100 i *> 6.6.6.0/24 192.168.56.6 0 0 300 i
查看R5的路由表
1 2 3 4 5
R5#sh ip route bgp 1.0.0.0/24 is subnetted, 1 subnets B 1.1.1.0 [200/0] via 2.2.2.2, 00:00:34 6.0.0.0/24 is subnetted, 1 subnets B 6.6.6.0 [20/0] via 192.168.56.6, 00:06:44
查看R1和R6的路由表
1 2 3 4 5 6 7
R1#show ip route bgp 6.0.0.0/24 is subnetted, 1 subnets B 6.6.6.0 [20/0] via 192.168.12.2, 00:00:40 ========================= R6#sh ip route bgp 1.0.0.0/24 is subnetted, 1 subnets B 1.1.1.0 [20/0] via 192.168.56.5, 00:01:16
R5#show ip bgp BGP table version is 11, local router ID is 5.5.5.5 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 2.2.2.2 0 100 0 100 i *> 6.6.6.0/24 6.6.6.6 0 0 300 i
R3#sh ip route bgp 1.0.0.0/24 is subnetted, 1 subnets B 1.1.1.0 [200/0] via 2.2.2.2, 00:03:29 6.0.0.0/24 is subnetted, 1 subnets B 6.6.6.0 [200/0] via 5.5.5.5, 00:01:30 ============================= R4#sh ip route bgp 1.0.0.0/24 is subnetted, 1 subnets B 1.1.1.0 [200/0] via 2.2.2.2, 00:02:00 6.0.0.0/24 is subnetted, 1 subnets B 6.6.6.0 [200/0] via 5.5.5.5, 00:01:50
下面检查R1–R6连通性
1 2 3 4 5 6
R1#ping 6.6.6.6 so 1.1.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 6.6.6.6, timeout is 2 seconds: Packet sent with a source address of 1.1.1.1 ..... Success rate is 0 percent (0/5)
R1#ping 6.6.6.6 so 1.1.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 6.6.6.6, timeout is 2 seconds: Packet sent with a source address of 1.1.1.1 !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
R3#sh ip route ospf 1.0.0.0/24 is subnetted, 1 subnets O E2 1.1.1.0 [110/1] via 192.168.23.2, 00:01:01, Ethernet0/0 2.0.0.0/32 is subnetted, 1 subnets O 2.2.2.2 [110/11] via 192.168.23.2, 00:05:10, Ethernet0/0 4.0.0.0/32 is subnetted, 1 subnets O 4.4.4.4 [110/21] via 192.168.35.5, 00:05:10, Ethernet0/1 [110/21] via 192.168.23.2, 00:05:10, Ethernet0/0 5.0.0.0/32 is subnetted, 1 subnets O 5.5.5.5 [110/11] via 192.168.35.5, 00:05:10, Ethernet0/1 6.0.0.0/24 is subnetted, 1 subnets O E2 6.6.6.0 [110/1] via 192.168.35.5, 00:00:40, Ethernet0/1 O 192.168.24.0/24 [110/20] via 192.168.23.2, 00:05:10, Ethernet0/0 O 192.168.45.0/24 [110/20] via 192.168.35.5, 00:05:10, Ethernet0/1 ==================== R4#sh ip route ospf 1.0.0.0/24 is subnetted, 1 subnets O E2 1.1.1.0 [110/1] via 192.168.24.2, 00:01:18, Ethernet0/0 2.0.0.0/32 is subnetted, 1 subnets O 2.2.2.2 [110/11] via 192.168.24.2, 00:05:24, Ethernet0/0 3.0.0.0/32 is subnetted, 1 subnets O 3.3.3.3 [110/21] via 192.168.45.5, 00:05:24, Ethernet0/1 [110/21] via 192.168.24.2, 00:05:24, Ethernet0/0 5.0.0.0/32 is subnetted, 1 subnets O 5.5.5.5 [110/11] via 192.168.45.5, 00:05:24, Ethernet0/1 6.0.0.0/24 is subnetted, 1 subnets O E2 6.6.6.0 [110/1] via 192.168.45.5, 00:00:57, Ethernet0/1 O 192.168.23.0/24 [110/20] via 192.168.24.2, 00:05:24, Ethernet0/0 O 192.168.35.0/24 [110/20] via 192.168.45.5, 00:05:24, Ethernet0/1
检查连通性
1 2 3 4 5 6
R1#ping 6.6.6.6 so 1.1.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 6.6.6.6, timeout is 2 seconds: Packet sent with a source address of 1.1.1.1 !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
R2&R4&R5 router bgp 200 nei 3.3.3.3 remote 200 nei 3.3.3.3 up lo0 nei 3.3.3.3 next-hop-s # R4不需要这条 =============== R3 R3(config)#router bgp 200 R3(config-router)#nei as200 peer R3(config-router)#nei as200 remote 200 R3(config-router)#nei as200 up lo0 R3(config-router)#nei as200 route-reflector-client R3(config-router)#nei 2.2.2.2 peer as200 R3(config-router)#nei 4.4.4.4 peer as200 R3(config-router)#nei 5.5.5.5 peer as200
检查连通性
1 2 3 4 5 6
R1#ping 6.6.6.6 so 1.1.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 6.6.6.6, timeout is 2 seconds: Packet sent with a source address of 1.1.1.1 !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
===============R1=============== interface Loopback0 no shutdown ip address 1.1.1.1 255.255.255.0 ! interface Ethernet0/0 no shutdown ip address 192.168.12.1 255.255.255.0 ! interface Ethernet0/1 no shutdown ip address 192.168.13.1 255.255.255.0
ip route 2.2.2.2 255.255.255.255 192.168.12.2 ip route 3.3.3.3 255.255.255.255 192.168.13.3 ===============R2=============== interface Loopback0 no shutdown ip address 2.2.2.2 255.255.255.0 ! interface Ethernet0/0 no shutdown ip address 192.168.12.2 255.255.255.0 ! interface Ethernet0/1 no shutdown ip address 192.168.24.2 255.255.255.0
ip route 1.1.1.1 255.255.255.255 192.168.12.1 ip route 4.4.4.4 255.255.255.255 192.168.24.4 ===============R3=============== interface Loopback0 no shutdown ip address 3.3.3.3 255.255.255.0 ! interface Ethernet0/0 no shutdown ip address 192.168.13.3 255.255.255.0 ! interface Ethernet0/1 no shutdown ip address 192.168.35.3 255.255.255.0
ip route 1.1.1.1 255.255.255.255 192.168.13.1 ip route 5.5.5.5 255.255.255.255 192.168.35.5 ===============R4=============== interface Loopback0 no shutdown ip address 4.4.4.4 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/0 no shutdown ip address 192.168.24.4 255.255.255.0 ! interface Ethernet0/1 no shutdown ip address 192.168.45.4 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/2 no shutdown ip address 192.168.46.4 255.255.255.0 ip ospf 1 area 0
ip route 2.2.2.2 255.255.255.255 192.168.24.2 ===============R5=============== interface Loopback0 no shutdown ip address 5.5.5.5 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/0 no shutdown ip address 192.168.45.5 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/1 no shutdown ip address 192.168.35.5 255.255.255.0 ! interface Ethernet0/2 no shutdown ip address 192.168.56.5 255.255.255.0 ip ospf 1 area 0
ip route 3.3.3.3 255.255.255.255 192.168.35.3 ===============R6=============== interface Loopback0 no shutdown ip address 6.6.6.6 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/0 no shutdown ip address 192.168.46.6 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/1 no shutdown ip address 192.168.56.6 255.255.255.0 ip ospf 1 area 0
R4#sh ip bgp Network Next Hop Metric LocPrf Weight Path * i 1.1.1.0/24 5.5.5.5 0 100 0 300 100 i *> 2.2.2.2 0 200 100 i *> 2.2.2.0/24 2.2.2.2 0 0 200 i *>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i *> 4.4.4.0/24 0.0.0.0 0 32768 i *>i 5.5.5.0/24 5.5.5.5 0 100 0 i
我们修改5.5.5.5这条路线的权重,可以影响R4的选路
1 2 3 4 5 6 7 8 9 10 11
R4(config)#router bgp 450 R4(config-router)#nei 5.5.5.5 weight 10 R4#clear ip bgp * so in R4#show ip bgp Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 5.5.5.5 0 100 10 300 100 i * 2.2.2.2 0 200 100 i *> 2.2.2.0/24 2.2.2.2 0 0 200 i *>i 3.3.3.0/24 5.5.5.5 0 100 10 300 i *> 4.4.4.0/24 0.0.0.0 0 32768 i *>i 5.5.5.0/24 5.5.5.5 0 100 10 i
可以看到凡是5.5.5.5学习的条目权重都被修改了,影响整个邻居,正常情况下不推荐使用。
1 2
R4(config)#router bgp 450 R4(config-router)#no nei 5.5.5.5 weight 10
可以使用route-map对特定路由的权重进行修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
R4(config)#access-list 1 permit 1.1.1.0
R4(config)#route-map R5 per R4(config-route-map)#mat ip ad 1 R4(config-route-map)#set weight 10 R4(config)#route-map R5 per 20
R4(config)#router bgp 450 R4(config-router)#nei 5.5.5.5 route-map R5 in R4(config-router)#do clea ip bgp * so in R4(config-router)#do sh ip bgp Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 5.5.5.5 0 100 10 300 100 i * 2.2.2.2 0 200 100 i *> 2.2.2.0/24 2.2.2.2 0 0 200 i *>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i *> 4.4.4.0/24 0.0.0.0 0 32768 i *>i 5.5.5.0/24 5.5.5.5 0 100 0 i
本地优先级(local preference)
公认自由决定属性
告诉AS中的路由器,哪条路径是离开AS的首选路径
LP越高路径越优
只发送给IBGP邻居,而不能传递给EBGP邻居
默认本地优先级为100
将上面的实验环境还原
1 2 3 4 5 6 7 8 9
R6#sh ip bgp Network Next Hop Metric LocPrf Weight Path * i 1.1.1.0/24 5.5.5.5 0 100 0 300 100 i *>i 4.4.4.4 0 100 0 200 100 i *>i 2.2.2.0/24 4.4.4.4 0 100 0 200 i *>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i *>i 4.4.4.0/24 4.4.4.4 0 100 0 i *>i 5.5.5.0/24 5.5.5.5 0 100 0 i *> 6.6.6.0/24 0.0.0.0 0 32768 i
R5(config)#router bgp 450 R5(config-router)#bgp default local-preference 500 R5(config-router)#do clea ip bgp * so out
查看R6的BGP表
1 2 3 4 5 6 7 8
R6#sh ip bgp Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 5.5.5.5 0 500 0 300 100 i *>i 2.2.2.0/24 4.4.4.4 0 100 0 200 i *>i 3.3.3.0/24 5.5.5.5 0 500 0 300 i *>i 4.4.4.0/24 4.4.4.4 0 100 0 i *>i 5.5.5.0/24 5.5.5.5 0 500 0 i *> 6.6.6.0/24 0.0.0.0 0 32768 i
如果想设置某台路由器作为整个AS的优选出口,可以修改默认的本地优先级
如果只是想改某一条路由的路径,建议用route-map
1 2 3 4 5 6 7 8 9
R5(config)#access-list 1 permit 1.1.1.0 R5(config)#route-map R6 per R5(config-route-map)#mat ip add 1 R5(config-route-map)#set local-preference 110 R5(config-route-map)#exit R5(config)#route-map R6 per 20 R5(config-route-map)#router bgp 450 R5(config-router)#nei 6.6.6.6 route-map R6 out R5(config-router)#do clea ip bgp * so out
查看R6的BGP表
1 2 3 4 5 6 7 8
R6#sh ip bgp Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 5.5.5.5 0 110 0 300 100 i *>i 2.2.2.0/24 4.4.4.4 0 100 0 200 i *>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i *>i 4.4.4.0/24 4.4.4.4 0 100 0 i *>i 5.5.5.0/24 5.5.5.5 0 100 0 i *> 6.6.6.0/24 0.0.0.0 0 32768 i
AS_PATH
公认强制属性
是前往目标网络的路由经过的自制系统号列表,通告该路由的自治系统号位于列表末尾
作用:确保无环,通告给EBGP时会加上自己的AS号;通告给IBGP时不修改AS-path
只有在AS之间传递的时候才会发生变化,如果AS_PATH中有自己的AS号,那么就不学习不传递
如果R1不想让AS450学习到1.1.1.0这个条目,我们可以在AS_PATH中手动加上AS450
首先在R2上查看一下1.1.1.0的AS_PATH,只有AS100
1 2 3
R2#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 1.1.1.1 0 0 100 i
在R1上配置1.1.1.0离开AS100的route-map追加AS450
1 2 3 4 5 6 7 8 9 10
R1(config)#access-list 1 permit 1.1.1.0 R1(config)#route-map AS100out per R1(config-route-map)#ma ip add 1 R1(config-route-map)#set as-path prepend 450 R1(config-route-map)#exit R1(config)#route-map AS100out per 20 R1(config-route-map)#router bgp 100 R1(config-router)#nei 2.2.2.2 route-map AS100out out R1(config-router)#nei 3.3.3.3 route-map AS100out out R1(config-router)#do clea ip bgp * so out
在R2上再次查看1.1.1.0的AS_PATH
1 2 3
R2#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 1.1.1.1 0 0 100 450 i
我们发现AS450中就学习不到这个条目了
1 2 3 4 5 6 7
R6#show ip bgp Network Next Hop Metric LocPrf Weight Path *>i 2.2.2.0/24 4.4.4.4 0 100 0 200 i *>i 3.3.3.0/24 5.5.5.5 0 100 0 300 i *>i 4.4.4.0/24 4.4.4.4 0 100 0 i *>i 5.5.5.0/24 5.5.5.5 0 100 0 i *> 6.6.6.0/24 0.0.0.0 0 32768 i
R2(config)#access-list 1 permit 1.1.1.0 R2(config)#route-map R4out per R2(config-route-map)#ma ip add 1 R2(config-route-map)#set as pre 200 200 200 R2(config-route-map)#route-map R4out per 20 R2(config-route-map)#router bgp 200 R2(config-router)#nei 4.4.4.4 route-map R4out out R2(config-router)#do clea ip bgp * so out
查看R4的BGP表
1 2 3 4
R4#show ip bgp Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 5.5.5.5 0 100 0 300 100 i * 2.2.2.2 0 200 200 200 200 100 i
AS_PATH有4种
有序AS_PATH
正常的AS_PATH都是会按照顺序进行排列,称为有序
450 300 100 i
无序AS_PATH
如果将多个AS的多条路由条目进行汇总,这个汇总的路由携带的AS_PATH就可能是无序的
汇总路由的明细来自于AS300和AS100,不分先后,所以无序
450 {300 100} i
联邦内有序AS_PATH
联邦内无序AS_PATH
ORIGIN
公认强制属性
标识路由的起源,有下列3种可能:
i 通过BGP network,也就是起源于IGP,因为BGP network必须保证该网络在路由表中
R2(config)#access-list 1 per 1.1.1.0 R2(config)#route-map R4out per R2(config-route-map)#mat ip ad 1 R2(config-route-map)#set origin incomplete R2(config-route-map)#route-map R4out per 20 R2(config-route-map)#router bgp 200 R2(config-router)#nei 4.4.4.4 route-map R4out out R2(config-router)#do clea ip bgp * so out
查看R4上路径的选择
1 2 3 4
R4#sh ip bgp Network Next Hop Metric LocPrf Weight Path *>i 1.1.1.0/24 5.5.5.5 0 100 0 300 100 i * 2.2.2.2 0 200 100 ?
R1(config)#access-list 1 permit 1.1.1.0 R1(config)#route-map R2out per R1(config-route-map)#ma ip add 1 R1(config-route-map)#set met R1(config-route-map)#set metric 100 R1(config-route-map)#route-map R2oute per 20 R1(config-route-map)#router bgp 100 R1(config-router)#nei 2.2.2.2 route-map R2out out R1(config-router)#do clea ip bgp * so
查看修改的效果
1 2 3
R2#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 1.1.1.1 100 0 100 i
BGP在重发布IGP条目的时候,会将IGP条目的度量值用作MED
1 2 3 4 5
R4(config)#access-list 1 permit 192.168.56.0 R4(config)#route-map o-b per R4(config-route-map)#ma ip ad 1 R4(config-route-map)#router bgp 450 R4(config-router)#redistribute ospf 1 route-map o-b
在R2上查看度量值,发现将OSPF的开销作为MED属性
1 2 3
R2#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 192.168.56.0 4.4.4.4 20 0 450 ?
R1(config)#access-list 1 per 1.1.1.0 R1(config)#access-list 2 per 10.10.10.0 R1(config)#route-map R2R3out per R1(config-route-map)#ma ip ad 1 R1(config-route-map)#set community 100:1 R1(config-route-map)#route-map R2R3out per 20 R1(config-route-map)#ma ip ad 2 R1(config-route-map)#set community 100:2 R1(config-route-map)#route-map R2R3oute per 30 R1(config-route-map)#router bgp 100 R1(config-router)#nei 2.2.2.2 route-map R2R3out out R1(config-router)#nei 3.3.3.3 route-map R2R3out out R1(config-router)#nei 2.2.2.2 send-community R1(config-router)#nei 3.3.3.3 send-community # 别忘了开启团体属性的发送
查看团体属性
1 2 3 4 5 6 7 8 9 10 11 12
R3(config)#ip bgp-community new-format R3(config)#do sh ip bgp 10.10.10.0 BGP routing table entry for 10.10.10.0/24, version 11 Paths: (1 available, best #1, table default) Advertised to update-groups: 1 Refresh Epoch 1 100 1.1.1.1 from 1.1.1.1 (1.1.1.1) Origin IGP, metric 0, localpref 100, valid, external, best Community: 100:2 rx pathid: 0, tx pathid: 0x0
后面可以根据不同的community属性加上策略
1 2 3 4 5 6 7
R3(config)#ip community-list 1 permit 100:1 R3(config)#route-map R5out deny R3(config-route-map)#match community 1 R3(config-route-map)#route-map R5out per 20 R3(config-route-map)#router bgp 300 R3(config-router)#nei 5.5.5.5 route-map R5out out R3(config-router)#do clea ip bgp * so
查看R5的bgp表,发现现在已经无法从R3学习到有100:1标签的路由了
1 2 3 4 5 6 7 8 9 10 11
R5#sh ip bgp 1.1.1.0 BGP routing table entry for 1.1.1.0/24, version 14 Paths: (1 available, best #1, table default) Advertised to update-groups: 1 Refresh Epoch 1 200 100 4.4.4.4 (metric 11) from 6.6.6.6 (6.6.6.6) Origin IGP, metric 0, localpref 100, valid, internal, best Originator: 4.4.4.4, Cluster list: 6.6.6.6 rx pathid: 0, tx pathid: 0x0
有默认操作的团体属性
以下的属性是有默认功能的,不需要手动加上策略,携带了这个团体属性的条目默认就回执行对应的动作
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<1-4294967295> community number # 正常的团体属性 aa:nn community number in aa:nn format # 正常的团体属性 internet Internet (well-known community) # 表示所有的条目,如果想匹配any,可以用这个 local-AS Do not send outside local AS (well-known community) # 不要让这个条目离开自己这个AS,也就是不会对EBGP邻居更新这个条目 no-advertise Do not advertise to any peer (well-known community) # 告知下一个AS,不要让这个条目给第三个路由器知道 no-export Do not export to next AS (well-known community) # 告知下一个AS,不要让这个条目给第三个AS知道 none No community attribute # 去除所有community标签
还原实验环境
让R6的6.6.6.0带上local-AS属性
1 2 3 4 5 6 7 8 9 10 11
R6(config)#access-list 1 permit 6.6.6.0 R6(config)#route-map R4R5out per R6(config-route-map)#ma ip ad 1 R6(config-route-map)#set commu local-AS R6(config-route-map)#route-map R4R5out per 20 R6(config-route-map)#router bgp 450 R6(config-router)#nei 4.4.4.4 route-map R4R5out out R6(config-router)#nei 5.5.5.5 route-map R4R5out out R6(config-router)#nei 4.4.4.4 send-comm R6(config-router)#nei 5.5.5.5 send-comm R6(config-router)#do clea ip bgp * so
查看R4上的条目是否有这个属性
1 2 3 4 5 6 7 8 9 10
R4#sh ip bgp 6.6.6.0 BGP routing table entry for 6.6.6.0/24, version 12 Paths: (1 available, best #1, table default, not advertised outside local AS) Not advertised to any peer Refresh Epoch 2 Local 6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6) Origin IGP, metric 0, localpref 100, valid, internal, best Community: local-AS rx pathid: 0, tx pathid: 0x0
查看其他AS是否能学习到6.6.6.0
1 2 3 4 5 6 7 8 9
R2#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 1.1.1.1 0 0 100 i *> 2.2.2.0/24 0.0.0.0 0 32768 i * 3.3.3.0/24 4.4.4.4 0 450 300 i *> 1.1.1.1 0 100 300 i *> 4.4.4.0/24 4.4.4.4 0 0 450 i *> 5.5.5.0/24 4.4.4.4 0 450 i * 1.1.1.1 0 100 300 450 i
让6.6.6.0携带上no-advertise
1 2 3
R6(config)#route-map R4R5out per 10 R6(config-route-map)#no set commu local-AS R6(config-route-map)#set commu no-adv
查看R4是否有这个属性
1 2 3 4 5 6 7 8 9 10
R4#sh ip bgp 6.6.6.0 BGP routing table entry for 6.6.6.0/24, version 13 Paths: (1 available, best #1, table default, not advertised to any peer) Not advertised to any peer Refresh Epoch 4 Local 6.6.6.6 (metric 11) from 6.6.6.6 (6.6.6.6) Origin IGP, metric 0, localpref 100, valid, internal, best Community: no-advertise rx pathid: 0, tx pathid: 0x0
然后查看R2是否学习到
1 2 3 4 5 6 7 8 9
R2#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 1.1.1.1 0 0 100 i *> 2.2.2.0/24 0.0.0.0 0 32768 i * 3.3.3.0/24 4.4.4.4 0 450 300 i *> 1.1.1.1 0 100 300 i *> 4.4.4.0/24 4.4.4.4 0 0 450 i *> 5.5.5.0/24 4.4.4.4 0 450 i * 1.1.1.1 0 100 300 450 i
还原实验环境,在R4通告R2的时候让6.6.6.0携带上no-advertise
1 2 3 4 5 6 7 8 9
R4(config)#access-list 1 per 6.6.6.0 R4(config)#route-map R2 per R4(config-route-map)#ma ip ad 1 R4(config-route-map)#set commu no-ex R4(config-route-map)#route-map R2 per 20 R4(config-route-map)#router bgp 450 R4(config-router)#nei 2.2.2.2 route-map R2 out R4(config-router)#nei 2.2.2.2 send-comm R4(config-router)#do clea ip bgp * so
查看R2是否有这个属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
R2#sh ip bgp 6.6.6.0 BGP routing table entry for 6.6.6.0/24, version 8 Paths: (2 available, best #2, table default, not advertised to EBGP peer) Not advertised to any peer Refresh Epoch 1 100 300 450 1.1.1.1 from 1.1.1.1 (1.1.1.1) Origin IGP, localpref 100, valid, external rx pathid: 0, tx pathid: 0 Refresh Epoch 1 450 4.4.4.4 from 4.4.4.4 (4.4.4.4) Origin IGP, localpref 100, valid, external, best Community: no-export rx pathid: 0, tx pathid: 0x0
到R1上查看路由条目,发现已经不能从R2学到这个条目了
1 2 3 4 5 6 7 8 9 10
R1#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 0.0.0.0 0 32768 i *> 2.2.2.0/24 2.2.2.2 0 0 200 i *> 3.3.3.0/24 3.3.3.3 0 0 300 i * 4.4.4.0/24 3.3.3.3 0 300 450 i *> 2.2.2.2 0 200 450 i * 5.5.5.0/24 2.2.2.2 0 200 450 i *> 3.3.3.3 0 300 450 i *> 6.6.6.0/24 3.3.3.3 0 300 450 i
R2(config)#ip community-list 1 per no-export R2(config)#access-list 1 per 6.6.6.0 R2(config)#route-map R4 per R2(config-route-map)#ma ip add 1 R2(config-route-map)#set comm-list 1 delete R2(config-route-map)#route-map R4 per 20 R2(config-route-map)#router bgp 200 R2(config-router)#nei 4.4.4.4 route-map R4 in R2(config-router)#do clea ip bgp * so in
查看R2上6.6.6.0的属性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
R2#sh ip bgp 6.6.6.0 BGP routing table entry for 6.6.6.0/24, version 9 Paths: (2 available, best #2, table default) Advertised to update-groups: 1 Refresh Epoch 3 100 300 450 1.1.1.1 from 1.1.1.1 (1.1.1.1) Origin IGP, localpref 100, valid, external rx pathid: 0, tx pathid: 0 Refresh Epoch 3 450 4.4.4.4 from 4.4.4.4 (4.4.4.4) Origin IGP, localpref 100, valid, external, best rx pathid: 0, tx pathid: 0x0
查看R1是否可以学习到这个条目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 0.0.0.0 0 32768 i *> 2.2.2.0/24 2.2.2.2 0 0 200 i *> 3.3.3.0/24 3.3.3.3 0 0 300 i * 4.4.4.0/24 3.3.3.3 0 300 450 i *> 2.2.2.2 0 200 450 i * 5.5.5.0/24 2.2.2.2 0 200 450 i *> 3.3.3.3 0 300 450 i * 6.6.6.0/24 2.2.2.2 0 200 450 i *> 3.3.3.3 0 300 450 i
R4#sh ip route bgp 172.16.0.0/24 is subnetted, 4 subnets B 172.16.10.0 [20/0] via 192.168.34.3, 00:02:35 B 172.16.11.0 [20/0] via 192.168.34.3, 00:02:35 B 172.16.20.0 [20/0] via 192.168.34.3, 00:02:35 B 172.16.21.0 [20/0] via 192.168.34.3, 00:02:35
R4#sh ip route bgp 172.16.0.0/16 is variably subnetted, 5 subnets, 2 masks B 172.16.0.0/16 [20/0] via 192.168.34.3, 00:00:22 B 172.16.10.0/24 [20/0] via 192.168.34.3, 00:03:38 B 172.16.11.0/24 [20/0] via 192.168.34.3, 00:03:38 B 172.16.20.0/24 [20/0] via 192.168.34.3, 00:03:38 B 172.16.21.0/24 [20/0] via 192.168.34.3, 00:03:38
R3(config-router)#do sh ip bgp BGP table version is 10, 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, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path *> 172.16.0.0 0.0.0.0 32768 i s> 172.16.10.0/24 192.168.13.1 0 0 100 i s> 172.16.11.0/24 192.168.13.1 0 0 100 i s> 172.16.20.0/24 192.168.23.2 0 0 200 i s> 172.16.21.0/24 192.168.23.2 0 0 200 i
查看R4的路由表和BGP表
1 2 3 4 5
R4#sh ip route bgp B 172.16.0.0/16 [20/0] via 192.168.34.3, 00:03:06 R4#show ip bgp Network Next Hop Metric LocPrf Weight Path *> 172.16.0.0 192.168.34.3 0 0 300 i
R4#show ip bgp Network Next Hop Metric LocPrf Weight Path *> 172.16.0.0 192.168.34.3 0 0 300 {100,200} i
检查AS100或者AS200,发现不会将汇总路由重新学习回去了
1 2 3 4
R2#show ip bgp Network Next Hop Metric LocPrf Weight Path *> 172.16.20.0/24 0.0.0.0 0 32768 i *> 172.16.21.0/24 0.0.0.0 0 32768 i
由于AS300会抑制172.16开头的明细条目,所以AS100和AS200互相学习不到明细
如果我们想让AS100和AS200能够互相学习明细路由
在R3上针对不同的邻居,可以取消某些条目的抑制
1 2 3 4 5 6 7 8 9 10 11 12 13 14
R3(config)#access-list 1 permit 172.16.20.0 R3(config)#access-list 1 permit 172.16.21.0 R3(config)#access-list 2 permit 172.16.10.0 R3(config)#access-list 2 permit 172.16.11.0 R3(config)#route-map unsupp per R3(config-route-map)#ma ip add 1 R3(config-route-map)#route-map unsup R3(config-route-map)#route-map unsupp per 20 R3(config-route-map)#ma ip add 2 R3(config-route-map)#exit R3(config)#route-map unsupp per 30 R3(config-route-map)#router bgp 300 R3(config-router)#nei 192.168.13.1 unsuppress-map unsupp R3(config-router)#nei 192.168.23.2 unsuppress-map unsupp
检查R1和R2的路由表
1 2 3 4
R1#sh ip route bgp 172.16.0.0/16 is variably subnetted, 6 subnets, 2 masks B 172.16.20.0/24 [20/0] via 192.168.13.3, 00:00:25 B 172.16.21.0/24 [20/0] via 192.168.13.3, 00:00:25
1 2 3 4
R2#sh ip route bgp 172.16.0.0/16 is variably subnetted, 6 subnets, 2 masks B 172.16.10.0/24 [20/0] via 192.168.23.3, 00:00:58 B 172.16.11.0/24 [20/0] via 192.168.23.3, 00:00:58
上面的需求是取消某些条目的抑制,如果我们只是想抑制部分,可以这样做
还原实验环境
1 2 3 4 5 6 7
R3(config)#access-list 1 per 172.16.11.0 R3(config)#access-list 1 per 172.16.21.0 R3(config)#route-map supp per R3(config-route-map)#ma ip ad 1 R3(config-route-map)#router bgp 300 R3(config-router)#ag R3(config-router)#aggregate-address 172.16.0.0 255.255.0.0 as-set suppress-map supp
查看R3的bgp表,确认部分被抑制
1 2 3 4 5 6 7
R3#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 172.16.0.0 0.0.0.0 100 32768 {100,200} i *> 172.16.10.0/24 192.168.13.1 0 0 100 i s> 172.16.11.0/24 192.168.13.1 0 0 100 i *> 172.16.20.0/24 192.168.23.2 0 0 200 i s> 172.16.21.0/24 192.168.23.2 0 0 200 i
R4#sh bgp Network Next Hop Metric LocPrf Weight Path *> 172.16.0.0 192.168.34.3 0 0 300 200 i
可以配置advertise-map让BGP做到明细丢失了,就把汇总也删除。
1 2 3 4 5 6 7
R3(config)#access-list 1 per 172.16.11.0 R3(config)#access-list 1 per 172.16.21.0 R3(config)#route-map adv per R3(config-route-map)#ma ip ad 1 R3(config-route-map)#router bgp 300 R3(config-router)#ag R3(config-router)#aggregate-address 172.16.0.0 255.255.0.0 as-set advertise-map adv
========R1========= interface Loopback0 ip address 1.1.1.1 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/0 ip address 192.168.123.1 255.255.255.0 ip ospf 1 area 0 ! router bgp 123 bgp log-neighbor-changes network 1.1.1.0 mask 255.255.255.0 neighbor 2.2.2.2 remote-as 123 neighbor 2.2.2.2 update-source Loopback0 neighbor 2.2.2.2 route-reflector-client neighbor 3.3.3.3 remote-as 123 neighbor 3.3.3.3 update-source Loopback0 neighbor 3.3.3.3 route-reflector-client ========R2========= interface Loopback0 ip address 2.2.2.2 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/0 ip address 192.168.123.2 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/1 ip address 192.168.24.2 255.255.255.0 ! router bgp 123 bgp log-neighbor-changes neighbor 1.1.1.1 remote-as 123 neighbor 1.1.1.1 update-source Loopback0 neighbor 1.1.1.1 next-hop-self neighbor 192.168.24.4 remote-as 400 ========R3========= interface Loopback0 ip address 3.3.3.3 255.255.255.0 ip ospf 1 area 0 ! interface Ethernet0/0 ip address 192.168.123.3 255.255.255.0 ip ospf 1 area 0 ! interface Serial1/0 ip address 192.168.34.3 255.255.255.0 ! router bgp 123 bgp log-neighbor-changes neighbor 1.1.1.1 remote-as 123 neighbor 1.1.1.1 update-source Loopback0 neighbor 1.1.1.1 next-hop-self neighbor 192.168.34.4 remote-as 400 ========R4========= interface Loopback0 ip address 4.4.4.4 255.255.255.0 ! interface Ethernet0/0 ip address 192.168.24.4 255.255.255.0 ! interface Serial1/0 ip address 192.168.34.4 255.255.255.0 ! router bgp 400 bgp log-neighbor-changes network 4.4.4.0 mask 255.255.255.0 neighbor 192.168.24.2 remote-as 123 neighbor 192.168.34.3 remote-as 123
检查R1和R4是否学习到彼此
1 2 3 4 5 6 7 8 9 10
R1#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 0.0.0.0 0 32768 i * i 4.4.4.0/24 3.3.3.3 0 100 0 400 i *>i 2.2.2.2 0 100 0 400 i R4#sh ip bgp Network Next Hop Metric LocPrf Weight Path * 1.1.1.0/24 192.168.34.3 0 123 i *> 192.168.24.2 0 123 i *> 4.4.4.0/24 0.0.0.0 0 32768 i
R4#show ip route bgp 1.0.0.0/24 is subnetted, 1 subnets B 1.1.1.0 [20/0] via 192.168.34.3, 00:01:56 [20/0] via 192.168.24.2, 00:01:56 R4#show ip route 1.1.1.0 Routing entry for 1.1.1.0/24 Known via "bgp 400", distance 20, metric 0 Tag 123, type external Last update from 192.168.24.2 00:02:13 ago Routing Descriptor Blocks: * 192.168.34.3, from 192.168.34.3, 00:02:13 ago Route metric is 0, traffic share count is 37 AS Hops 1 Route tag 123 MPLS label: none 192.168.24.2, from 192.168.24.2, 00:02:13 ago Route metric is 0, traffic share count is 240 AS Hops 1 Route tag 123 MPLS label: none
R1#show ip route bgp 4.0.0.0/24 is subnetted, 1 subnets B 4.4.4.0 [200/0] via 3.3.3.3, 00:00:10 [200/0] via 2.2.2.2, 00:00:10 R1#show ip route 4.4.4.0 Routing entry for 4.4.4.0/24 Known via "bgp 123", distance 200, metric 0 Tag 400, type internal Last update from 2.2.2.2 00:00:27 ago Routing Descriptor Blocks: * 3.3.3.3, from 3.3.3.3, 00:00:27 ago Route metric is 0, traffic share count is 37 AS Hops 1 Route tag 400 MPLS label: none 2.2.2.2, from 2.2.2.2, 00:00:27 ago Route metric is 0, traffic share count is 240 AS Hops 1 Route tag 400 MPLS label: none
R1#sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 0.0.0.0 0 32768 i *>i 4.4.4.0/24 2.2.2.2 0 100 0 400 i * i 3.3.3.3 0 100 0 400 i
修改下一跳为3.3.3.3的路由权重
1 2 3 4 5 6 7 8
R1(config)#router bgp 123 R1(config-router)#nei 3.3.3.3 weight 10 R1(config-router)#do clea ip bgp * so in R1(config-router)#do sh ip bgp Network Next Hop Metric LocPrf Weight Path *> 1.1.1.0/24 0.0.0.0 0 32768 i * i 4.4.4.0/24 2.2.2.2 0 100 0 400 i *>i 3.3.3.3 0 100 10 400 i
在R2上配置cost communtiy,将R1的路由选择改回来,从2.2.2.2走
1 2 3 4 5 6 7 8
R2 access-list 1 permit 4.4.4.0 route-map cost permit 10 match ip address 1 route-map cost permit 20 router bgp 123 neighbor 1.1.1.1 send-community extended neighbor 1.1.1.1 route-map cost out