HSRP的相关概念

HSRP(热备份路由选择协议)是思科私有的一种技术,他确保了当网络边缘设备或接入链路出现故障时,备份路由还能正常通信。

HSRP为IP网络提供容错和增强的路由选择功能。


HSRP组成员

活跃路由器:

功能是转发发送到虚拟路由的数据包。活跃路由器通送hello包消息来承担和保持的活跃角色

备份路由器:

功能是来监听HSRP组的运行状态,并且当活跃路由不能运行时来承担转发数据包的责任

虚拟路由器:

功能是提供一台连续工作的路由器。虚拟路由器有自己的IP和mac地址,但不能转发数据包

其他路由器:

监听hello消息但不能应答


HSRP状态与计时器

HSRP状态

初始状态 学习状态 监听状态 发言状态 备份状态 活跃状态

HSRP计时器

Hello间隔(默认3s) 保持时间(默认10s)

HSRP与VRRP的区别?

HSRP

VRRP

Cisco专有协议

IETF制定,不同厂家设备通用协议

六种状态

三种状态(主状态,备份状态,初始状态)

发送UDP报文

发送TCP报文


允许参与VRRP组的设备间建立认证机制(更安全)

HSRP占先权的含义?

优先级高的路由器重新获得转发权,恢复成为活跃路由器

HSRP中端口跟踪的含义

跟踪活跃路由器的端口,发现端口失效,活跃路由器自动降低优先级,将自己变成备份路由器。

HSRP中,路由器选举为活跃路由器的依据

组中最高优先级的路由器将成为活跃路由器,如果优先级相同,IP大的路由器成为

活跃路由器

以下操作实验要求和步骤

按图中要求配置所有设备;

2、在SW1和SW2上配置HSRP(虚拟ip、优先级、占先权、端口跟踪),要求SW1是VLAN10的活跃路由器,同时做VLAN20的备份路由器,SW2是VLAN20的活跃路由器,同时做VLAN10的备份路由器;

3、查看各接口standby的状态注意活跃路由器的位置

4、测试pc1和pc2可以ping通pc3;

5、中断SW1的所有接口,在SW1上查看standby的状态变化,显示VLAN10和VLAN20的活跃路由器都在SW2上,pc1和pc2还可以ping通pc3;

6、重新激活SW1的所有接口,查看SW1是否恢复成为VLAN10的活跃路由器;

             热备份路由选择协议(HSRP)_优先级

PC3> ip 202.1.1.2 202.1.1.1

Checking for duplicate address...


PC1> ip 192.168.2.3 192.168.2.254

Checking for duplicate address...


PC2> ip 192.168.3.2 192.168.3.254

Checking for duplicate address...


R1(config)#int f1/0

R1(config-if)#ip add 202.1.1.1 255.255.255.0

R1(config-if)#no sh

R1(config-if)#int f0/0

R1(config-if)#ip add 10.0.0.1 255.0.0.0

R1(config-if)#no sh

R1(config-if)#int f0/1

R1(config-if)#ip add 20.0.0.1 255.0.0.0

R1(config)#ip route 192.168.2.0 255.255.255.0 10.0.0.2

R1(config)#ip route 192.168.3.0 255.255.255.0 10.0.0.2

R1(config)#ip route 192.168.2.0 255.255.255.0 20.0.0.2

R1(config)#ip route 192.168.3.0 255.255.255.0 20.0.0.2



SW1(config-if)#int f1/0

SW1(config-if)#no sw

SW1(config-if)#ip add 10.0.0.2 255.0.0.0

SW1(config-if)#no sh

SW1(config)#vlan 2

SW1(config-vlan)#vlan 3

SW1(config-vlan)#exit

SW1(config)#interface range f1/1 -2

SW1(config)#sw mo tr

SW1(config)#ip route 202.1.1.0 255.255.255.0 10.0.0.2

SW1(config)#ip route 202.1.1.0 255.255.255.0 20.0.0.2


SW2#conf t

SW2(config)#int f1/0

SW2(config-if)#no sw

SW2(config-if)#ip add 20.0.0.2 255.0.0.0

SW2(config-if)#no sh

SW2(config-if)#exit

SW2(config)#vlan 2

SW2(config-vlan)#vlan 3

SW2(config-vlan)#exit

SW2(config)#int r f1/1 -2

SW2(config-if-range)#sw mo tr

SW2(config-if-range)#exit

