随着Internet的日益普及,人们对网络的依赖性也越来越强。这同时对网络的稳定性提出了更高的要求,人们自然想到了基于设备的备份结构,就像在服务器中为提高数据的安全性而采用双硬盘结构一样。路由器是整个网络的核心和心脏,如果路由器发生致命性的故障,将导致本地网络的瘫痪,如果是骨干路由器,影响的范围将更大,所造成的损失也是难以估计的。因此,对路由器采用热备份是提高网络可靠性的必然选择。在一个路由器完全不能工作的情况下,它的全部功能便被系统中的另一个备份路由器完全接管,直至出现问题的路由器恢复正常,这就是热备份路由协议(HotStandbyRouterProtocal),HSR��PRFC2281技术要解决的问题。
一、HSRP协议概述
实现HSRP的条件是系统中有多台路由器,它们组成一个"热备份组",这个组形成一个虚拟路由器。在任一时刻,一个组内只有一个路由器是活动的,并由它来转发数据包,如果活动路由器发生了故障,将选择一个备份路由器来替代活动路由器,但是在本网络内的主机看来,虚拟路由器没有改变。所以主机仍然保持连接,没有受到故障的影响,这样就较好地解决了路由器切换的问题。
为了减少网络的数据流量,在设置完活动路由器和备份路由器之后,只有活动路由器和备份路由器定时发送HSRP报文。如果活动路由器失效,备份路由器将接管成为活动路由器。如果备份路由器失效或者变成了活动路由器,将有另外的路由器被选为备份路由器。
在实际的一个特定的局域网中,可能有多个热备份组并存或重叠。每个热备份组模仿一个虚拟路由器工作,它有一个Well-known-MAC地址和一个IP地址。该IP地址、组内路由器的接口地址、主机在同一个子网内,但是不能一样。当在一个局域网上有多个热备份组存在时,把主机分布到不同的热备份组,可以使负载得到分担。
二、HSRP的工作原理
HSRP协议利用一个优先级方案来决定哪个配置了HSRP协议的路由器成为默认的主动路由器。如果一个路由器的优先级设置的比所有其他路由器的优先级高,则该路由器成为主动路由器。路由器的缺省优先级是100,所以如果只设置一个路由器的优先级高于100,则该路由器将成为主动路由器。
通过在设置了HSRP协议的路由器之间广播HSRP优先级,HSRP协议选出当前的主动路由器。当在预先设定的一段时间内主动路由器不能发送hello消息时,优先级最高的备用路由器变为主动路由器。路由器之间的包传输对网络上的所有主机来说都是透明的。
配置了HSRP协议的路由器交换以下三种多点广播消息:
Hello---hello消息通知其他路由器发送路由器的HSRP优先级和状态信息,HSRP路由器默认为每3秒钟发送一个hello消息;
Coup---当一个备用路由器变为一个主动路由器时发送一个coup消息;
Resign---当主动路由器要宕机或者当有优先级更高的路由器发送hello消息时,主动路由器发送一个resign消息。在任一时刻,配置了HSRP协议的路由器都将处于以下六种状态之一:
Initial---HSRP启动时的状态,HSRP还没有运行,一般是在改变配置或端口刚刚启动时进入该状态。
learn---路由器已经得到了虚拟IP地址,但是它既不是活动路由器也不是等待路由器。它一直监听从活动路由器和等待路由器发来的HELLO报文。
Listen---路由器正在监听hello消息。
Speak---在该状态下,路由器定期发送HELLO报文,并且积极参加活动路由器或等待路由器的竞选。
Standby---当主动路由器失效时路由器准备接管包传输功能。
Active---路由器执行包传输功能。
三、案例学习
1.网络拓扑结构
2.2621路由器:
Router#show run
Building configuration...
Current configuration : 902 bytes
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname Router
!
enable secret 5 $1$FNST$1jR6ovSbqyaYGsErswvAj/
!
ip subnet-zero
!
fax interface-type fax-mail
mta receive maximum-recipients 0
!
interface FastEthernet0/0
ip address 192.168.1.253 255.255.255.0
ip nat inside
duplex auto
speed auto
standby 1 ip 192.168.1.254
standby 1 priority 110
standby 1 preempt
!
interface FastEthernet0/1
ip address 10.30.1.178 255.255.255.0
ip nat outside
duplex auto
speed auto
!
ip nat inside source list 11 interface FastEthernet0/1 overload
ip classless
ip route 0.0.0.0 0.0.0.0 10.30.1.1
ip http server
ip pim bidir-enable
!
!
access-list 11 permit 192.168.1.0 0.0.0.255
!
call rsvp-sync
!
mgcp profile default
!
dial-peer cor custom
!
line con 0
line aux 0
line vty 0 4
password cisco
login
!
!
end
Router#
3.3550交换机配置
Router#telnet 10.30.1.193
Trying 10.30.1.193 ... Open
User Access Verification
Password:
3550>en
Password:
3550#show run
Building configuration...
Current configuration : 3803 bytes
!
version 12.1
no service pad
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname 3550
!
enable secret 5 $1$fuzU$uHYzd5qz/vNVQ.xXIeWJe0
!
ip subnet-zero
!
!
spanning-tree mode pvst
spanning-tree extend system-id
!
!
!
!
!
interface FastEthernet0/1
no switchport
ip address 192.168.1.252 255.255.255.0
no ip redirects
standby timers 3 250
standby 1 ip 192.168.1.254
standby 1 priority 50
standby 1 preempt
!
interface FastEthernet0/2
switchport mode dynamic desirable
!
interface FastEthernet0/3
switchport mode dynamic desirable
!
interface FastEthernet0/4
switchport mode dynamic desirable
!
interface FastEthernet0/5
switchport mode dynamic desirable
!
interface FastEthernet0/6
switchport mode dynamic desirable
!
interface FastEthernet0/7
switchport mode dynamic desirable
!
interface FastEthernet0/8
switchport mode dynamic desirable
!
interface FastEthernet0/9
switchport mode dynamic desirable
!
interface FastEthernet0/10
switchport mode dynamic desirable
!
interface FastEthernet0/11
switchport mode dynamic desirable
!
interface FastEthernet0/12
switchport mode dynamic desirable
!
interface FastEthernet0/13
switchport mode dynamic desirable
!
interface FastEthernet0/14
switchport mode dynamic desirable
!
interface FastEthernet0/15
switchport mode dynamic desirable
!
interface FastEthernet0/16
switchport mode dynamic desirable
!
interface FastEthernet0/17
switchport mode dynamic desirable
!
interface FastEthernet0/18
switchport mode dynamic desirable
!
interface FastEthernet0/19
switchport mode dynamic desirable
!
interface FastEthernet0/20
switchport mode dynamic desirable
!
interface FastEthernet0/21
switchport mode dynamic desirable
!
interface FastEthernet0/22
switchport mode dynamic desirable
!
interface FastEthernet0/23
switchport mode dynamic desirable
!
interface FastEthernet0/24
switchport mode dynamic desirable
!
interface FastEthernet0/25
switchport mode dynamic desirable
!
interface FastEthernet0/26
switchport mode dynamic desirable
!
interface FastEthernet0/27
switchport mode dynamic desirable
!
interface FastEthernet0/28
switchport mode dynamic desirable
!
interface FastEthernet0/29
switchport mode dynamic desirable
!
interface FastEthernet0/30
switchport mode dynamic desirable
!
interface FastEthernet0/31
switchport mode dynamic desirable
!
interface FastEthernet0/32
switchport mode dynamic desirable
!
interface FastEthernet0/33
switchport mode dynamic desirable
!
interface FastEthernet0/34
switchport mode dynamic desirable
!
interface FastEthernet0/35
switchport mode dynamic desirable
!
interface FastEthernet0/36
switchport mode dynamic desirable
!
interface FastEthernet0/37
switchport mode dynamic desirable
!
interface FastEthernet0/38
switchport mode dynamic desirable
!
interface FastEthernet0/39
switchport mode dynamic desirable
!
interface FastEthernet0/40
switchport mode dynamic desirable
!
interface FastEthernet0/41
switchport mode dynamic desirable
!
interface FastEthernet0/42
switchport mode dynamic desirable
!
interface FastEthernet0/43
switchport mode dynamic desirable
!
interface FastEthernet0/44
switchport mode dynamic desirable
!
interface FastEthernet0/45
switchport mode dynamic desirable
!
interface FastEthernet0/46
switchport mode dynamic desirable
!
interface FastEthernet0/47
switchport mode dynamic desirable
!
interface FastEthernet0/48
no switchport
ip address 10.30.1.193 255.255.255.0
!
interface GigabitEthernet0/1
switchport mode dynamic desirable
!
interface GigabitEthernet0/2
switchport mode dynamic desirable
!
interface Vlan1
no ip address
shutdown
!
ip classless
ip route 0.0.0.0 0.0.0.0 10.30.1.1
ip http server
!
!
line con 0
line vty 0 4
password cisco
login
line vty 5 15
login
!
!
end
4.调试结果
3550#show ip int brief
Interface IP-Address OK? Method Status Protocol
Vlan1 unassigned YES unset administratively down down
FastEthernet0/1 192.168.1.252 YES manual up up
FastEthernet0/2 unassigned YES unset down down
FastEthernet0/3 unassigned YES unset down down
FastEthernet0/4 unassigned YES unset down down
FastEthernet0/5 unassigned YES unset down down
FastEthernet0/6 unassigned YES unset down down
FastEthernet0/7 unassigned YES unset down down
FastEthernet0/8 unassigned YES unset down down
FastEthernet0/9 unassigned YES unset down down
FastEthernet0/10 unassigned YES unset down down
FastEthernet0/11 unassigned YES unset down down
FastEthernet0/12 unassigned YES unset down down
FastEthernet0/13 unassigned YES unset down down
FastEthernet0/14 unassigned YES unset down down
FastEthernet0/15 unassigned YES unset down down
FastEthernet0/16 unassigned YES unset down down
FastEthernet0/17 unassigned YES unset down down
FastEthernet0/18 unassigned YES unset down down
FastEthernet0/19 unassigned YES unset down down
FastEthernet0/20 unassigned YES unset down down
FastEthernet0/21 unassigned YES unset down down
FastEthernet0/22 unassigned YES unset down down
FastEthernet0/23 unassigned YES unset down down
FastEthernet0/24 unassigned YES unset down down
FastEthernet0/25 unassigned YES unset down down
FastEthernet0/26 unassigned YES unset down down
FastEthernet0/27 unassigned YES unset down down
FastEthernet0/28 unassigned YES unset down down
FastEthernet0/29 unassigned YES unset down down
FastEthernet0/30 unassigned YES unset down down
FastEthernet0/31 unassigned YES unset down down
FastEthernet0/32 unassigned YES unset down down
FastEthernet0/33 unassigned YES unset down down
FastEthernet0/34 unassigned YES unset down down
FastEthernet0/35 unassigned YES unset down down
FastEthernet0/36 unassigned YES unset down down
FastEthernet0/37 unassigned YES unset down down
FastEthernet0/38 unassigned YES unset down down
FastEthernet0/39 unassigned YES unset down down
FastEthernet0/40 unassigned YES unset down down
FastEthernet0/41 unassigned YES unset down down
FastEthernet0/42 unassigned YES unset down down
FastEthernet0/43 unassigned YES unset down down
FastEthernet0/44 unassigned YES unset down down
FastEthernet0/45 unassigned YES unset down down
FastEthernet0/46 unassigned YES unset down down
FastEthernet0/47 unassigned YES unset down down
FastEthernet0/48 10.30.1.193 YES manual up up
GigabitEthernet0/1 unassigned YES unset down down
GigabitEthernet0/2 unassigned YES unset down down
3550#show standby brief
P indicates configured to preempt.
|
Interface Grp Prio P State Active addr Standby addr Group addr
Fa0/1 1 50 P Standby 192.168.1.253 local 192.168.1.254
3550#
3550#show standby
FastEthernet0/1 - Group 1
Local state is Standby, priority 50, may preempt
Hellotime 3 sec, holdtime 10 sec
Next hello sent in 0.878
Virtual IP address is 192.168.1.254 configured
Active router is 192.168.1.253, priority 110 expires in 8.252
Standby router is local
10 state changes, last state change 00:57:34
IP redundancy name is "hsrp-Fa0/1-1" (default)
3550#
Router#show standby brief
P indicates configured to preempt.
|
Interface Grp Prio P State Active Standby Virtual IP
Fa0/0 1 110 P Active local 192.168.1.252 192.168.1.254
Router#show standby
FastEthernet0/0 - Group 1
State is Active
9 state changes, last state change 01:00:05
Virtual IP address is 192.168.1.254
Active virtual MAC address is 0000.0c07.ac01
Local virtual MAC address is 0000.0c07.ac01 (default)
Hello time 3 sec, hold time 10 sec
Next hello sent in 1.333 secs
Preemption enabled, min delay 0 sec, sync delay 0 sec
Active router is local
Standby router is 192.168.1.252, priority 50 (expires in 7.263 sec)
Priority 110 (configured 110)
Router#
Router's f0/0 shutdown
Router's status
02:06:16: HSRP: Fa0/0 API Software interface going down
02:06:16: HSRP: Fa0/0 API Software interface going down
02:06:16: HSRP: Fa0/0 Interface down
02:06:16: HSRP: Fa0/0 Grp 1 Active: b/HSRP disabled
02:06:16: HSRP: Fa0/0 Grp 1 Active router is unknown, was local
02:06:16: HSRP: Fa0/0 Grp 1 Standby router is unknown, was 192.168.1.252
02:06:16: HSRP: Fa0/0 Grp 1 Resign out 192.168.1.253 Active pri 110 vIP 192.168.1.254
02:06:16: HSRP: Fa0/0 Grp 1 Active -> Init
02:06:16: %HSRP-6-STATECHANGE: FastEthernet0/0 Grp 1 state Active -> Init
02:06:16: HSRP: Fa0/0 Grp 1 Resign out 192.168.1.253 Init pri 110 vIP 192.168.1.254
02:06:16: %SYS-5-CONFIG_I: Configured from console by vty0 (192.168.1.191)
02:06:16: HSRP: Fa0/0 API Add active HSRP addresses to ARP table
02:06:18: %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
02:06:18: HSRP: API Hardware state change
02:06:19: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
02:06:50: HSRP: Fa0/1 API active virtual address 10.30.1.178 not found
Switch status
02:11:13: SB1: Fa0/1 Hello out 192.168.1.252 Standby pri 50 ip 192.168.1.254
02:11:16: SB1: Fa0/1 Hello out 192.168.1.252 Standby pri 50 ip 192.168.1.254
02:11:17: SB1: Fa0/1 Standby: c/Active timer expired (192.168.1.253)
02:11:17: SB1: Fa0/1 Active router is local, was 192.168.1.253
02:11:17: SB1: Fa0/1 Standby router is unknown, was local
02:11:17: SB1: Fa0/1 Standby -> Active
02:11:17: %STANDBY-6-STATECHANGE: FastEthernet0/1 Group 1 state Standby -> Active
02:11:17: SB1: Fa0/1 Redundancy "hsrp-Fa0/1-1" state Standby -> Active
02:11:17: SB1: Fa0/1 Hello out 192.168.1.252 Active pri 50 ip 192.168.1.254
02:11:20: SB1: Fa0/1 Hello out 192.168.1.252 Active pri 50 ip 192.168.1.254
02:11:20: SB1: Fa0/1 Redundancy group hsrp-Fa0/1-1 state Active -> Active
02:11:23: SB1: Fa0/1 Hello out 192.168.1.252 Active pri 50 ip 192.168.1.254
02:11:23: SB1: Fa0/1 Redundancy group hsrp-Fa0/1-1 state Active -> Active
02:11:25: SB1: Fa0/1 Hello out 192.168.1.252 Active pri 50 ip 192.168.1.254
02:11:28: SB1: Fa0/1 Hello out 192.168.1.252 Active pri 50 ip 192.168.1.254
Router's f0/0 up
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#no shut
Router(config-if)#
02:07:56: HSRP: Fa0/0 API MAC address update
02:07:56: HSRP: Fa0/0 API Software interface coming up
02:07:58: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
02:07:58: HSRP: API Hardware state change
02:07:59: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Active pri 50 vIP 192.168.1.254
02:07:59: HSRP: Fa0/0 Grp 1 Active router is 192.168.1.252
02:08:00: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
02:08:00: HSRP: Fa0/0 API Software interface coming up
02:08:01: HSRP: Fa0/0 API active virtual address 192.168.1.253 not found
02:08:01: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Active pri 50 vIP 192.168.1.254
02:08:04: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Active pri 50 vIP 192.168.1.254
02:08:06: HSRP: Fa0/0 Interface up
02:08:06: HSRP: Fa0/0 Grp 1 Init: a/HSRP enabled
02:08:06: HSRP: Fa0/0 Grp 1 Init -> Listen
02:08:06: HSRP: Fa0/0 Redirect adv out, Passive, active 0 passive 1
02:08:07: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Active pri 50 vIP 192.168.1.254
02:08:07: HSRP: Fa0/0 Grp 1 Listen: h/Hello rcvd from lower pri Active router (50/192.168.1.252)
02:08:07: HSRP: Fa0/0 Grp 1 Active router is local, was 192.168.1.252
02:08:07: HSRP: Fa0/0 Redirect adv out, Active, active 0 passive 2
02:08:07: HSRP: Fa0/0 Grp 1 Coup out 192.168.1.253 Listen pri 110 vIP 192.168.1.254
02:08:07: HSRP: Fa0/0 Grp 1 Listen -> Active
02:08:07: %HSRP-6-STATECHANGE: FastEthernet0/0 Grp 1 state Listen -> Active
02:08:07: HSRP: Fa0/0 Redirect adv out, Active, active 1 passive 1
02:08:07: HSRP: Fa0/0 Grp 1 Hello out 192.168.1.253 Active pri 110 vIP 192.168.1.254
02:08:07: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Speak pri 50 vIP 192.168.1.254
02:08:10: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Speak pri 50 vIP 192.168.1.254
02:08:10: HSRP: Fa0/0 Grp 1 Hello out 192.168.1.253 Active pri 110 vIP 192.168.1.254
02:08:13: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Speak pri 50 vIP 192.168.1.254
02:08:13: HSRP: Fa0/0 Grp 1 Hello out 192.168.1.253 Active pri 110 vIP 192.168.1.254
02:08:16: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Speak pri 50 vIP 192.168.1.254
02:08:16: HSRP: Fa0/0 Grp 1 Hello out 192.168.1.253 Active pri 110 vIP 192.168.1.254
02:08:17: HSRP: Fa0/0 Grp 1 Hello in 192.168.1.252 Standby pri 50 vIP 192.168.1.254