所谓的热备份路由协议(HSRP)主要是向我们提供了这样一种机制,它的设计目的主要在于支持IP传输失败情况下的不中断服务。具体说,就是本协议用于在源主机无法动态地学习到首跳路由器IP地址的情况下防止首跳路由的失败。它主要用于多接入,多播和广播局域网(例如以太网)。
      下面做个实验来理解HSPR
 
 网关冗余之HSPR的配置和应用_休闲
 
 
 按照实验拓扑图配置好基础配置,在PCping 10.1.1.1
PC#
PC#ping 192.168.1.1
 
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
 
此时在R1R2中没有运行HSPRPC上的网管192.168.1.1并不存在。所以ping不通
 
R1R2间运行HSRP,构建虚拟网关
R1(config-if)#standby 1 ip 192.168.1.1
R1(config-if)#
*Mar  1 00:07:04.299: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Speak -> Standby    //配置成功,R1处于Standby状态
R2(config-if)#standby 1 ip 192.168.1.1
R2(config-if)#
*Mar  1 00:10:23.579: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Speak -> Standby
*Mar  1 00:10:24.079: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Standby -> Active  //配置成功,R2处于Active状态
 
此时PCping 10.1.1.1
PC#ping 10.1.1.1     
 
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
!!!!!  // 通了
 
查看路径
PC#traceroute 10.1.1.1
 
Type escape sequence to abort.
Tracing the route to 10.1.1.1
 
  1  *  *
    192.168.1.3 52 msec   //是通过R2路由器ping通的,即R2处于Active状态,一般说来,在其他因素都相同的情况下,IP最大的那个路由器将处于Active状态
 
查看路由器R1和路由器R2Standby信息
R1(config-if)#do sh standby
FastEthernet0/0 - Group 1
  State is Standby          // 此路由器处于Standy状态
    1 state change, last state change 00:00:15
  Virtual IP address is 192.168.1.1
  Active virtual MAC address is 0000.0c07.ac01
    Local virtual MAC address is 0000.0c07.ac01 (v1 default)
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 2.484 secs
  Preemption disabled
  Active router is 192.168.1.3, priority 100 (expires in 8.804 sec)
  Standby router is local
  Priority 100 (default 100)
  IP redundancy name is "hsrp-Fa0/0-1" (default)
 
 
R2(config-if)#do sh standby
FastEthernet0/0 - Group 1
  State is Active   // 此路由器处于Standy状态
    2 state changes, last state change 00:00:59
  Virtual IP address is 192.168.1.1
  Active virtual MAC address is 0000.0c07.ac01
    Local virtual MAC address is 0000.0c07.ac01 (v1 default)
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 0.948 secs
  Preemption disabled
  Active router is local
  Standby router is 192.168.1.2, priority 100 (expires in 4.628 sec)
  Priority 100 (default 100)
  IP redundancy name is "hsrp-Fa0/0-1" (default)
HSRP组中的每台路由器均会带有一个优先级。优先级会影响哪一台路由器成为ACTIVE路由器,用于响应客户端的ARP请求。如果在HSRP刚启动,而且每台路由器的优先级均相同,则会优先选择接口IP较高的为ACTIVE路由器
 
 
 
PCping 10.1.1.1 多个数据包,ping中手工downR2上的f0/0接口
R2(config-if)#shut
R2(config-if)#
*Mar  1 00:11:53.051: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Active -> Init
 
PC#ping 10.1.1.1 repeat 100
 
R1(config-if)#
*Mar  1 00:12:57.255: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Standby -> Active
 
Type escape sequence to abort.
Sending 100, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!..!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
可见在R2 down掉后,R1上的接口已经起作用了
 
R2f0/0接口处于UP状态
 
此时路由器处于非抢占状态,我们要想让比较强的R2在接口起来时继续处于Active状态,就应该修改priority值,和启动抢占状态
R2(config-if)#standby 1 priority 200
R2(config-if)#standby 1 preempt
R2(config-if)#
*Mar  1 00:16:55.823: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Standby -> Active         // R2又处于Active状态
 
 
R2的下行线路断后,要想让R1马上起用,要有如下配置:
R1(config-if)#standby 1 preempt
 