SW2(config)#ip route 202.1.1.0 255.255.255.0 20.0.0.1


SW3#conf t

SW3(config)#vlan 2

SW3(config-vlan)#vlan 3

SW3(config-vlan)#exit

SW3(config)#int f1/15

SW3(config-if)#sw ac vlan 2

SW3(config-if)#int f1/14

SW3(config-if)#sw ac vlan 3

SW3(config-if)#int f1/2

SW3(config-if)#sw mo tr

SW3(config-if)#int f1/1

SW3(config-if)#sw mo tr


  1. 配置HSRP实现热备份
  2. 在SW1上配置SW1(config)#int vlan 2
    SW1(config-if)#ip add 192.168.2.1 255.255.255.0
    SW1(config-if)#standby 2 ip 192.168.2.254网关)
    SW1(config-if)#standby 2 priority 150优先级)
    SW1(config-if)#standby 2 preempt (占先权)
    SW1(config-if)#standby 2 track f1/1 100端口跟踪)
    SW1(config-if)#standby 2 track f1/0 100
    SW1(config-if)#exit
    SW1(config)#int vlan 3
    SW1(config-if)#ip add 192.168.3.1 255.255.255.0vlan3的IP)
    SW1(config-if)#standby 3 ip 192.168.3.254网关)
    SW1(config-if)#standby 3 preempt占先权)
  3. 在SW2上配置

SW2(config)#int vlan 2

SW2(config-if)#ip add 192.168.2.2 255.255.255.0

SW2(config-if)#standby 2 ip 192.168.2.254

SW2(config-if)#standby 2 preempt


SW2(config)#int vlan 3

SW2(config-if)#ip add 192.168.3.2 255.255.255.0

SW2(config-if)#standby 3 ip 192.168.3.254

SW2(config-if)#standby 3 priority 150

SW2(config-if)#standby 3 preempt

SW2(config-if)#standby 3 track f1/0 100

SW2(config-if)#standby 3 track f1/2 100


然后查看SW1和SW2的热备状态

SW1#show standby brief

P indicates configured to preempt.

|

Interface Grp Pri P State Active Standby Virtual IP

Vl2 2 150 P Active local 192.168.2.2 192.168.2.254

Vl3 3 100 P Standby 192.168.3.2 local 192.168.3.254


SW2#show standby brief

P indicates configured to preempt.

|

Interface Grp Pri P State Active Standby Virtual IP

Vl2 2 100 P Standby 192.168.2.1 local 192.168.2.254

Vl3 3 150 P Active local 192.168.3.1 192.168.3.254



PC1> ping 202.1.1.1

84 bytes from 202.1.1.1 icmp_seq=1 ttl=254 time=46.513 ms

84 bytes from 202.1.1.1 icmp_seq=2 ttl=254 time=45.453 ms

84 bytes from 202.1.1.1 icmp_seq=3 ttl=254 time=46.213 ms

PC2> ping 202.1.1.2

84 bytes from 202.1.1.2 icmp_seq=1 ttl=62 time=60.896 ms

84 bytes from 202.1.1.2 icmp_seq=2 ttl=62 time=61.572 ms

84 bytes from 202.1.1.2 icmp_seq=3 ttl=62 time=61.312 ms


Sw2#show standby brief

P indicates configured to preempt.

|

Interface Grp Pri P State Active Standby Virtual IP

Vl2 2 100 P Standby 192.168.2.1 local 192.168.2.254

Vl3 3 150 P Active local 192.168.3.1 192.168.3.254


(standby备份路由) (Active 活跃路由)

优先级高的为备份路由,优先级低为活跃路由


接下来测试故障,断掉SW1的f1/0和f1/1,看是否vlan2的主转移到SW2

SW1(config)#int f1/0

SW1(config-if)#shutdown

SW1(config-if)#int f1/1

SW1(config-if)#shutdown


SW1#show standby brief

P indicates configured to preempt.

|

Interface Grp Pri P State Active Standby Virtual IP

Vl2 2 0 P Standby 192.168.2.2 local 192.168.2.254

Vl3 3 100 P Standby 192.168.3.2 local 192.168.3.254



SW2#show standby brief

P indicates configured to preempt.

|

Interface Grp Pri P State Active Standby Virtual IP

Vl2 2 100 P Active local 192.168.2.1 192.168.2.254

Vl3 3 150 P Active local 192.168.3.1 192.168.3.254