1、第二部分 HRRP 热备份路由协议多台路由器组成一个“热备份组” ,用来模拟为一个虚拟的路由器(拥有虚拟的 IP 地址和虚拟的 MAC 地址),在一个备份组中,只有一台路由器作为活动路由器发送数据包,只有当活动路由器失效后,将选择一台备份路由器才能成为活动路由器转发数据包,但对于网络中的主机来说,虚拟路由器并没有发生任何改变。HSRP 有三种广播包:1) Hello 包,hello 消息通知其他路由器发送路由器的 HSRP 优先级和状态信息,HSRP 路由器,默认为每 3 秒钟发送一个 hello 消息;可以修改这个参数。2) Coup 包,当一个备用路由器变为一个主动路由器时发送一个 cou
2、p 消息。3) Resign 包,当主动路由器要宕机或者当有优先级更高的路由器发送 hello 消息时,主动路由器发送一个 resign 消息。HSRP 状态类型:1) Initial 初始化, HSRP 启动时的状态,HSRP 还没有运行,一般是在改变配置或端口刚启动时进入该状态。2) Learn 学习状态,路由器已经得到了虚拟 IP 地址,但是它既不是活动路由器也不是备份路由器。它一直监听从活动路由器和备份路由器发来的 HELLO 报文。3) Listen 监听状态,路由器正在监听 hello 消息。4) Speak 对话状态,在该状态下,路由器定期发送 HELLO 报文,并且积极参加活动
3、路由器或等待路由器的竞选。5) Standby 被动状态,当主动路由器失效时路由器准备接包传输功能。6) Active 活动状态,路由器执行包传输功能。HSRP 路由器体系1)活动路由器,负责转发发送到虚拟路由器的数据。它通过发送 HELLO 消息(基于 UDP,端口号为1985 的广播)来通告它的活跃状态2)备份路由器,监视 HSRP 组中的运行状态,并且在当前活跃路由器不可用时,迅速承担起负责数据转发的任务。备份路由器也发送 HELLO 消息来通告组中其他的路由器它备份路由器的角色。3) 虚拟路由器,向最终的用户来代表一台能持续工作的路由器设备。它有自己的 MAC 和 IP 地址。但是实际
4、上它是不用来转发数据包,它的作用仅仅是代表一台可用的路由设备。虚拟 MAC 地址组成:Vendor ID:厂商 ID,构成 MAC 地址的头 3 个字节HSRP 代码:表示该地址是 HSRP 虚拟路由器的。XX07.acxx组 ID:最后一个字节是组 ID,由组号组成如我们可以通过命令:show ip arp 命令查看00000007ac014)其他路由器,也监听 HELLO 消息,但是不作应答,这样它就不会在备份组有身份的概念,同时它也不参与发送到虚拟路由器的数据包,但是还是转发其他路由器发来的数据包。选举过程1) 默认情况下,优先级为 100,这时 MAC 地址最小的成为活动路由器2) 当
5、活动路由器失效后,备份路由器替代成为活动路由器,当活动和备份路由器都失效后,其他路由器将参与活动和备份路由器的选举工作a) 优先级高的成为活动路由器,默认为 100,取值为 0255b) 优先级别相同时,接口 IP 地址高的将成为活动路由器HSRP 的抢占 Preempt 技术HRSP 技术能够保证优先级高的路由器失效恢复后总能处于活动状态。活动路由器失效后,优先级最高的备用路由器处于活动状态,如果没有使用 preempt 技术,则当活动路由器恢复后,只能处于备用状态,先前的备用服务器代替其角色处于活动状态,直到下一次选举发生。HSRP 的端口跟踪 track 技术如果所监测的端口出现故障,则
6、也可以进行路由器的切换。如果主路由器上有多条线路被跟踪,则当一条线路出现故障时,就会切换到备份路由器上,即使其他都线路正常工作,直到主路由器该线路正常工作,才能重新切换回来。接口跟踪使得能够根据 HSRP 组路由器的接口是否可用,来自动调整该路由器的优先级。当被跟踪的接口不可用时,路由器的 HSRP 优先级将降低。HSRP 跟踪特性确保当 HSRP 活跃路由器的重要入站接口不可用时,该路由器不再是活跃路由器。多组 HSRP为了方便负载均衡,同一台路由器可以是同一个网段或 VLAN 中多个 HSRP 备用组的成员。配置多个备用组可进一步提高冗余性,在网络中均衡负载,提高冗余路由器的使用率。路由器
7、在为一个 HSRP 组转发通信流的同时,可以在另一个 HSRP 组中处于备用或监听状态。每个备用组都模拟一个虚拟路由器。在 VLAN 或接口上,最多可以有 255 个备用组如下图,路由器 A 和路由器 B 都是 HSRP 组 1 和 2 的成员,然而,路由器 A 是 HSRP 组 1 的活跃路由器和 HSRP 组 2 的备用路由器;而路由器 B 是 HSRP 组 2 的活跃路由器和 HSRP 组 1 的备用路由器。配置过程:默认配置特性 默认配置-HSRP 组 未定义备用组编号 0备用组 MAC 地址 0000.0c07.acXX, XX 是 HSRP 组号优先级 100延时 0(没有延时)跟
8、踪端口的优先级 10HELLO 时间 3 秒HOLD 时间 10 秒配置要求:1 HSRP 最多可以配置 32 个 VLAN 或路由接口2 配置接口必须是 3 层接口路由接口:接口使用 no switchport,并且配置 ip 地址SVI(交换虚拟接口):使用命令 interface vlan vlan 号3 层以太网通道(EtherChannel)3 所有 3 层接口都必须配置 IP 地址配置 HSRP1) 进入全局模式 configure terminal2) 进入接口模式 interface 接口3) 使能 HSRP,指定热备份组的组号和虚拟 IP 地址standby 组号 ip IP
9、 地址组号:取值为 0-255,如果是一个备用组,可以不输入组号,默认为 0ip 地址:是虚拟的 Ip 地址,不能为接口上的地址4) 指定备用组的优先级别standby 组号 priority 优先级别 优先级:取值为 1-255,默认为 100,数值越大级别越高5) 指定抢占模式,当活动路由器失效后,备份路由器马上替换为活动路由器,不需要时间等待(hold time)standby 组号 preempt delay 秒数d elay:取值为 0-3600(1 小时)6) 设置端口跟踪(可选)standby 组号 track 端口号 降低的优先级别降低的优先级别:默认为 107) 人工指定虚拟
10、 mac 地址(可选)standby 组号 mac mac 地址8) 使用实际接口的 mac 地址(可选, 只有 25 系列路由器使用)standby 组号 use-bia9) 配置认证(可选)standby 组号 authentication mode text 密码密码: 密码是明文,默认为 cisco注意:对于 IOS12.3 以上的版本中,HSRP 支持 MD5 的认证,具体配置命令为standby 组号 authentication md5 key-string 密码10)配置 HSRP 时间(可选)standby 组号 timers hello 秒数 hold 秒数hello 秒数
11、:取值为 1-255,默认为 3 秒hold 秒数:取值为 1-255,默认为 10 秒,hold time= 3*hello time检验和调试:检验:show standby 接口 组active|init|listen|standbybrief如:show standby Ethernet0 init brief调试:debug standby:显示所有的 HSRP 错误、事件和数据包debug standby terse :显示除 hello 和通告以外的所有 HSRP 错误、事件和数据包debug standby events detail:显示 HSRP 事件debug stand
12、by error:显示 HSRP 错误debug standby packets advertise|coup|hello|resigndetail案例:sw1(config)#int vlan 10sw1(config-if)#ip address 192.168.1.1 255.255.255.0sw1(config-if)#standby 1 ip 192.168.1.254sw1(config-if)#standby 1 priority 110-sw2(config)#int vlan 10sw2(config-if)#ip address 192.168.1.2 255.255.2
13、55.0sw2(config-if)#standby 1 ip 192.168.1.254sw2(config-if)#standby 1 priority 100-SW1#show standby Vlan10 - Group 1State is Active2 state changes, last state change 00:02:38Virtual IP address is 192.168.1.254Active virtual MAC address is 0000.0c07.ac01Local virtual MAC address is 0000.0c07.ac01 (v1
14、 default)Hello time 3 sec, hold time 10 secNext hello sent in 0.124 secsPreemption enabledActive router is localStandby router is 192.168.1.2, priority 100 (expires in 7.992 sec)Priority 110 (configured 110)IP redundancy name is “hsrp-Vl10-1“ (default)-SW2#show standyVlan10 - Group 1State is Standby
15、1 state change, last state change 00:02:32Virtual IP address is 192.168.1.254Active virtual MAC address is 0000.0c07.ac01Local virtual MAC address is 0000.0c07.ac01 (v1 default)Hello time 3 sec, hold time 10 secNext hello sent in 0.328 secsPreemption enabledActive router is 192.168.1.1, priority 110
16、 (expires in 9.456 sec)Standby router is localPriority 100 (default 100)IP redundancy name is “hsrp-Vl10-1“ (default)SW1#show stan brieP indicates configured to preempt.|Interface Grp Prio P State Active Standby Virtual IP V10 1 110 P Active local 192.168.1.2 192.168.1.254 多组 HSRP 备用组Router A Config
17、urationSwitch# configure terminalSwitch(config)# interface gigabitethernet0/1Switch(config-if)# no switchportSwitch(config-if)# ip address 10.0.0.1 255.255.255.0Switch(config-if)# standby 1 ip 10.0.0.3Switch(config-if)# standby 1 priority 110 Switch(config-if)# standby 1 preempt Switch(config-if)# s
18、tandby 2 ip 10.0.0.4Switch(config-if)# standby 2 preempt Switch(config-if)# endRouter B ConfigurationSwitch# configure terminalSwitch(config)# interface gigabitethernet0/1Switch(config-if)# no switchportSwitch(config-if)# ip address 10.0.0.2 255.255.255.0Switch(config-if)# standby 1 ip 10.0.0.3Switc
19、h(config-if)# standby 1 preempt Switch(config-if)# standby 2 ip 10.0.0.4Switch(config-if)# standby 2 priority 110 Switch(config-if)# standby 2 preempt Switch(config-if)# end案例:CCIE-LAB(V160)题目要求:Configure HSRP on R3 and R4 for hosts on VLAN A:Carefully read the requirements:There are 10 hosts on VLA
20、N A。5 Windows PCs and 5 Unix workstationsThe Windows PCs are configured to use 160.YY.10.50 as their default gatewayThe UNIX workstations are configured to use 160.YY.10.100 as their default gatewayR3 is the preferred router for Windows users.R4 is the prefered router for Unix users.If the frame rel
21、ay connection on R3 goes down,then R4 becomes the preferred router for all users。If the frame relay connection on R4 goes down,then R3 becomes the preferred router for all users。Once either R3 or R4 recover from a failure then the network must operate as outinedabove, I.e Each router must resume the
22、ir original role。配置:R3config termiinterface f0/0standby 1 ip 160.11.10.50standby 1 priority 110standby 1 track s0/0 20standby 1 preemptstandby 2 ip 160.11.10.100standby 2 preemptR4 config termiinterface f0/0standby 1 ip 160.11.10.50standby 1 preemptstandby 2 ip 160.11.10.100standby 2 priority 110sta
23、ndby 2 track s0/0 20standby 2 preemptTrunk 链路上的 HSRP此项功能能通过在子网和 VLAN 间提供负载均衡和冗余能力提高整个网络的韧性。我们可以实现通过两个路由器来实现在干道上的互为活跃/备份路由器。我们只要设置一下他们在 HSRP 中的优先级就可以实现。配置步骤:1 定义封装类型和 vlan如:interface f0/0.10encapaulation isl 10interface f0/0.20encapaulation isl 202.分配 IP 地址如:interface f0/0.10ip address 10.10.10.2 255
24、.255.255.0interface f0/0.20ip address 10.10.20.2 255.255.255.03.启动 HSRP如:inteface f0/0.10standby 1 ip 10.10.10.254standby 1 priority 105standby 1 preemptinterface f0/0.20standby 2 ip 10.10.20.254standby 2 priority 90新:HSRP2在 CISCO IOS 12.3 以上的版本中,HSRP 支持 V2 的版本。HSRP V2 和 HSRP V1 命令上没有什么不同,只是 HSRP V2
25、 所支持的组号进行了扩展,HSRP V1 只支持 0-255 个组,而 HSRP V2 可以支持0-4095 个组,主要是应用在它可以支持匹配在子接口上的 VLAN 号(扩展的 VLAN 可以支持到 4094个)HSRP V1 和 HSRP V2 不能同时在一个接口上启用,但是在同一台路由器上的不同接口上,可以应用不同版本的 HSRP配置过程:1) 进入全局模式 configure terminal2) 进入接口模式 interface 接口3) 启用 HSRP 版本 2standby version 24) 配置 HSRPstandby 组号 ip ip 地址组号:取值范围 0-4095案例
26、:RouterA#configure terminal RouterA(config)#interface f0/0 RouterA(config-if)#standby version 2 RouterA(config-if)#standby 4095 ip 10.1.1.1 RouterA(config-if)#standby 4095 timers msec 15 msec 50RouterA(config-if)#standby 4095 priority 200 RouterA(config-if)#standby 4095 preempt -RouterB#configure te
27、rminal RouterB(config)#interface f0/0 RouterB(config-if)#standby version 2 RouterB(config-if)#standby 4095 ip 10.1.1.1 RouterB(config-if)#standby 4095 timers msec 15 msec 50RouterB(config-if)#standby 4095 preempt -RouterA#show standbyFastEthernet0/0 - Group 4095 (version 2)State is Active2 state cha
28、nges, last state change 00:11:47Virtual IP address is 10.1.1.1Active virtual MAC address is 0000.0c9f.ffffLocal virtual MAC address is 0000.0c9f.ffff (v2 default)Hello time 15 msec, hold time 50 msecNext hello sent in 0.007 secsPreemption enabledActive router is localStandby router is 10.1.1.3, priority 100 (expires in 0.030 sec)Priority 200 (configured 200)IP redundancy name is “hsrp-Fa0/0-4095“ (default