1. 程式人生 > >雙點雙向重分發與次優路徑問題

雙點雙向重分發與次優路徑問題

在雙點雙向重分發中,經常會遇到次優路徑問題,所謂次優路徑就是由於路由協議的重分發,導致並不是最優的路由替代了現有的最優路由,根本原因就是重分發過來的路由的管理距離比現有的路由管理距離要小,進而替代了現有的最優路由,這就是次優路徑問題。

我們直接用下面拓撲圖作為例項來演示一下次優路徑問題的產生和解決:
這裡寫圖片描述
我們先來配置一下底層:
在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

那麼我們如何處理這個問題呢,在這裡我們有以下幾個思路:

  1. 更改ospf的管理距離為121(比rip的120大即可)
  2. 更改rip的管理距離為109(比ospf大即可)
  3. 放棄冗餘,直接過濾掉一條路徑的路由(非常不推薦)
  4. 使用router-map進行策略路由(比較麻煩)
    在這裡我推薦前兩條,我用第一條來演示一下:
    在演示之前,你可能會問,如果更改了ospf的管理距離,那麼豈不是RIP那邊又會出現次優路徑問題,難道改來改去?我先告訴你,並不會這樣,不信我們來看如何操作:
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那麼我們現在均正常了!

我們這個拓撲圖非常簡單,假如在複雜的拓撲圖中,雙點雙向重分發如果不進行處理的話,不僅僅會引起次優路徑的問題,還會帶來一系列的麻煩,比如路由環路,而且網路規模如果很大的話,更會讓我們處理起來頭也會很大。