1. 程式人生 > >配置熱備份路由協議(HSRP)

配置熱備份路由協議(HSRP)

0ms standby color watermark end 自動 出口 evel 網絡拓撲圖

案例:HSRP配置
1.1 問題

在企業網絡到外部的連接方案中,要求不高的條件下可以是單出口。一旦該出口線路出現問題,整個企業網絡就不能連接到外網了。為了使得企業網絡到外網連接的高可用性,可以設置兩個以上的出口,然而多個出口對於內網主機意味著我個網關。主機不能同時使用多個網關,當主機所使用的網關出現故障時,它不能實現網關的自動切換。

配置熱備份路由協議

1.2 方案

在出口設備上配置熱備份路由協議(HSRP),組成一個HSRP組,組內兩個出口設備共享一個虛擬IP地址,該IP地址作為內網主機的網關。

HSRP組成員有主備之分,虛擬IP地址被附加到主設備上。如果主設備線路出故障,備份設備會成為主設備,虛擬IP地址也會遷移過來。這樣,不管哪一個出口設備出現問題,不管哪個出口設備在提供外網接入,內網主機的網關都不需要改變。

網絡拓撲圖如圖-1所示:

技術分享圖片
圖-1
1.3 步驟

實現此案例需要按照如下步驟進行。

步驟一:分別在三臺路由器上配置端口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上配置到外網的默認路由

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

配置熱備份路由協議(HSRP)