HSRP协议:当网络中有多个路由器作为网关时,通过HSRP协议把两个网关地址虚拟成一个虚拟网关。
如图,R1和R2都是PC1的出口网关,通过HSRP协议将网关R1和R2虚拟成一个网关192.168.1.1,在PC1上指定网关为192.168.1.1。正常情况下,PC1的数据流量只从R1上通过,当R1出故障时,R2替代上来,让流量从R2上通过,从而达到冗余备份,实现网络可靠性。
HSRP命令
standby
1、创建HSRP
R1(config-if)#standby group-numberip virtual-ip-address
2、配置HSRP优先级
R1(config-if)#standby group-numberpriority priority-value
3、HSRP占先权
R1(config-if)#standby group-numberpreempt
4、配置Hello间隔和保持时间
R1(config-if)#standby group-numbertimes hellotimeholdtime
5、HSRP端口跟踪配置
R1(config-if)#standby group-numbertrack type mod/num interface-priority
(注:这些配置都是在真实网关所在接口下配置的)
查看:
查看HSRP摘要信息
R1#show standby [type mod/num][group-number] brief
查看HSRP详细信息
R1#show standby
监听HSRP事件
R1#debug standby events
配置实例
如下图,pc1和pc2分别属于vlan10和vlan20,使vlan10的流量从M1通过,当M1出故障时PC1流量切换至M2;默认vlan20的的流量M2通过,dangM2出故障时,流量切换至M1。
1、配置R1、M1和M2之间的链路相互连通,并在R1配置换回口Loopback1,做测试用。
R1上的配置:
int f0/0
ip add 206.135.1.1 255.255.255.252
no sh
int f0/1
ip add 206.135.1.5 255.255.255.252
no sh
int loop 1
ip add 1.1.1.1 255.0.0.0
no sh
M1上的配置
intf0/0
ipadd206.135.1.2255.255.255.252
nosh
iproute1.0.0.0255.0.0.0206.135.1.1
iproute206.135.1.4255.255.255.252206.135.1.1
M2上配置
intf0/1
ipadd206.135.1.6255.255.255.252
nosh
iproute1.0.0.0255.0.0.0206.135.1.5
iproute206.135.1.0255.255.255.252206.135.1.5
2、在SW1将f1/1、f1/2划分为vlan10和vlan20,并配置中继口
SW1上配置
noiprouting
vlan10
vlan20
intf1/1
swaccvlan10
intf1/2
swaccvlan20
intf1/0
swmotrunk
intf1/15
swmotrunk
M1上配置
intf1/0
swmotrunk
M2上配置
intf1/15
swmotrunk
3、在M1和M2上配置vlan10和vlan20做为真实网关,并在PC1上配置ip测试网络连通性
M1上配置
vlan10
vlan20
intvlan10
ipadd192.168.10.10255.255.255.0
intvlan20
ipadd192.168.20.20255.255.255.0
M2上配置
vlan10
vlan20
intvlan10
ipadd192.168.10.20255.255.255.0
intvlan20
ipadd192.168.20.10255.255.255.0
4、配置HSRP
M1上配置
intvlan10
standby 1ip 192.168.10.1
standby 1priority120
standby 1 preempt
standby1track fa0/0
standby1track fa1/0
intvlan20
standby 2ip 192.168.20.1
standby2priority115
standby 2preempt
M2上配置
intvlan10
standby 1ip 192.168.10.1
standby1 priority115
standby 1 preempt
intvlan20
standby 2ip 192.168.20.1
standby2priority120
standby 2preempt
standby 1track fa0/1
standby1 track fa1/15
5、在R1配置静态路由及浮动路由
ip route 192.168.10.0255.255.255.0206.135.1.2
iproute192.168.10.0255.255.255.0206.135.1.610
iproute192.168.20.0255.255.255.0206.135.1.6
iproute192.168.20.0255.255.255.0206.135.1.210
VRRP协议
和HSRP工作原理相似
1、创建VRRP
R1(config-if)#vrrp group-numberip virtual-ip-address
2、配置HSRP优先级
R1(config-if)#vrrp group-numberpriority priority-value
3、HSRP占先权
R1(config-if)#vrrp group-numberpreempt
4、ARRP端口跟踪配置
R1(config)#track track-numberinterface interface-typeinterface-number line-protocol
R1(config-if)#vrrp track track-number
注:每跟踪一个端口,都需要在全局模式下创建一个track-number