实验名称:思科配置HSRP协议

实验目的:通过配置HSRP,为pc机提供不间断的网关服务

实验拓扑:
思科——HSRP的应用_第1张图片

实验需求:台路由器,一台pc机,一台交换机

实验思路:

  1. 配置pc机
  2. 配置路由器
    实验步骤:
    配置PC机:为PC配置IP、子网掩码及网关
    思科——HSRP的应用_第2张图片
    Gateway-1:
    Router>en
    Router#configure terminal
    Enter configuration commands, one per line. End with CNTL/Z.
    Router(config)#hostname gateway-1 \命名gateway-1
    gateway-1(config)#interface gigabitEthernet 0/0
    gateway-1(config-if)#no shutdown
    gateway-1(config-if)#
    %LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up
    %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up
    gateway-1(config-if)#ip address 192.168.10.254 255.255.255.0\配置ip地址
    gateway-1(config-if)#exit
    gateway-1(config-if)#standby 1 ip 192.168.10.250 \开启HSRP,并配置虚拟网关IP
    %HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Standby -> Active
    \表示该路由器已成为活动路由,相当于VRRP中的master路由器

gateway-1(config-if)#
Gateway-2:
Router>en
Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname gateway-2 \命名gateway-2
gateway-2(config)#interface gigabitEthernet 0/0
gateway-2(config-if)#no shutdown

%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up
gateway-2(config-if)#ip address 192.168.10.253 255.255.255.0\配置ip地址

gateway-2(config-if)#exit
%SYS-5-CONFIG_I: Configured from console by console
gateway-2(config-if)#standby 1 ip 192.168.10.250\开启HSRP,并配置虚拟网关IP

%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Speak -> Standby
\表示该路由器已成为备份路由,相当于VRRP中的backup路由器

测试与验证:
测试:
未修改前,gateway-1为主路由,gateway-2为备份路由
修改gateway-2的优先级,两台路由器都打开抢占功能,观察主设备与备份设备角色的变化
Gateway-1:
gateway-1(config)#interface gigabitEthernet 0/0
gateway-1(config-if)#standby 1 preempt\开启抢占功能

gateway-2:
gateway-2(config)#interface gigabitEthernet 0/0
gateway-2(config-if)#standby 1 priority 110\默认优先级是100,修改优先级大于100
gateway-2(config-if)#standby 1 preempt\开启抢占功能
验证:
Gateway-1:
gateway-1#show standby
GigabitEthernet0/0 - Group 1 (version 2)
State is Standby 此时gateway-1由原来的主路由变成了备份路由
3 state changes, last state change 00:05:02
Virtual IP address is 192.168.10.250\虚拟网关为192.168.10.250

Active virtual MAC address is 0000.0C9F.F001
Local virtual MAC address is 0000.0C9F.F001 (v2 default)
Hello time 3 sec, hold time 10 sec
Next hello sent in 1.538 secs
Preemption enabled\抢占功能已开启
Active router is 192.168.10.253\主路由是gateway-2
Standby router is local
Priority 100 (default 100)\优先级是100
Group name is hsrp-Gig0/0-1 (default)
Gateway-2:
gateway-2#show standby
GigabitEthernet0/0 - Group 1 (version 2)
State is Active 此时,gateway-2由原来的备份路由变成了主路由
4 state changes, last state change 00:04:25
Virtual IP address is 192.168.10.250\虚拟网关为192.168.10.250
Active virtual MAC address is 0000.0C9F.F001
Local virtual MAC address is 0000.0C9F.F001 (v2 default)
Hello time 3 sec, hold time 10 sec
Next hello sent in 0.381 secs
Preemption enabled\抢占功能已开启
Active router is local
Standby router is 192.168.10.254
Priority 110 (configured 110) \优先级是110

Group name is hsrp-Gig0/0-1 (default)

实验总结:
1.HSRP中会根据已建立虚拟网关的路由器的优先级来确定路由器的角色,备份组中优先级最大且以获得虚拟IP地址的路由器会成为主路由器(活动路由器),优先级其次的路由器将成为备份路由器。
2.路由器的优先级默认值是100,可设置范围为0-255。

拓展:
HSRP:Hot Standby Router Protocol双机热备份协议
思科私有协议(与VRRP功能相同,命令稍有不同),保证对网络用户使用的默认网关的冗余性,通过HSRP,可以对网络用户的网关备份(冗余),当某个用户的网段故障时,HSRP可以自动切换路由(即备份网关),从而为用户提供不间断的网关服务。

VRRP :(公有协议)
在多个路由器之间运行,
可以虚拟出一个或者多个网关IP地址(虚拟路由器);
从而实现内网不同网段之间的互通