11-网关冗余HSRP协议
HSRP
• HSRP 路由器发送的多播消息有以下三种:
– HELLO: HELLO 消息通知其它路由器发送路由器 的 HSRP 优先级和状态信息,HSRP 路由器默认为 每 3 秒钟发送一个 HELLO 消息; – Coup:当一个备用路由器变为一个活动路由器时 发送一个 coup 消息; – Resign:当活动路由器要宕机或者当有优先级更高 的路由器发送 HELLO 消息时,主动发送一个 resign 消息。
HSRP
HSRP
• HSRP 路由器利用 HELLO 包来互相监听各 自的存在。当备份路由器长时间没有接收到 HELLO包,就认为活动路由器故障,备份路 由器就会成为活动路由器。 • HSRP 协议利用优先级决定组内哪个路由器 成为活动路由器。
– 如果一个路由器的优先级比其它路由器的优先级高, 则该路由器成为活动路由器。 – 路由器的缺省优先级是 100。 – 一个组中,最多有一个活动路由器。
HSRP配置命令
1. 指定热备份组的组号和虚拟ip 地址
standby 组号 ip ip地址
– – 组号:取值为0-255,如果是一个备用组,可以不输入组号,默认为0 ip地址:是虚拟的ip地址,不能为接口上的地址
2. 指定备份组的优先级别
standby 组号 priority 优先级别
– 优先级:取值为1-255,默认为100,数值越大级别越高
• R1(config-if)#standby 1 track s0/0/0 30
//跟踪的是 s0/0/0 接口,如果该接口故障,优先级降低 30,,默认降低 10,模拟软件PT只支持10。
HSRP配置举例
RA:
(config)#int f0/0 (config-if)#ip add 172.16.10.1 255.255.255.0 (config-if)#standby 1 ip 172.16.10.254 (config-if)#standby 1 preempt (config-if)#standb# config terminal RA(config)# interface f0/0 RA(config-if)# ip address 172.16.10.1 255.255.255.0 RA(config-if)# standby 1 ip 172.16.10.254 RA(config-if)# standby 1 priority 120 RA(config-if)# standby 1 preempt RA(config-if)# standby 2 ip 172.16.10.253 RA(config-if)# standby 2 preempt RA(config-if)# end
HSRP配置举例
RB# configure terminal RB(config)# interface f0/0 RB(config-if)# ip address 172.16.10.2 255.255.255.0 RB(config-if)# standby 1 ip 172.16.10.254 RB(config-if)# standby 1 preempt RB(config-if)# standby 2 ip 172.16.10.253 RB(config-if)# standby 2 priority 120 RB(config-if)# standby 2 preempt RB(config-if)# end
实验步骤
1. 连接拓扑图,搭建环境 2. 配置 IP 地址、路由协议等,使得网络连通
– – – – – – – – R3(config)#interface GigabitEthernet0/0 R3(config-if)#ip address 192.168.13.3 255.255.255.0 R3(config)#interface Serial0/0/1 R3(config-if)#ip address 192.168.23.3 255.255.255.0 R3(config)#router rip R3(config-router)#network 192.168.23.0 R3(config-router)#network 192.168.13.0 R3(config-router)#passive-interface GigabitEthernet0/0
• PC0的网关可以选择任一台路由器设置
• 此时用PC0去pingPC1,可以通~~~网络全部 互通
实验步骤
1. 连接拓扑图,搭建环境 2. 配置 IP 地址、路由协议等,使得网络连通 3. 配置 HSRP
– R1(config)#interface g0/0 – R1(config-if)#standby 1 ip 192.168.13.254
网关冗余与负载均衡
概述
• 作为网关的路由器故障了,有什么办法? • HSRP 和 VRRP 是最常用的网关冗余技术
– HSRP 是 Cisco 的专有协议。 – VRRP 的工作原理和 HSRP 非常类似,不过 VRRP 是国际上的标准,允许在不同厂商的设备之间运行。
• 我们希望在冗余的同时,能同时实现负载平衡, 以充分利用设备的能力,GLBP 同时提供了冗 余和负载平衡的能力
• R1(config-if)#standby 1 priority 120
//配置 HSRP 的优先级,如果不设置该项,缺省优先级为 100,该值越 大抢占为活动路由器的优先权越高。
• R1(config-if)#standby 1 preempt
//该设置允许该路由器在优先级是最高时成为活动路由器。如果不设置, 即使该路由器权值再高,也可能不会成为活动路由器。
HSRP配置命令
• R1(config)#interface g0/0 • R1(config-if)#standby 1 ip 192.168.13.254
//启用 HSRP 功能,1 为 standby 的组号,192.168.13.254为虚拟 IP 地 址。相同组号的路由器属于同一个 HSRP 组,所有属于同一个 HSRP 组的路由器的虚拟地址必须一致
3. 指定抢占模式
当活动路由器失效后,备份路由器马上替换为活动路由器,不需要时间等待
standby 组号 preempt [delay 秒数]
– delay:取值为0-3600(1小时)
4. 设置端口跟踪(可选)
standby 组号 track 端口号 降低的优先级数值
– 若该端口故障 降低的优先级别:默认为10,可设置其他值,须合理设置,使得网络中 的活动路由器合理切换。端口恢复之后该优先级会自动增加该值。
多组HSRP
• 为了方便负载均衡,同一台路由器可以是同 一个网段或vlan中多个hsrp备用组的成员。 • 配置多个备用组可进一步提高冗余性,在网 络中均衡负载,提高冗余路由器的使用率。 • 路由器在为一个hsrp组转发通信流的同时,可 以在另一个hsrp组中处于备用或监听状态。 • 每个备用组都模拟一个虚拟路由器。在vlan或 接口上,最多可以有255个备用组
实验步骤
1. 连接拓扑图,搭建环境 2. 配置 IP 地址、路由协议等,使得网络连通
– – – – – – – – – – – – – R2(config)#int g0/0 R2(config-if)#ip address 192.168.20.2 255.255.255.0 R2(config)#int s0/0/0 R2(config-if)#clock rate 128000 R2(config-if)#ip address 192.168.12.2 255.255.255.0 R2(config)#int s0/0/1 R2(config-if)#clock rate 128000 R2(config-if)#ip address 192.168.23.2 255.255.255.0 R2(config)#router rip R2(config-router)#network 192.168.12.0 R2(config-router)#network 192.168.23.0 R2(config-router)#network 192.168.20.0 R2(config-router)#passive-interface GigabitEthernet0/0
//启用 HSRP 功能,并设置虚拟 IP 地址
– R1(config-if)#standby 1 priority 110
//配置 HSRP 优先级
– R1(config-if)#standby 1 preempt
//该设置允许该路由器在优先级是最高时成为活动路由器
实验步骤
1. 连接拓扑图,搭建环境 2. 配置 IP 地址、路由协议等,使得网络连通 3. 配置 HSRP
实验目的
1、理解 HSRP 的工作原理 2、掌握 HSRP 的配置
实验拓扑
实验步骤
1. 连接拓扑图,搭建环境 2. 配置 IP 地址、路由协议等,使得网络连通
– – – – – – – – R1(config)#interface Gi0/0 R1(config-if)#ip address 192.168.13.1 255.255.255.0 R1(config)#interface S0/0/0 R1(config-if)#ip add 192.168.12.1 255.255.255.0 R1(config)#router rip R1(config-router)#network 192.168.12.0 R1(config-router)#network 192.168.13.0 R1(config-router)#passive-interface GigabitEthernet0/0 //之所以把 g0/0 接口设为被动接口,是防止从该接口 发送 RIP 信息给 R3,防止RIP回环。