浮動靜態路由(浮動靜態路由是如何實現的)
浮動靜態路由
浮動靜態路由是一種特殊的靜態路由,通過配置一個比主路由的管理距離更大的靜態路由,保證網絡中主路由失效的情況下,提供備份路由。但在主路由存在的情況下備份路由不會出現在路由表中。
拓撲圖
VPC1和VPC2通信,默認走上面R2---R1---R3---PC2路由,如果R1掛掉或者端口down,會自動切換到下面R2---R4---R3路由。
配置名稱和IP地址
R1
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R1
R1(config)#interface ethernet 0/0
R1(config-if)#ip add 12.1.1.1 255.255.255.0
R1(config-if)#no shut
R1(config)#interface ethernet 0/1
R1(config-if)#ip add 13.1.1.1 255.255.255.0
R1(config-if)#no shu
R1#show ip interface bri
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 12.1.1.1 YES manual up up
Ethernet0/1 13.1.1.1 YES manual up up
Ethernet0/2 unassigned YES manual administratively down down
Ethernet0/3 unassigned YES NVRAM administratively down down
R1#
R2
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R2
R2(config)#interface ethernet 0/1
R2(config-if)#ip add 12.1.1.2 255.255.255.0
R2(config-if)#no shut
R2(config)#interface e
R2(config)#interface ethernet 0/2
R2(config-if)#ip add 172.16.1.1 255.255.255.0
R2(config-if)#no shut
R2(config)#interface ethernet 0/0
R2(config-if)#ip add 24.1.1.1 255.255.255.0
R2(config-if)#no shut
R2#show ip interface brief
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 24.1.1.1 YES manual up up
Ethernet0/1 12.1.1.2 YES manual up up
Ethernet0/2 172.16.1.1 YES manual up up
Ethernet0/3 unassigned YES unset administratively down down
R2#
R3
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R3
R3(config)#interface ethernet 0/0
R3(config-if)#ip add 13.1.1.3 255.255.255.0
R3(config-if)#no shu
R3(config)#interface
*Jul 8 23:17:56.567: %LINK-3-UPDOWN: Interface Ethernet0/0, changed state to up
*Jul 8 23:17:57.576: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/0, chan
ged state to up
R3(config)#interface ethernet 0/1
R3(config-if)#ip add 34.1.1.3 255.255.255.0
R3(config-if)#no shut
R3(config)#interface ethernet 0/2
R3(config-if)#ip add 172.16.2.1 255.255.255.0
R3(config-if)#no shut
R3(config-if)#en
*Jul 8 23:19:13.080: %LINK-3-UPDOWN: Interface Ethernet0/2, changed state to up
*Jul 8 23:19:14.080: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/2, chan
ged state to up
R3(config-if)#end
R3#
*Jul 8 23:19:15.186: %SYS-5-CONFIG_I: Configured from console by console
R3#show ip interface brief
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 13.1.1.3 YES manual up up
Ethernet0/1 34.1.1.3 YES manual up up
Ethernet0/2 172.16.2.1 YES manual up up
Ethernet0/3 unassigned YES unset administratively down down
R3#
R4
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R4
R4(config)#interface ethernet 0/0
R4(config-if)#ip add 24.1.1.4 255.255.255.0
R4(config-if)#no shu
R4(config)#interface ethernet 0/1
R4(config-if)#ip address 34.1.1.4 255.255.255.0
R4(config-if)#no shut
R4#show ip interface brief
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 24.1.1.4 YES manual up up
Ethernet0/1 34.1.1.4 YES manual up up
Ethernet0/2 unassigned YES unset administratively down down
Ethernet0/3 unassigned YES unset administratively down down
Ethernet1/0 unassigned YES unset administratively down down
Ethernet1/1 unassigned YES unset administratively down down
Ethernet1/2 unassigned YES unset administratively down down
Ethernet1/3 unassigned YES unset administratively down down
R4#
VPC1
VPCS> set pcname VPC1
VPC1> ip 172.16.1.2/24 172.16.1.1
Checking for duplicate address...
PC1 : 172.16.1.2 255.255.255.0 gateway 172.16.1.1
VPC1> ping 172.16.1.1
172.16.1.1 icmp_seq=1 timeout
84 bytes from 172.16.1.1 icmp_seq=2 ttl=255 time=0.532 ms
84 bytes from 172.16.1.1 icmp_seq=3 ttl=255 time=0.447 ms
84 bytes from 172.16.1.1 icmp_seq=4 ttl=255 time=0.386 ms
84 bytes from 172.16.1.1 icmp_seq=5 ttl=255 time=0.470 ms
VPC1>
VPC2
VPCS> set pcname VPC2
VPC2> ip 172.16.2.2/24 172.16.2.1
Checking for duplicate address...
PC1 : 172.16.2.2 255.255.255.0 gateway 172.16.2.1
VPC2> ping 172.16.2.1
84 bytes from 172.16.2.1 icmp_seq=1 ttl=255 time=0.305 ms
84 bytes from 172.16.2.1 icmp_seq=2 ttl=255 time=0.887 ms
84 bytes from 172.16.2.1 icmp_seq=3 ttl=255 time=0.548 ms
84 bytes from 172.16.2.1 icmp_seq=4 ttl=255 time=0.600 ms
84 bytes from 172.16.2.1 icmp_seq=5 ttl=255 time=0.503 ms
VPC2>
配置完IP地址,最好互相ping下直接路由,避免是因為IP地址產生的問題。
配置靜態路由和浮動靜態路由
R1
R1(config)#ip route 172.16.1.0 255.255.255.0 ethernet 0/0 12.1.1.2
R1(config)#ip route 172.16.2.0 255.255.255.0 ethernet 0/1 13.1.1.3
R1(config)#
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
+ - replicated route, % - next hop override
Gateway of last resort is not set
12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 12.1.1.0/24 is directly connected, Ethernet0/0
L 12.1.1.1/32 is directly connected, Ethernet0/0
13.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 13.1.1.0/24 is directly connected, Ethernet0/1
L 13.1.1.1/32 is directly connected, Ethernet0/1
172.16.0.0/24 is subnetted, 2 subnets
S 172.16.1.0 [1/0] via 12.1.1.2, Ethernet0/0
S 172.16.2.0 [1/0] via 13.1.1.3, Ethernet0/1
R1#
R2
R2(config)#ip route 0.0.0.0 0.0.0.0 ethernet 0/1 12.1.1.1
R2(config)#ip route 0.0.0.0 0.0.0.0 ethernet 0/0 24.1.1.4 ?
<1-255> Distance metric for this route
multicast multicast route
name Specify name of the next hop
permanent permanent route
tag Set tag for this route
track Install route depending on tracked item
R3
R3(config)#ip route 0.0.0.0 0.0.0.0 ethernet 0/0 13.1.1.1
R3(config)#ip route 0.0.0.0 0.0.0.0 ethernet 0/1 34.1.1.4 10
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
+ - replicated route, % - next hop override
Gateway of last resort is 13.1.1.1 to network 0.0.0.0
S* 0.0.0.0/0 [1/0] via 13.1.1.1, Ethernet0/0
13.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 13.1.1.0/24 is directly connected, Ethernet0/0
L 13.1.1.3/32 is directly connected, Ethernet0/0
34.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 34.1.1.0/24 is directly connected, Ethernet0/1
L 34.1.1.3/32 is directly connected, Ethernet0/1
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C 172.16.2.0/24 is directly connected, Ethernet0/2
L 172.16.2.1/32 is directly connected, Ethernet0/2
R3#
R4
R4(config)#ip route 172.16.1.0 255.255.255.0 ethernet 0/0 24.1.1.2
R4(config)#ip route 172.16.2.0 255.255.255.0 ethernet 0/1 34.1.1.3
R4#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
+ - replicated route, % - next hop override
Gateway of last resort is not set
24.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 24.1.1.0/24 is directly connected, Ethernet0/0
L 24.1.1.4/32 is directly connected, Ethernet0/0
34.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 34.1.1.0/24 is directly connected, Ethernet0/1
L 34.1.1.4/32 is directly connected, Ethernet0/1
172.16.0.0/24 is subnetted, 2 subnets
S 172.16.1.0 [1/0] via 24.1.1.2, Ethernet0/0
S 172.16.2.0 [1/0] via 34.1.1.3, Ethernet0/1
R4#
測試實驗結果
1.VPC1與VPC2互通是正常的
2.R1出現故障
由于模擬器的原因,R1關閉端口但與R2和R3連接的對應端口還是up,R1也無法關閉,所以將R2和R3對應的端口關閉掉。
R2:
R3:
顯示R2和R3的靜態路由切換到下面R4。
突然發現一個問題:R2的 e0/0 地址配置錯了,趕緊更正。
數據通信路由走的備份路由。
3.R1恢復之后
將之前R1關閉的端口,R2和R3關閉的端口都放開。
R2路由自動切換到主路由
R3自動切換到主路由
通過浮動靜態路由的實驗,可以通過該特性,合理的使用,以增加網絡的冗余和穩定性!
關于PNETLAB的Bug:
R1關機狀態,但R2和R3對應的端口還是up,有知道如何解決的朋友,麻煩說下!
