一、拓撲圖:
二、單組的HSRP配置及說明:
1、用路由器模拟三層交換機,同時R1和R2中的回環接口模拟某主機與R1、R2直連。
R1(config-line)#int lo0
R1(config-if)#ip add 10.1.1.1 255.255.255.0
R1(config-if)#int f0/0
R1(config-if)#no sh
R1(config-if)#ip add 192.168.1.2 255.255.255.0
R2(config-line)#int lo0
R2(config-if)#ip add 10.1.1.1 255.255.255.0
R2(config-if)#int f0/0
R2(config-if)#ip add 192.168.1.3 255.255.255.0
PC1(config)#no ip routing
PC1(config)#ip default-gateway 192.168.1.1 (網關配置為HSRP虛拟的網關位址)
PC1(config)#int f0/0
PC1(config-if)#no sh
PC1(config-if)#ip add 192.168.1.10 255.255.255.0
2、為了有效的確定網關的備援,我們在R1和R2上配置HSRP協定:
R1(config-if)#standby ip 192.168.1.1(設定組0虛拟IP,在standby後面不跟組時,預設為0組)
R2(config-if)#standby ip 192.168.1.1
3、啟用HSRP組0之後,IOS指出目前R1為active路由器,負責arp響應和三層路由任務:
*Mar 1 00:33:23.963: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 0 state Standby -> Active
4、檢視一下R1和R2的standby 資訊:
R1(config-if)#do sh standby
FastEthernet0/0 - Group 0 (指出為組)
State is Active (指出目前為活動狀态)
2 state changes, last state change 00:11:49
Virtual IP address is 192.168.1.1(指出虛拟路由器IP為192.168.1.1,也為用戶端指定的網關)
Active virtual MAC address is 0000.0c07.ac00(虛拟路由器的MAC位址)
Local virtual MAC address is 0000.0c07.ac00 (v1 default)
Hello time 3 sec, hold time 10 sec(HSRP的HELLO發送周期和保持時間用于監測ACTIVE路由器狀态)
Next hello sent in 1.672 secs
Preemption disabled (強占沒有開啟)
Active router is local
Standby router is 192.168.1.3, priority 100 (expires in 8.864 sec)(指出備份路由器IP和優先級)
Priority 100 (default 100) (在沒有指定優先級的情況下,都為100)
IP redundancy name is "hsrp-Fa0/0-0" (default)
R2#sh standby
FastEthernet0/0 - Group 0
State is Standby (狀态為備份)
1 state change, last state change 00:00:29
Virtual IP address is 192.168.1.1
Active virtual MAC address is 0000.0c07.ac00
Local virtual MAC address is 0000.0c07.ac00 (v1 default)
Hello time 3 sec, hold time 10 sec
Next hello sent in 0.668 secs
Preemption disabled
Active router is 192.168.1.2, priority 100 (expires in 9.656 sec)(指出活動路由器IP和優先級)
Standby router is local
Priority 100 (default 100)
IP redundancy name is "hsrp-Fa0/0-0" (default)
5、HSRP組中的每台路由器均會帶有一個優先級。優先級會影響哪一台路由器成為active路由器,用于響應用戶端的ARP請求。如果在HSRP剛啟動,而且每台路由器的優先級均相同,則會優先選擇接口IP較高的為ACTIVE路由器。但如果在一台路由器配置好之後再去配置另一台,且是優先級相同,那麼會選擇先配置的那台路由器成為active路由器。這裡路由器就選擇了R1成為active。
6、在PC1上traceroute一下10.1.1.1,并查一下ARP資訊:
PC1#traceroute 10.1.1.1
Type escape sequence to abort.
Tracing the route to 10.1.1.1
1 192.168.1.2 32 msec * 32 msec (因為R1為active,是以它選擇了走R1)
PC1#sh arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 192.168.1.10 - cc00.0a88.0000 ARPA FastEthernet0/0
Internet 192.168.1.1 29 0000.0c07.ac00 ARPA FastEthernet0/0(看到虛拟網關的IP位址和MAC位址,其中MAC含義:0000.0c為cisco廠商辨別,07.ac為HSRP組辨別,01為HSRP組号)
7、為了檢視HSRP的備援作用我們使用擴充ping 向10.1.1.1/24發送較多的包,并且把R1的F0/0 down掉,我們發現丢了兩個包之後轉向備援路由器了:
PC1#ping
Protocol [ip]:
Target IP address: 10.1.1.1
Repeat count [5]: 100000
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]:
Sweep range of sizes [n]:
Sending 100000, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!..!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(丢了兩個包後又起來了)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.(這裡還有一個包)
Success rate is 99 percent (2142/2145), round-trip min/avg/max = 1/9/64 ms
PC1#
R1(config)#int f0/0
R1(config-if)#shut (手動down掉f0/0)
1 192.168.1.3 40 msec * 40 msec (跟蹤指令發現下一跳為R2了)
8、下面我們把R1的F0/0置為up後,過一段時間後發現R1還是standby角色:
R1#
*Mar 1 01:44:39.779: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 0 state Speak -> Standby
R1#sh standby
FastEthernet0/0 - Group 0
State is Standby
4 state changes, last state change 00:04:35
Virtual IP address is 192.168.1.1
Active virtual MAC address is 0000.0c07.ac00
Local virtual MAC address is 0000.0c07.ac00 (v1 default)
Hello time 3 sec, hold time 10 sec
Next hello sent in 0.464 secs
Preemption disabled
Active router is 192.168.1.3, priority 100 (expires in 8.172 sec) (指出活動路由器為R2)
Standby router is local
Priority 100 (default 100)
IP redundancy name is "hsrp-Fa0/0-0" (default)
9、但如果R1這台性能比較好,R2隻想讓它在R1出問題的情況下頂替上來,是以更希望當R1恢複時,能夠負責ARP的響應和三層路由任務。那麼我們要為R1配置較高的優先級,并且配置HSRP搶占功能:
R1(config-if)#standby priority 120 (設定R1的HSRP優先級為120)
R1(config-if)#standby preempt (開啟HSRP的搶占功能)
*Mar 1 09:37:03.313: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 0 state Standby -> Active
(配置完之後,提示資訊馬上就顯示了狀态從standby變成active)
10、如果R1的上行鍊路lo0 down的話,而PC1将不會意識到走R1将會不通。會繼續把R1當作下一跳,但HSRP除了能夠對下行鍊路實施備援,同時也可以對上行鍊路進行監測。是以為了確定萬無一失,我們需要對上行鍊路進行跟蹤:
R1(config-if)#standby track lo0 30 (對loopback0跟蹤,如果發現有問題,優先級将會降30,那麼将是120-30=90,比R2的100低,這樣R2将會成為active。)
11、把R1上的loopback0 down掉之後,看到HSRP的顯示R1狀态變成standby:
State is Standby (跟蹤端口down後,接口優先級降30。Hello包接收到更高的優先級,新狀态standby)
15 state changes, last state change 00:00:42
Next hello sent in 2.580 secs
Preemption enabled
Active router is 192.168.1.3, priority 100 (expires in 8.604 sec)
Priority 90 (configured 120)
Track interface Loopback0 state Down decrement 30 (配置的跟蹤)
本文轉自wxs-163 51CTO部落格,原文連結:
http://blog.51cto.com/supercisco/288456