描述一些前置知识:
关于路由黑洞:
以2.1的拓扑图为例:
pc1的192.168.1.10对pc2的172.16.30.10做ping测试,就需要有路由信息。路由信息封装在bgp中, 从R4到R5的链路中,R1没有运行bgp,当bgp的数据包传输的时候,因为是基于tcp封装的,bgp信息依次被tcp、ip、以太网等包头封装,和普通的网络包一样,只要相邻的两台路由器可以互通,就可以把数据包从R4传送到R5; 但是数据包从pc2返回pc1的时候,封包格式为icmp+ip,IP包头中会有src和dest的地址,这个dest ip就是pc1的192.168.1.10地址,这个数据包到了R3的后,R1是没有bgp协议的,也就学不到192.168.1.0的路由信息,所以传输会失败。这就是路由黑洞。
解决路由黑洞的方法有好几种,比如:
本次实验是采用GNS3模拟器做的,采用了IOU设备的方式。
模拟了bgp的实现过程,顺便验证了一下BGP中的路由黑洞。
拓扑解释:
1 配置IP地址
R1配置IP:
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#int s2/0
R1(config-if)#ip add 12.1.1.2 255.255.255.0
R1(config-if)#no shu
R1(config-if)#exit
R1(config)#int s2/1
R1(config-if)#ip add 11.1.1.1 255.255.255.0
R1(config-if)#no shu
R2配置IP:
R2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#int s2/0
R2(config-if)#ip add 14.1.1.2 255.255.255.0
R2(config-if)#no shu
R2(config-if)#exit
R2(config)#int s2/1
R2(config-if)#ip add 12.1.1.1 255.255.255.0
R2(config-if)#no shu
R3配置IP:
R3#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#int s2/0
R3(config-if)#ip add 11.1.1.2 255.255.255.0
R3(config-if)#no shu
R3(config-if)#exit
R3(config)#int s2/1
R3(config-if)#ip add 13.1.1.1 255.255.255.0
R3(config-if)#no shu
2 配置ospf,对于R2和R3来说,只配置AS内的接口,外联ebgp的口不配置到ospf中
R1配置
R1(config)#router ospf 110
R1(config-router)#router-id 1.1.1.1
R1(config-router)#net 12.1.1.2 0.0.0.0 area 0
R1(config-router)#net 11.1.1.1 0.0.0.0 area 0
R2配置
R2(config)#router ospf 110
R2(config-router)#router-id 2.2.2.2
R2(config-router)#net 12.1.1.1 0.0.0.0 area 0
R3配置
R3(config)#router ospf 110
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 11.1.1.2 0.0.0.0 area 0
3 查看路由表信息
R2#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override
Gateway of last resort is not set
11.0.0.0/24 is subnetted, 1 subnets
O 11.1.1.0 [110/128] via 12.1.1.2, 00:01:46, Serial2/1
12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 12.1.1.0/24 is directly connected, Serial2/1
L 12.1.1.1/32 is directly connected, Serial2/1
查看ospf
R2#show ip ospf database
OSPF Router with ID (2.2.2.2) (Process ID 110)
Router Link States (Area 0)
Link ID ADV Router Age Seq# Checksum Link count
1.1.1.1 1.1.1.1 178 0x80000005 0x00A804 4
2.2.2.2 2.2.2.2 205 0x80000004 0x0083EC 2
3.3.3.3 3.3.3.3 179 0x80000004 0x002742 2
这部分分为ibgp和ebgp的
1 在R2配置bgp协议
R2(config)#router bgp 123
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#neighbor 11.1.1.2 remote-as 123 //为bgp指定邻居,这里指定的是本as内R3的s2/0
R2(config-router)#
*Feb 29 15:43:36.408: %BGP-5-ADJCHANGE: neighbor 11.1.1.2 Up //等待片刻,可以看到邻居建立
R2(config-router)#neighbor 14.1.1.1 remote-as 4 //这里是指定ebgp对端as4的邻居关系
2 在R3配置bgp协议
R3(config)#router bgp 123
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#neighbor 12.1.1.1 remote-as 123
R3(config-router)#neighbor 13.1.1.2 remote-as 5
3 查看bgp信息,因为as4和5的IP和bgp还没配置,所以邻居部分的显示不正常
R2执行查看
R2#show ip bgp summary
BGP router identifier 2.2.2.2, 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
11.1.1.2 4 123 9 9 1 0 0 00:04:47 0
14.1.1.1 4 4 0 0 1 0 0 never Idle
R3执行查看
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
12.1.1.1 4 123 9 10 1 0 0 00:05:28 0
13.1.1.2 4 5 0 0 1 0 0 never Idle
1 首先配置R4和5的IP地址
R4的地址
R4#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R4(config)#int s2/0
R4(config-if)#ip add 14.1.1.1 255.255.255.0
R4(config-if)#no shu
R4(config-if)#exit
R4(config)#int e0/0
R4(config-if)#ip add 192.168.1.1 255.255.255.0
R4(config-if)#no shu
R5的地址
R5#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R5(config)#int s2/0
R5(config-if)#ip add 13.1.1.2 255.255.255.0
R5(config-if)#no shu
R5(config-if)#exit
R5(config)#int e0/0
R5(config-if)#ip add 172.16.30.1 255.255.255.0
R5(config-if)#no shu
2 为R4配置bgp
R4(config)#router bgp 4
R4(config-router)#bgp router-id 4.4.4.4
R4(config-router)#neighbor 14.1.1.2 remote-as 123 //指定as123中R2的s2/0为邻居
R4(config-router)#
*Feb 29 15:54:02.133: %BGP-5-ADJCHANGE: neighbor 14.1.1.2 Up //邻居建立提示
3 为R5配置bgp
R5(config-router)#bgp router
R5(config-router)#bgp router-id 5.5.5.5
R5(config-router)#neighbor 13.1.1.1 remote-as 123
4 查看bgp信息
R4#show ip bgp summary
BGP router identifier 4.4.4.4, local AS number 4
BGP table version is 1, main routing table version 1
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
14.1.1.2 4 123 6 6 1 0 0 00:02:38 0
此时再看R2或者R3的bgp信息,邻居关系就都正常了
R2#show ip bgp summary
BGP router identifier 2.2.2.2, 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
11.1.1.2 4 123 19 18 1 0 0 00:13:40 0
14.1.1.1 4 4 7 7 1 0 0 00:03:14 0
这里是要将pc1的192.168.1.0/24这个网络宣告到bgp中,步骤如下
1 在R4上宣告路由
R4(config)#router bgp 4
R4(config-router)#network 192.168.1.0 mask 255.255.255.0 //只能宣告网段,指定掩码
查看bgp 路由信息
R4#show ip bgp
BGP table version is 2, 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, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
*> 192.168.1.0 0.0.0.0 0 32768 i
本地产生,下一跳为0.0.0.0
2 此时到R2上查看bgp信息,发现路由信息已经过来了,且可以看到192.168.1.0网段的下一跳为14.1.1.1(R4的S2/0,出口接口)
R2#show ip bgp
BGP table version is 2, 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, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
*> 192.168.1.0 14.1.1.1 0 0 4 i
R2上也能看到路由信息,可以看到192.168.1.0是通过bgp学习到的,metric是20,通过ebgp学习到的路由条目metric都是20,如果是ibgp则为200
R2#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override
Gateway of last resort is not set
11.0.0.0/24 is subnetted, 1 subnets
O 11.1.1.0 [110/128] via 12.1.1.2, 00:31:18, Serial2/1
12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 12.1.1.0/24 is directly connected, Serial2/1
L 12.1.1.1/32 is directly connected, Serial2/1
14.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 14.1.1.0/24 is directly connected, Serial2/0
L 14.1.1.2/32 is directly connected, Serial2/0
B 192.168.1.0/24 [20/0] via 14.1.1.1, 00:05:35
3 再看R3上的bgp信息,发现下一跳还是R4上的s2/0,而且路由条目前面没有>,不是最优路由,说明没有把信息传过来,ibgp传输路由信息的时候不会传输下一跳的地址
R3#show ip bgp
BGP table version is 1, 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,
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 192.168.1.0 14.1.1.1 0 100 0 4 i
需要在R2路由上添加next-hop-self,才会把下一跳的信息传递过来。 这个参数只用在as边缘路由器向内部传ibgp信息时。
R2(config)#router bgp 123
R2(config-router)#neighbor 11.1.1.2 next-hop-self
此时再看,发现下一跳的地址已经更新过来了,12.1.1.1正是R2的s2/1出口
R3#show ip bgp
BGP table version is 2, 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,
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 192.168.1.0 12.1.1.1 0 100 0 4 i
再看R3的路由信息,也就有bgp学习到的条目了,当然因为是ibgp传输,所有metric值为200
R3#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override
Gateway of last resort is not set
11.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 11.1.1.0/24 is directly connected, Serial2/0
L 11.1.1.2/32 is directly connected, Serial2/0
12.0.0.0/24 is subnetted, 1 subnets
O 12.1.1.0 [110/128] via 11.1.1.1, 00:40:23, Serial2/0
13.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 13.1.1.0/24 is directly connected, Serial2/1
L 13.1.1.1/32 is directly connected, Serial2/1
B 192.168.1.0/24 [200/0] via 12.1.1.1, 00:04:57
同理,R3上也需要为R2来设置next-hop-self,否则R5向R4方向的路由也会出现同样的问题
R3(config)#router bgp 123
R3(config-router)#neighbor 12.1.1.1 next-hop-self
过程和上一章节类似
1 直接在R5上宣告
R5(config)#router bgp 5
R5(config-router)#network 172.16.30.0 mask 255.255.255.0
2 在R4上已经可以看到正常的路由条目了
R4#show bgp
BGP table version is 3, 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, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
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.30.0/24 14.1.1.2 0 123 5 i
*> 192.168.1.0 0.0.0.0 0 32768 i
1.pc机配置IP地址
在pc1上配置192.168.1.10
在pc2上配置172.16.30.10
2.在路由器R1上打开debug
R1#debug ip packet
IP packet debugging is on
3 执行ping测试,失败
wangql> ping 172.16.30.10
172.16.30.10 icmp_seq=1 timeout
172.16.30.10 icmp_seq=2 timeout
172.16.30.10 icmp_seq=3 timeout
172.16.30.10 icmp_seq=4 timeout
172.16.30.10 icmp_seq=5 timeout
4 观察R1的输出,提示源192.168.1.10到目的172.16.30.10不可达
*Feb 29 16:22:51.401: IP: s=192.168.1.10 (Serial2/0), d=172.16.30.10, len 84, input feature, MCI Check(99), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSE
*Feb 29 16:22:51.401: IP: s=192.168.1.10 (Serial2/0), d=172.16.30.10, len 84, unroutable
因为R1没开启bgp,只有ospf,所有没有这两个网段的路由
R1#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override
Gateway of last resort is not set
11.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 11.1.1.0/24 is directly connected, Serial2/1
L 11.1.1.1/32 is directly connected, Serial2/1
12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 12.1.1.0/24 is directly connected, Serial2/0
L 12.1.1.2/32 is directly connected, Serial2/0
1 R1启用bgp,并添加对端端口的邻居
R1(config)#router bgp 123
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor 12.1.1.1 remote-as 123
R1(config-router)#neighbor 11.1.1.2 remote-as 123
2 R2和R3两天边缘路由器需要对R1添加邻居信息和next-hop-self,否则无法传递bgp路由的下一跳参数
R2
R2(config)#router bgp 123
R2(config-router)#neighbor 12.1.1.2 remote-as 123
R2(config-router)#neighbor 12.1.1.2 next-hop-self
R3
R3(config)#router bgp 123
R3(config-router)#neighbor 11.1.1.1 remote-as 123
R3(config-router)#neighbor 11.1.1.1 next-hop-self
3 再次测试pc1和pc2,网络通畅了
wangql> ping 172.16.30.10
84 bytes from 172.16.30.10 icmp_seq=1 ttl=59 time=36.557 ms
84 bytes from 172.16.30.10 icmp_seq=2 ttl=59 time=36.735 ms
84 bytes from 172.16.30.10 icmp_seq=3 ttl=59 time=36.005 ms
84 bytes from 172.16.30.10 icmp_seq=4 ttl=59 time=33.740 ms
wangql> trace 172.16.30.10
trace to 172.16.30.10, 8 hops max, press Ctrl+C to stop
1 192.168.1.1 0.290 ms 0.141 ms 0.163 ms
2 14.1.1.2 9.157 ms 9.058 ms 8.496 ms
3 12.1.1.2 18.042 ms 17.537 ms 17.808 ms
4 11.1.1.2 26.682 ms 26.471 ms 26.210 ms
5 13.1.1.2 36.360 ms 35.922 ms 34.192 ms
6 *172.16.30.10 37.326 ms (ICMP type:3, code:3, Destination port unreachable)
通过上面的实验,总结如下:
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!
赞3
添加新评论0 条评论