案例:HSRP配置
1.1 問題網絡
在企業網絡到外部的鏈接方案中,要求不高的條件下能夠是單出口。一旦該出口線路出現問題,整個企業網絡就不能鏈接到外網了。爲了使得企業網絡到外網鏈接的高可用性,能夠設置兩個以上的出口,然而多個出口對於內網主機意味着我個網關。主機不能同時使用多個網關,當主機所使用的網關出現故障時,它不能實現網關的自動切換。ide
配置熱備份路由協議
1.2 方案測試
在出口設備上配置熱備份路由協議(HSRP),組成一個HSRP組,組內兩個出口設備共享一個虛擬IP地址,該IP地址做爲內網主機的網關。日誌
HSRP組成員有主備之分,虛擬IP地址被附加到主設備上。若是主設備線路出故障,備份設備會成爲主設備,虛擬IP地址也會遷移過來。這樣,無論哪個出口設備出現問題,無論哪一個出口設備在提供外網接入,內網主機的網關都不須要改變。code
網絡拓撲圖如圖-1所示:blog
圖-1
1.3 步驟接口
實現此案例須要按照以下步驟進行。ip
步驟一:分別在三臺路由器上配置端口IP地址路由
tarena-R1(config)# interface f0/0 tarena-R1(config-if)#ip address 192.168.1.252 255.255.255.0 tarena-R1(config-if)#no shutdown tarena-R1(config-if)#interface f0/1 tarena-R1(config-if)#ip address 192.168.2.1 255.255.255.0 tarena-R1(config-if)#no shutdown tarena-R2(config)#interface f0/0 tarena-R2(config-if)#ip address 192.168.1.253 255.255.255.0 tarena-R2(config-if)#no shutdown tarena-R2(config-if)#interface f0/1 tarena-R2(config-if)#ip address 192.168.3.1 255.255.255.0 tarena-R2(config-if)#no shutdown tarena-R3(config)#interface f0/0 tarena-R3(config-if)#ip address 192.168.2.2 255.255.255.0 tarena-R3(config-if)#no shutdown tarena-R3(config-if)#interface f0/1 tarena-R3(config-if)#ip address 192.168.3.2 255.255.255.0 tarena-R3(config-if)#no shutdown tarena-R3(config-if)#interface f1/0 tarena-R3(config-if)#ip address 192.168.4.254 255.255.255.0 tarena-R3(config-if)#no shutdown
步驟二:在R1和R2上配置到外網的默認路由it
tarena-R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.2.2 tarena-R1(config)#end tarena-R1#show ip route Codes: C - connected, S - static, I - IGRP, 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, E - EGP i - IS-IS, 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 192.168.1.2 to network 0.0.0.0 C 192.168.1.0/24 is directly connected, FastEthernet0/0 C 192.168.2.0/24 is directly connected, FastEthernet0/1 S* 0.0.0.0/0 [1/0] via 192.168.2.2 tarena-R1# tarena-R2(config)#ip route 0.0.0.0 0.0.0.0 192.168.3.2 tarena-R2(config)#exit tarena-R2#show ip route Codes: C - connected, S - static, I - IGRP, 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, E - EGP i - IS-IS, 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 192.168.2.2 to network 0.0.0.0 C 192.168.1.0/24 is directly connected, FastEthernet0/0 C 192.168.3.0/24 is directly connected, FastEthernet0/1 S* 0.0.0.0/0 [1/0] via 192.168.3.2
步驟三:在R3上配置到企業內網的靜態路由
tarena-R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1 tarena-R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.3.1 tarena-R3(config)#end tarena-R3#show ip route Codes: C - connected, S - static, I - IGRP, 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, E - EGP i - IS-IS, 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 S 192.168.1.0/24 [1/0] via 192.168.2.1 [1/0] via 192.168.3.1 C 192.168.2.0/24 is directly connected, FastEthernet0/0 C 192.168.3.0/24 is directly connected, FastEthernet0/1 C 192.168.4.0/24 is directly connected, FastEthernet1/0 tarena-R3#
步驟四:在R1上配置HSRP,指定其優先級爲200
HSRP的默認優先級爲100,路由器啓動後,根據優先級決定誰能夠成爲活躍路由器,優先級高的將勝出。若是路由器優先級相同,再比較端口IP地址,IP地址大的成爲活路躍路由器。
另外,若是優先級低的路由器先啓動了,它將成爲活躍路由器。優先級高的路由器啓動後,發現已有活躍路由器存在,它將接受現狀,直到活躍路由器出現故障它纔會在從新選舉時成爲活躍角色。
tarena-R1(config)#interface f0/0 tarena-R1(config-if)#standby 1 ip 192.168.1.254 tarena-R1(config-if)#standby 1 priority 200 %HSRP-6-STATECHANGE: FastEthernet0/0 Grp 1 state Speak -> Standby %HSRP-6-STATECHANGE: FastEthernet0/0 Grp 1 state Standby -> Active
配置HSRP後,經過輸出日誌能夠觀察到路由器角色的改變。
步驟五:在R2上配置HSRP,指定其優先級爲195
tarena-R2(config)#interface f0/0 tarena-R2(config-if)#standby 1 ip 192.168.1.254 tarena-R2(config-if)#standby 1 priority 195 %HSRP-6-STATECHANGE: FastEthernet0/0 Grp 1 state Speak -> Standby
步驟六:分別在R1和R2上查看HSRP信息
tarena-R1#show standby brief P indicates configured to preempt. | Interface Grp Pri P State Active Standby Virtual IP Fa0/0 1 200 Active local 192.168.1.253 192.168.1.254 tarena-R2#show standby brief P indicates configured to preempt. | Interface Grp Pri P State Active Standby Virtual IP Fa0/0 1 195 Standby 192.168.2.252 local 192.168.1.254
步驟七:在內部主機上測試到外網主機的連通性
SERVER>ipconfig FastEthernet0 Connection:(default port) Link-local IPv6 Address.........: FE80::207:ECFF:FE80:557D IP Address......................: 192.168.1.1 Subnet Mask.....................: 255.255.255.0 Default Gateway.................: 192.168.1.254 PC>ping 192.168.4.1 Pinging 192.168.4.1 with 32 bytes of data: Reply from 192.168.4.1: bytes=32 time=0ms TTL=126 Reply from 192.168.4.1: bytes=32 time=0ms TTL=126 Reply from 192.168.4.1: bytes=32 time=0ms TTL=126 Reply from 192.168.4.1: bytes=32 time=1ms TTL=126 Ping statistics for 192.168.4.1 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 1ms, Average = 0ms
步驟八:在R1配置端口跟蹤、R2配置佔先權
tarena-R1(config)#interface fastEthernet 0/0 tarena-R1(config-if)#standby 1 track f0/1 tarena-R2(config)#interface fastEthernet 0/0 tarena-R2(config-if)#standby 1 preempt
步驟九:關閉R1的f0/1接口,模擬設備故障,查看R2的HSRP信息
tarena-R1(config)#interface fastEthernet 0/1 tarena-R1(config-if)#shutdown tarena-R2#show standby brief P indicates configured to preempt. | Interface Grp Pri P State Active Standby Virtual IP Fa0/0 1 195 Active local unknown 192.168.1.254
結果顯示R2已成爲活躍路由器,而備份路由器狀態未知。虛擬路由器的IP地址192.168.1.254/24也已遷移到R2上了。
步驟十:在R1配置佔先權,並激活R1的f0/1接口並查狀態
備份路由器成爲活躍路由器後,原來的活躍路由器R1即便線路修復也不會從新成爲進入活躍狀態。
爲了使路由器徹底根據優先級來決定其狀態,須要配置佔先權。佔先權保證了嚴格根據優先級來決定哪臺設備進入活躍狀態。
tarena-R1(config)#interface f0/0 tarena-R1(config-if)#standby 1 preempt tarena-R1(config)#interface f0/1 tarena-R1(config-if)#no shutdown tarena-R1#show standby brief P indicates configured to preempt. | Interface Grp Pri P State Active Standby Virtual IP Fa0/0 1 200 Active local 192.168.1.253 192.168.1.254