在双点双向重分发中,经常会遇到次优路径问题,所谓次优路径就是由于路由协议的重分发,导致并不是最优的路由替代了现有的最优路由,根本原因就是重分发过来的路由的管理距离比现有的路由管理距离要小,进而替代了现有的最优路由,这就是次优路径问题。
我们直接用下面拓扑图作为实例来演示一下次优路径问题的产生和解决:
我们先来配置一下底层:
在R1上配置:
R1>en
R1#conf t
R1(config)#int f0/0
R1(config-if)#ip add 12.1.1.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exi
R1(config)#int f0/1
R1(config-if)#ip add 13.1.1.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exi
R1(config)#int lo 0
R1(config-if)#ip add 1.1.1.1 255.255.255.255
R1(config-if)#no sh
R1(config-if)#exi
R1(config)#router rip
R1(config-router)#no au
R1(config-router)#v 2
R1(config-router)#net 1.0.0.0
R1(config-router)#net 12.0.0.0
R1(config-router)#net 13.0.0.0
R1(config-router)#exi
在R2上配置:
R2>en
R2#conf t
R2(config)#int lo 0
R2(config-if)#ip add 2.2.2.2 255.255.255.255
R2(config-if)#no sh
R2(config-if)#int f0/0
R2(config-if)#ip add 12.1.1.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exi
R2(config)#int f0/1
R2(config-if)#ip add 24.1.1.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exi
R2(config)#router ri
R2(config-router)#no au
R2(config-router)#v 2
R2(config-router)#net 2.0.0.0
R2(config-router)#net 12.0.0.0
R2(config-router)#exi
R2(config)#router os 100
R2(config-router)#net 24.1.1.0 0.0.0.255 a 0
R2(config-router)#exi
在R3上配置:
R3>en
R3#conf t
R3(config)#int lo 0
R3(config-if)#ip add 3.3.3.3 255.255.255.255
R3(config-if)#no sh
R3(config-if)#exi
R3(config)#int f0/1
R3(config-if)#ip add 13.1.1.3 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exi
R3(config)#int f0/0
R3(config-if)#ip add 34.1.1.3 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exi
R3(config)#router ri
R3(config-router)#no au
R3(config-router)#v 2
R3(config-router)#net 13.1.1.0
R3(config-router)#exi
R3(config)#router os 100
R3(config-router)#net 3.3.3.3 0.0.0.0 a 0
R3(config-router)#net 34.1.1.0 0.0.0.255 a 0
R3(config-router)#exi
在 R4上配置:
R4>en
R4#conf t
R4(config)#int lo 0
R4(config-if)#ip add 4.4.4.4 255.255.255.255
R4(config-if)#no sh
R4(config-if)#exi
R4(config)#int f0/0
R4(config-if)#ip add 34.1.1.4 255.255.255.0
R4(config-if)#no sh
R4(config-if)#int f0/1
R4(config-if)#ip add 24.1.1.4 255.255.255.0
R4(config-if)#no sh
R4(config-if)#exi
R4(config)#router os 100
R4(config-router)#net 4.4.4.4 0.0.0.0 a 0
R4(config-router)#net 24.1.1.0 0.0.0.255 a 0
R4(config-router)#net 34.1.1.0 0.0.0.255 a 0
R4(config-router)#exi
好了我们先在R2上进行重分发操作:
R2(config)#router os 100
R2(config-router)#redistribute rip subnets
R2(config-router)#exi
R2(config)#router rip
R2(config-router)#redistribute ospf 100 metric 1
R2(config-router)#exi
好了,重分发之后我们去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
34.0.0.0/24 is subnetted, 1 subnets
C 34.1.1.0 is directly connected, FastEthernet0/0
1.0.0.0/32 is subnetted, 1 subnets
O E2 1.1.1.1 [110/20] via 34.1.1.4, 00:22:57, FastEthernet0/0
2.0.0.0/32 is subnetted, 1 subnets
O E2 2.2.2.2 [110/20] via 34.1.1.4, 00:22:57, FastEthernet0/0
3.0.0.0/32 is subnetted, 1 subnets
C 3.3.3.3 is directly connected, Loopback0
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/11] via 34.1.1.4, 00:22:57, FastEthernet0/0
24.0.0.0/24 is subnetted, 1 subnets
O 24.1.1.0 [110/20] via 34.1.1.4, 00:22:59, FastEthernet0/0
12.0.0.0/24 is subnetted, 1 subnets
O E2 12.1.1.0 [110/20] via 34.1.1.4, 00:22:59, FastEthernet0/0
13.0.0.0/24 is subnetted, 1 subnets
C 13.1.1.0 is directly connected, FastEthernet0/1
大家发现了什么问题?没错,去往1.1.1.1 的路由是标记为O E2的下一跳是R4的路由,而在拓扑图中,很明显去往R1最近的应该是直连,直接发给R1,这是为什么呢,因为之前1.1.1.1这个路由是通过rip学到的,而RIP的管理距离是120,而ospf的管理距离是110,我们在R2上进行了重分发动作,R3同样在ospf的区域0中,也会收到标记为O E2的R2重分发来的RIP路由,这其中就有1.1.1.1这条路由,而ospf的管理距离是110小于rip的120,所以被取代,我们在R3才看见了这么不合理的路由。
我们接着在R3上进行重分发操作:
R3(config)#router ri
R3(config-router)#redistribute ospf 100 metric 1
R3(config-router)#exi
R3(config)#router os 100
R3(config-router)#redistribute rip subnets
R3(config-router)#exi
只在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
34.0.0.0/24 is subnetted, 1 subnets
C 34.1.1.0 is directly connected, FastEthernet0/0
1.0.0.0/32 is subnetted, 1 subnets
O E2 1.1.1.1 [110/20] via 34.1.1.4, 00:30:02, FastEthernet0/0
2.0.0.0/32 is subnetted, 1 subnets
O E2 2.2.2.2 [110/20] via 34.1.1.4, 00:30:02, FastEthernet0/0
3.0.0.0/32 is subnetted, 1 subnets
C 3.3.3.3 is directly connected, Loopback0
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/11] via 34.1.1.4, 00:30:02, FastEthernet0/0
24.0.0.0/24 is subnetted, 1 subnets
O 24.1.1.0 [110/20] via 34.1.1.4, 00:30:03, FastEthernet0/0
12.0.0.0/24 is subnetted, 1 subnets
O E2 12.1.1.0 [110/20] via 34.1.1.4, 00:30:04, FastEthernet0/0
13.0.0.0/24 is subnetted, 1 subnets
C 13.1.1.0 is directly connected, FastEthernet0/1
那么我们如何处理这个问题呢,在这里我们有以下几个思路:
R3(config)#router os 100
R3(config-router)#distance 121 2.2.2.2 0.0.0.0
之后我们在R3上查看一下路由表:
R3(config)#do 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
34.0.0.0/24 is subnetted, 1 subnets
C 34.1.1.0 is directly connected, FastEthernet0/0
1.0.0.0/32 is subnetted, 1 subnets
R 1.1.1.1 [120/1] via 13.1.1.1, 00:00:10, FastEthernet0/1
2.0.0.0/32 is subnetted, 1 subnets
O E2 2.2.2.2 [121/20] via 34.1.1.4, 00:00:26, FastEthernet0/0
3.0.0.0/32 is subnetted, 1 subnets
C 3.3.3.3 is directly connected, Loopback0
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/11] via 34.1.1.4, 00:00:26, FastEthernet0/0
24.0.0.0/24 is subnetted, 1 subnets
O 24.1.1.0 [121/20] via 34.1.1.4, 00:00:28, FastEthernet0/0
12.0.0.0/24 is subnetted, 1 subnets
R 12.1.1.0 [120/1] via 13.1.1.1, 00:00:14, FastEthernet0/1
13.0.0.0/24 is subnetted, 1 subnets
C 13.1.1.0 is directly connected, FastEthernet0/1
可以看到R1又变回来了,但却并没有影响到其他ospf的管理距离,只有从R2传过来的两条路由的管理距离改变了。而且我们去R4查看路由表也没有任何异常(管理距离被更改),没错,你一定也看出来这个命令的意思了,这条命令就是说,所有从Router-id为2.2.2.2发来的路由的管理距离均改成121,而我是在R3上配置的这条命令,自然也只是在R3上生效,那么问题来了,既然R3上去往1.1.1.1变回了直连,那么R2上一定又出现了次优路径问题,我们去看一下:
R2#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
34.0.0.0/24 is subnetted, 1 subnets
O 34.1.1.0 [110/20] via 24.1.1.4, 00:44:36, FastEthernet0/1
1.0.0.0/32 is subnetted, 1 subnets
O E2 1.1.1.1 [110/20] via 24.1.1.4, 00:06:30, FastEthernet0/1
2.0.0.0/32 is subnetted, 1 subnets
C 2.2.2.2 is directly connected, Loopback0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/21] via 24.1.1.4, 00:43:49, FastEthernet0/1
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/11] via 24.1.1.4, 00:44:46, FastEthernet0/1
24.0.0.0/24 is subnetted, 1 subnets
C 24.1.1.0 is directly connected, FastEthernet0/1
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
O E2 13.1.1.0 [110/20] via 24.1.1.4, 00:16:25, FastEthernet0/1
果然,去往R1的路由变成了O E2的路由,不要慌,我们再在R2上配置一遍刚才的命令只不过将Router-id变成3.3.3.3就好了:
R2#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
34.0.0.0/24 is subnetted, 1 subnets
O 34.1.1.0 [110/20] via 24.1.1.4, 00:00:24, FastEthernet0/1
1.0.0.0/32 is subnetted, 1 subnets
R 1.1.1.1 [120/1] via 12.1.1.1, 00:00:02, FastEthernet0/0
2.0.0.0/32 is subnetted, 1 subnets
C 2.2.2.2 is directly connected, Loopback0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [121/21] via 24.1.1.4, 00:00:24, FastEthernet0/1
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/11] via 24.1.1.4, 00:00:24, FastEthernet0/1
24.0.0.0/24 is subnetted, 1 subnets
C 24.1.1.0 is directly connected, FastEthernet0/1
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
R 13.1.1.0 [120/1] via 12.1.1.1, 00:00:05, FastEthernet0/0
ok那么我们现在均正常了!
我们这个拓扑图非常简单,假如在复杂的拓扑图中,双点双向重分发如果不进行处理的话,不仅仅会引起次优路径的问题,还会带来一系列的麻烦,比如路由环路,而且网络规模如果很大的话,更会让我们处理起来头也会很大。