概述
- HSRP能防止路由器單點(diǎn)失效從而提供網(wǎng)絡(luò)的高可用性。雙機(jī)冗余需要用到HSRP。
- 在一個(gè)HSRP組內(nèi)的多個(gè)路由器共用一個(gè)虛擬的物理地址和IP地址。HSRP協(xié)議決定na個(gè)路由器被激活,該被激活的路由器接收發(fā)過來的數(shù)據(jù)包并進(jìn)行路由。
- HSRP使用組播、基于UDP的呼叫信號(hào)包來實(shí)現(xiàn)與同一HSRP組內(nèi)其它路由器之間的通信,組內(nèi)的各路由器之間交換呼叫信號(hào),如果當(dāng)前路由器變得無法使用,備用路由器將進(jìn)入激活狀態(tài),接管路由任務(wù)。
實(shí)驗(yàn)拓?fù)渑c說明

image
- 路由器R1和R2的e0/0接口IP設(shè)置為192.168.20.252和192.168.20.253,公用standby IP為192.168.20.254
- R1為主,R1的優(yōu)先級(jí)為200,R2為備,它的優(yōu)先級(jí)為150
- linux測(cè)試主機(jī)的IP為192.168.20.1
實(shí)驗(yàn)?zāi)繕?biāo)
- 配置實(shí)現(xiàn)兩臺(tái)路由器雙機(jī)冗余互備
- 怎樣查看冗余互備的情況
需要用到的命令
- standby ip:用于激活HSRP
- standby priority:用于設(shè)定端口的HSRP優(yōu)先級(jí),具有最高備份優(yōu)先級(jí)的HSRP成員將成為激活路由器(假設(shè)設(shè)置為優(yōu)先權(quán)方式)
- standby timers:用于設(shè)定 hello包之間的時(shí)間間隔( hello time)以及路由器在多長一個(gè)時(shí)間段內(nèi)沒有從HSRP鄰居收到 hello包就判定該鄰居已關(guān)閉( hold time)。
- standby preempt:表明當(dāng)本地路由器的備份優(yōu)先級(jí)超過當(dāng)前激活路由器時(shí),它就將接管控制權(quán),成為激活路由器
- standby track:用于設(shè)置允許路由器端口根據(jù)另一端口的可用性而修改自己的HSRP優(yōu)先級(jí)值
配置步驟
R1的配置
Router>en
Router#configure terminal
Router(config)#hostname R1
R1(config)#interface e0/0
R1(config-if)#ip address 192.168.20.252 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#standby priority 200 //設(shè)置優(yōu)先級(jí)
R1(config-if)#standby preempt
R1(config-if)#standby ip 192.168.20.254 //standby ip 為兩臺(tái)路由器共用
R2的配置
Router>en
Router#configure terminal
Router(config)#hostname R2
R2(config)#interface e0/0
R2(config-if)#ip address 192.168.20.253 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#standby priority 150
R2(config-if)#standby preempt
R2(config-if)#standby ip 192.168.20.254
至此,HRSP雙機(jī)熱備完成配置
測(cè)試
-
在主機(jī)上ping standby IP,下圖顯示已經(jīng)可以ping了
image
在路由器上檢查設(shè)備狀態(tài)
- 在R1上,狀態(tài)是
State is Active
R1#show standby
Ethernet0/0 - Group 0
State is Active
2 state changes, last state change 04:07:11
Virtual IP address is 192.168.20.254
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 //3s相互發(fā)hello,10s接受不到邊切換
Next hello sent in 1.792 secs
Preemption enabled
Active router is local
Standby router is 192.168.20.253, priority 150 (expires in 9.904 sec)
Priority 200 (configured 200)
Group name is "hsrp-Et0/0-0" (default)
- 在R2上,狀態(tài)是
State is Standby
R2#show standby
Ethernet0/0 - Group 0
State is Standby
1 state change, last state change 04:05:46
Virtual IP address is 192.168.20.254
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 2.848 secs
Preemption enabled
Active router is 192.168.20.252, priority 200 (expires in 8.912 sec)
Standby router is local
Priority 150 (configured 150)
Group name is "hsrp-Et0/0-0" (default)
通過debug來查看兩設(shè)備之間的通信信息
- 在正常的情況下,在任一臺(tái)路由器上
debug standby,每隔3秒左右,就看兩臺(tái)設(shè)備互發(fā)信息
R1#debug standby
HSRP debugging is on
R1#
*Jan 2 02:22:43.438: HSRP: Et0/0 Grp 0 Hello in 192.168.20.253 Standby pri 150 vIP 192.168.20.254
*Jan 2 02:22:44.000: HSRP: Et0/0 Grp 0 Hello out 192.168.20.252 Active pri 200 vIP 192.168.20.254
R1#
R1#no debug standby
HSRP debugging is off
- 斷掉R1的e0/0連線,測(cè)試R2是否接管
在R2 debug standby可以看到切換的信息

image
在R2上show standby可以R2已經(jīng)變?yōu)锳ctive了
R2#
*Jan 2 02:40:25.369: HSRP: Et0/0 Grp 0 Hello out 192.168.20.253 Active pri 15 R2#show standby
Ethernet0/0 - Group 0
State is Active //R2已經(jīng)變?yōu)锳ctive了
2 state changes, last state change 00:02:07
Virtual IP address is 192.168.20.254
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 1.200 secs
Preemption enabled
Active router is local
Standby router is unknown
Priority 150 (configured 150)
Group name is "hsrp-Et0/0-0" (default)
R2#
當(dāng)R1恢復(fù)正常后,會(huì)變回主設(shè)備