R2(config-if)#standby 1 track lo0 160 
 
R2上打开debug消息,手工downLo0口查看
R2#debug standby events
HSRP Events debugging is on
R2#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R2(config)#int lo0
R2(config-if)#shut
R2(config-if)#
*Mar  1 00:21:07.647: HSRP: Fa0/0 Grp 1 Track 1 object changed, state Up -> Down
*Mar  1 00:21:07.647: HSRP: Fa0/0 Grp 1 Priority 200 -> 40
*Mar  1 00:21:08.019: HSRP: Fa0/0 Grp 1 Ignoring Coup (100/192.168.1.2 < 200/192.168.1.3)
*Mar  1 00:21:08.031: HSRP: Fa0/0 API arp proto filter, 0000.0c07.ac01 is active vMAC for grp 1 - filter
*Mar  1 00:21:08.031: HSRP: Fa0/0 Grp 1 Hello  in  192.168.1.2 Active  pri 100 vIP 192.168.1.1
*Mar  1 00:21:08.035: HSRP: Fa0/0 Grp 1 Active router is 192.168.1.2, was local
*Mar  1 00:21:08.035: HSRP: Fa0/0 Grp 1 Standby router is unknown, was 192.168.1.2
*Mar  1 00:21:08.035: HSRP: Fa0/0 Grp 1 Active: g/Hello rcvd from higher pri Active router (100/192.168.1.2)
*Mar  1 00:21:08.035: HSRP: Fa0/0 Grp 1 Active -> Speak
*Mar  1 00:21:08.039: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Active -> Speak
R2(config-if)#
*Mar  1 00:21:08.039: HSRP: Fa0/0 Grp 1 Redundancy "hsrp-Fa0/0-1" state Active -> Speak
*Mar  1 00:21:08.043: HSRP: Fa0/0 API MAC address update
R2(config-if)#
*Mar  1 00:21:09.643: %LINK-5-CHANGED: Interface Loopback0, changed state to administratively down
*Mar  1 00:21:10.643: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to down
R2(config-if)#
*Mar  1 00:21:18.035: HSRP: Fa0/0 Grp 1 Speak: d/Standby timer expired (unknown)
*Mar  1 00:21:18.035: HSRP: Fa0/0 Grp 1 Standby router is local
*Mar  1 00:21:18.035: HSRP: Fa0/0 Grp 1 Speak -> Standby
*Mar  1 00:21:18.035: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Speak -> Standby
R2(config-if)#
*Mar  1 00:21:18.039: HSRP: Fa0/0 Grp 1 Redundancy "hsrp-Fa0/0-1" state Speak -> Standby
 
 
  R1(config-if)#
*Mar  1 00:12:57.255: %HSRP-5-STATECHANGE: FastEthernet0/0 Grp 1 state Standby -> Active   //此时R1处于Active  状态
 
查看R1R2standy的信心
R1(config-if)#do sh standby          
FastEthernet0/0 - Group 1
  State is Active
    8 state changes, last state change 00:00:26
  Virtual IP address is 192.168.1.1
  Active virtual MAC address is 0000.0c07.ac01
    Local virtual MAC address is 0000.0c07.ac01 (v1 default)
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 0.732 secs
  Preemption enabled
  Active router is local  // 处于Active状态
  Standby router is 192.168.1.3, priority 40 (expires in 9.216 sec)
  Priority 100 (default 100)
  IP redundancy name is "hsrp-Fa0/0-1" (default)
 
R2(config-if)#do sh standby
FastEthernet0/0 - Group 1
  State is Standby  // 此时处于Standby状态
    10 state changes, last state change 00:00:19
  Virtual IP address is 192.168.1.1
  Active virtual MAC address is 0000.0c07.ac01
    Local virtual MAC address is 0000.0c07.ac01 (v1 default)
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 1.252 secs
  Preemption enabled
  Active router is 192.168.1.2, priority 100 (expires in 8.088 sec)
  Standby router is local
  Priority 40 (configured 200)  // Priority 变成40
    Track interface Loopback0 state Down decrement 160
  IP redundancy name is "hsrp-Fa0/0-1" (default)