3分钟详细了解HSRP热备份路由协议

HSRP 概述

HSRP 热备份路由协议是一种私有技术,它确保了网络边缘设备或接入链路出现故障时,用户通信能迅速并透明地恢复,以此为IP网络提供冗余性。热备份路由协议为IP网络提供容错和增强的路由选择功能。

通过使用一个虚拟的IP地址和虚拟MAC地址,LAN网段上的两台或者多台路由器可以作为一台虚拟路由器对外提供服务。

HSRP 组成员

HSRP备份有一台活跃路由器,一台备份路由器,一台虚拟路由器和其他路由器组成。

活跃路由器:主要功能是转发到虚拟路由器的数据包。组中的另一台路由器被选为备份路由器。活跃路由器通过发送Hello消息来承担和保持它活跃的角色。

备份路由器:只要功能是监视HSRP组的运行状态,并且到活跃路由器不能运行时,迅速承担起转发数据包的责任。备份路由器也传输Hello消息,告知组中所有路由器备份路由器的角色和状态变化。

虚拟路由器:主要功能是想最终用户提供一台可以连续工作的路由器。虚拟路由器配置有它自己的IP地址和MAC地址,但并不实际转发数据包。

其他路由器:这些路由器监视Hello消息,但不做应答。这些路由器转发任何经由他们的数据包,但并不转发经由虚拟路由器的数据包。

HSRP原理

HSRP组内的每个路由器都有指定的优先级,用于衡量路由器在活跃路由器选择中的优先程度。

默认优先级为100(可配置范围0-255),组中最高优先的路由器将成为活跃路由器,其次的为备份路由器。当优先级相同的情况下,将比较路由器的LAN口IP地址,地址大的将成为活跃路由器。

当终端用户向虚拟路由器提交数据时,将由活跃路由器进行处理,当活跃路由器发生故障时,备份路由器将在数秒之内承担活跃路由器的工作,这时由于备份成为了活跃路由器,而备份路由器的位置空缺,组内其它路由器将晋升备份路由器,再次比较优先级选出备份路由器。

HSRP 配置

1、拓扑:

在路由器上和三层交换机上配置HSRP。使用路由器模拟PC。

2、实验步骤:

Router(config)#hostname R1

R1(config)#line console 0

R1(config-line)#exec-timeout 0 0

R1(config-line)#logging synchronous

R1(config-line)#exit

R1(config)#no ip domain-lookup

R1(config)#interface fastEthernet 0/0

R1(config-if)#ip address 192.168.13.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#exit

R1(config)#interface s2/0

R1(config-if)#ip address 192.168.12.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#exit

R1(config)#router rip

R1(config-router)version 2

R1(config-router)no auto-summary

R1(config-router)#network 192.168.12.0

R1(config-router)#network 192.16.13.0

R1(config-router)#passive-interface f0/0 //把f0/0接口设置为被动接口,防止从此接口发送RIP信息给R3。

R1(config-router)#exit

Router>enable

Router#configure

Configuring from terminal, memory, or network [terminal]?

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#line console 0

Router(config-line)#exec-timeout 0 0

Router(config-line)#logging synchronous

Router(config-line)#exit

Router(config)#no ip domain-lookup

Router(config)#hostname R2

R2(config)#interface lo0

R2(config-if)#ip address 192.168.2.2 255.255.255.0

R2(config-if)#exit

R2(config)#interface s2/0

R2(config-if)#ip address 192.168.12.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#exit

R2(config)#interface s2/1

R2(config-if)#ip address 192.168.23.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#exit

R2(config)#router rip

*Aug 20 19:55:10.071: %LINK-3-UPDOWN: Interface Serial2/1, changed state to up

R2(config)#router rip

R2(config-router)version 2

R2(config-router)no auto-summary

R2(config-router)#network 192.168.12.0

R2(config-router)#network 192.168.23.0

R2(config-router)#network 192.168.2.0

R2(config-router)#exit

Router>enable

Router#configure

Configuring from terminal, memory, or network [terminal]?

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#line console 0

Router(config-line)#exec-timeout 0 0

Router(config-line)#logging synchronous

Router(config-line)#exit

Router(config)#no ip domain-lookup

Router(config)#hostname R3

R3(config)#interface fastEthernet 0/0

R3(config-if)#ip address 192.168.13.3 255.255.255.0

R3(config-if)#no shutdown

R3(config-if)#exit

R3(config)#interface s2/1

R3(config-if)#ip address 192.168.23.3 255.255.255.0

R3(config-if)#no shutdown

R3(config-if)#exit

R3(config)#router rip

R3(config-router)#network 192.168.13.0

R3(config-router)#network 192.168.23.0

R3(config-router)#passive-interface fastEthernet 0/0

R3(config-router)#exit

配置HSRP

R1(config)#int

R1(config)#interface f0/0

R1(config-if)#standby 1 ip 192.168.13.254

//启用HSRP功能,并设置虚拟IP地址,1 为standby的组号。相同组号的路由器属于同一个HSRP组,同一个组的HSRP路由器虚拟地址必须一致

R1(config-if)#standby 1 priority 120

//配置HSRP的优先级,默认100.值大的路由器为活动路由器

R1(config-if)#standby 1 preempt

//开启抢占功能,如果不开启,就算优先级权值再高,也不会成为活动路由器

R1(config-if)#standby 1 timers 3 10

//每隔3s发送一次hello信息 ,10s没有收到活动路由器的信息,则认为活动路由器发生故障。默认值为3和10 ,相同组的该设置必须一致

R1(config-if)#standby 1 authentication md5 key-string cisco

//配置认证密码,防止非法设备加入到HSRP组,同一个组密码必须一致。

R1(config-if)#exit

R3(config)#interface f0/0

R3(config-if)#standby 1 ip 192.168.13.254

R3(config-if)#standby 1 preempt

R3(config-if)#standby 1 timers 3 10

R3(config-if)#standby 1 authentication md5 key-string cisco

R3(config-if)#exit

//没有设置优先级,默认100

3、检测:

PC ping 192.168.2.2

是R1接口断开,查看现象。


版权声明:本文转载自公众号“bjfwcx”,版权归原作者所有,转载请保留此字段,感谢!

举报
评论 0