网络冗余架构设计中,必不可少的就是网关冗余功能,而很多核心网中都会用到HSRP(Hot Standby Routing Protocol)协议来实现这个功能。
热备份路由协议(HSRP)是思科公司专有的协议,用于为IP网络提供高可用性和冗余性。它允许多个路由器在一个组中协同工作,提供一个虚拟IP地址,可以用作子网上主机的默认网关。如果主要路由器发生故障,其中一个备用路由器将接管虚拟IP地址,以确保不间断的连接。
从HSRP组中选出的单个路由器负责转发主机发送给虚拟路由器的数据包。这种路由器被称为活动路由器。另一个路由器被选为备用路由器。当主用路由器出现故障时,备用路由器将承担转发报文的责任。虽然可以有任意数量的路由器运行HSRP,但只有主路由器转发发送到虚拟路由器IP地址的报文。
运行HSRP协议的路由器之间通过HSRP hello报文来传递HSRP信息。这些数据包通过用户数据报协议(UDP)端口1985发送到目的IP组播地址224.0.0.2。224.0.0.2是保留的组播地址,用于与所有路由器通信。
主用路由器从配置的IP地址和HSRP虚拟MAC地址发出hello报文。备用路由器从其配置的IP地址和烧录的MAC地址(BIA)中获取hello。这种方式可以使HSRP路由器能够正确地识别彼此。
虚拟MAC地址:0000.0c07.ac** ,其中**为十六进制HSRP组号,根据接口配置。例如,HSRP组1使用HSRP虚拟MAC地址000.00 c07.ac01。相邻局域网段的主机使用正常的ARP (Address Resolution Protocol)进程来解析关联的MAC地址。
尽管HSRP组可以由多个三层设备组成,但在典型的企业环境中,通常由两台汇聚交换机配置HSRP,为所有接入层vlan提供网关冗余。
您至少需要两个路由器来配置HSRP。我们称它们为路由器A和路由器B。
在将参与HSRP组的路由器接口上配置IP地址。
路由器A:
- interface FastEthernet0/0
- ip address 192.168.1.1 255.255.255.0
-
路由器B:
- interface FastEthernet0/0
- ip address 192.168.1.2 255.255.255.0
-
在相同子网上的两个路由器上配置HSRP。HSRP在每个接口上运行。
standby 指令帮助
- Router(config-if)#standby ?
- <0-255> group number
- authentication Authentication
- delay HSRP initialisation delay
- follow Name of HSRP group to follow
- ip Enable HSRP IPv4 and set the virtual IP address
- mac-refresh Refresh MAC cache on switch by periodically sending packet
- from virtual mac address
- name Redundancy name string
- preempt Overthrow lower priority Active routers
- priority Priority level
- redirect Configure sending of ICMP Redirect messages with an HSRP
- virtual IP address as the gateway IP address
- timers Hello and hold timers
- track Priority tracking
- version HSRP version
-
路由器A:
- interface FastEthernet0/0
- standby 1 ip 192.168.1.250
- standby 1 priority 110
- standby 1 preempt
-
路由器B:
- interface FastEthernet0/0
- standby 1 ip 192.168.1.250
- standby 1 priority 100
- standby 1 preempt
-
-------啊
您可以使用以下命令验证HSRP状态:
- show standby
- show standby brief
-
这些命令将显示HSRP组的当前状态以及路由器的活动/备用状态。
在RouterA故障的情况下,RouterB将承担HSRP的主动角色。但是,即使RouterA在故障恢复后,RouterB仍将充当活动路由器。这种情况可以在RouterA配置抢占来改变主备角色。在配置抢占时,可以指定抢占的延迟时间。
- Router(config-if)#standby 50 preempt delay ?
- minimum Delay at least this long
- reload Delay after reload
- sync Wait for IP redundancy clients
-
如果需要保证该组HSRP的安全性,可以对该HSRP通信配置Authentication。
- Router(config-if)#standby 50 authentication ?
- md5 Use MD5 authentication
- text Plain text authentication
-
- Router(config-if)#standby 50 authentication md5 ?
- key-chain Set key chain
- key-string Set key string
-
- *** This is how you do it with a Key String ****
- Router(config-if)#standby 50 authentication md5 key-string 0 MRN-China
-
- **** This is how you do it with Key-Chain ******
- Router(config-if)#standby 50 authentication md5 key-chain MRN
- Router(config)#key chain MRN
- Router(config-keychain)#?
- Key-chain configuration commands:
- default Set a command to its defaults
- exit Exit from key-chain configuration mode
- key Configure a key
- no Negate a command or set its defaults
-
- Router(config-keychain)#key ?
- <0-2147483647> Key identifier
-
- Router(config-keychain)#key 1 ?
- <cr>
- Router(config-keychain)#key 1
- Router(config-keychain-key)#?
- Key-chain key configuration commands:
- accept-lifetime Set accept lifetime of key
- default Set a command to its defaults
- exit Exit from key-chain key configuration mode
- key-string Set key string
- no Negate a command or set its defaults
- send-lifetime Set send lifetime of key
-
- Router(config-keychain-key)#key-string ?
- 0 Specifies an UNENCRYPTED password will follow
- 7 Specifies a HIDDEN password will follow
- LINE The UNENCRYPTED (cleartext) user password
-
- Router(config-keychain-key)#key-string 0 MRN
-
默认的Hello Time是3秒,默认的Hold Time是10秒。如果希望使HSRP故障转移更快地发生,可以更改这些值。以秒为单位,可以转到最小15秒的Hello Time。但是如果你想让它更快,你可以在Hello Time中指定以毫秒为单位。
- Router(config-if)#standby 50 timers ?
- <1-254> Hello interval in seconds
- msec Specify hello interval in milliseconds
-
- *** How to set Hello Time 333 ms & Hold Time 1s (or 1000 ms) ***
- Router(config-if)#standby 50 timers msec 333 msec 1000
-
HSRP有两个版本:版本1和版本2。默认情况下,如果不指定版本,则为版本1。您可以配置“standby 50 version 2”来更改版本。
- Router(config-if)#standby 50 version 2
-
HSRP version 1和version 2 主要有七点差异
如您需要更加深入的了解,可以从思科的HSRP-FAQ文档中找到更多有用的信息。