HSRP(热备份路由协议)

一、概述

HSRP:热备份路由器协议(HSRP:Hot Standby Router Protocol),是cisco平台一种特有的技术,是cisco的私有协议。
该协议中含有多台路由器,对应一个HSRP组。该组中只有一个路由器承担转发用户流量的职责,这就是活动路由器。当活动路由器失效后,备份路由器将承担该职责,成为新的活动路由器。这就是热备份的原理。百度百科

二、原理

在这里插入图片描述
备份的是网关。

三、实验

1)网段规划

在这里插入图片描述

2)配置IP开通端口

两台PC IP配置
在这里插入图片描述
在这里插入图片描述
两个网关配置IP+开启端口
R1-GW

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ho R1-GW
R1-GW(config)#
R1-GW(config)#
R1-GW(config)#int f0/0
R1-GW(config-if)#ip add 192.168.1.252 255.255.255.0
R1-GW(config-if)#no shut

R1-GW(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R1-GW(config-if)#exit
R1-GW(config)#int f0/1
R1-GW(config-if)#ip add 10.1.1.1 255.255.255.0
R1-GW(config-if)#no shut
R1-GW(config-if)#exit
R1-GW(config)#do show ip int b
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/0        192.168.1.252   YES manual up                    up 
FastEthernet0/1        10.1.1.1        YES manual up                    up 
Vlan1                  unassigned      YES unset  administratively down down

R2-GW

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ho R2-GW
R2-GW(config)#int f0/0
R2-GW(config-if)#ip add 192.168.1.253 255.255.255.0
R2-GW(config-if)#no shut

R2-GW(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R2-GW(config-if)#
R2-GW(config-if)#exit
R2-GW(config)#int f0/1
R2-GW(config-if)#ip add 20.1.1.1 255.255.255.0
R2-GW(config-if)#no shut

R2-GW(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up

R2-GW(config-if)#exit
R2-GW(config)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

R2-GW(config)#
R2-GW(config)#do show ip int b
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/0        192.168.1.253   YES manual up                    up 
FastEthernet0/1        20.1.1.1        YES manual up                    up 
Vlan1                  unassigned      YES unset  administratively down down

R-waiwang

Router>
Router>en 
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ho R-waiwang
R-waiwang(config)#int f0/0
R-waiwang(config-if)#ip add 10.1.1.2 255.255.255.0
R-waiwang(config-if)#no shut

R-waiwang(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R-waiwang(config-if)#exit
R-waiwang(config)#int f0/1
R-waiwang(config-if)#ip add 20.1.1.2 255.255.255.0
R-waiwang(config-if)#no shut

R-waiwang(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

R-waiwang(config-if)#exit
R-waiwang(config)#int f0/3
%Invalid interface type and number
R-waiwang(config)#int f1/0
R-waiwang(config-if)#ip add 30.1.1.254 255.255.255.0
R-waiwang(config-if)#no shut

R-waiwang(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up

R-waiwang(config-if)#exit
R-waiwang(config)#do show ip int b
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/0        10.1.1.2        YES manual up                    up 
FastEthernet0/1        20.1.1.2        YES manual up                    up 
FastEthernet1/0        30.1.1.254      YES manual up                    up 
FastEthernet1/1        unassigned      YES unset  administratively down down 
Vlan1                  unassigned      YES unset  administratively down down

外网PC
在这里插入图片描述
在这里插入图片描述

3)配置路由表

R1-GW
R1-GW(config)#ip route 0.0.0.0 0.0.0.0 10.1.1.2
R2-GW
R1-GW(config)#ip route 0.0.0.0 0.0.0.0 20.1.1.2

R-waiwang
在这里插入图片描述
为了体现实验,我们如果将R1接口down掉,PC可以使用备份路由上网,所以我们要将外网路由的下一跳IP指向R2的F0/1的IP

R-waiwang(config)#ip route 0.0.0.0 0.0.0.0 20.1.1.1

R-waiwang(config)#do show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is 20.1.1.1 to network 0.0.0.0

     10.0.0.0/24 is subnetted, 1 subnets
C       10.1.1.0 is directly connected, FastEthernet0/0
     20.0.0.0/24 is subnetted, 1 subnets
C       20.1.1.0 is directly connected, FastEthernet0/1
     30.0.0.0/24 is subnetted, 1 subnets
C       30.1.1.0 is directly connected, FastEthernet1/0
S*   0.0.0.0/0 [1/0] via 20.1.1.1

4)热备份

R1-活跃路由器

R1-GW(config)#int f0/0
R1-GW(config-if)#standby 1 ip 192.168.1.254  创建热备份组号为1,虚拟网关IP为192.168.1.254
%HSRP-6-STATECHANGE: FastEthernet0/0 Grp 1 state Speak -> Standby

%HSRP-6-STATECHANGE: FastEthernet0/0 Grp 1 state Standby -> Active
R1-GW(config-if)#standby 1 priority 200      设置优先级为200
R1-GW(config-if)#standby 1 preempt           设置占先权
R1-GW(config-if)#standby 1 track f0/1        跟踪f0/1接口    

查看热备份配置信息

R1-GW#show standby brief 
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Fa0/0       1    200   Active   local           192.168.1.253   192.168.1.254  

R2-备份路由器

R2-GW(config)#int f0/0
R2-GW(config-if)#standby 1 ip 192.168.1.254
R2-GW(config-if)#standby 1 priority 
%HSRP-6-STATECHANGE: FastEthernet0/0 Grp 1 state Speak -> Standby

R2-GW(config-if)#standby 1 priority 195
R2-GW(config-if)#standby 1 preempt

查看热备份配置信息

R2-GW#show standby brief 
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Fa0/0       1    195 P Standby  192.168.1.252   local           192.168.1.254  
R2-GW#

5)测试

我们进入活跃路由器将网关接口f0/0,down掉,备份路由器每隔一段时间会与活跃路由器进行通信(检测端口是否正常),当检测到活跃路由器异常时会自动升级为活跃路由器,如果活跃路由器的故障修复重新启动,那么会重新接管活跃路由器的身份,备份路由器会自动降级。

也就是说活跃路由器故障那么会由备份路由器接管,故障修复后备份路由器会回到原来的位置。
备份路由器的身份转变取决于活跃路由器是否出现异常。

C:\>ping -t 30.1.1.1

Pinging 30.1.1.1 with 32 bytes of data:

Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 30.1.1.1: bytes=32 time=15ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time=12ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Request timed out.
Request timed out.
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time=1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time=1ms TTL=126
Reply from 30.1.1.1: bytes=32 time<1ms TTL=126
Reply from 30.1.1.1: bytes=32 time=1ms TTL=126
Reply from 30.1.1.1: bytes=32 time=1ms TTL=126

将f0/1接口down掉
在这里插入图片描述
查看活跃路由器的热备份信息

R1-GW#sh standby brief 
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Fa0/0       1    190   Standby  192.168.1.253   local           192.168.1.254  
R1-GW#sh standby
FastEthernet0/0 - Group 1
  State is Standby
    16 state changes, last state change 03:33:02
  Virtual IP address is 192.168.1.254
  Active virtual MAC address is 0000.0C07.AC01
    Local virtual MAC address is 0000.0C07.AC01 (v1 default)
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 0.035 secs
  Preemption disabled
  Active router is 192.168.1.253, priority 195 (expires in 9 sec)
    MAC address is 0000.0C07.AC01
  Standby router is local
  Priority 190 (configured 200)
    Track interface FastEthernet0/1 state Down decrement 10
  Group name is hsrp-Fa0/0-1 (default)
R1-GW#

查看备份路由器的热备份信息

R2-GW#sh standby brief 
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Fa0/0       1    195 P Active   local           192.168.1.252   192.168.1.254  
R2-GW#
  • 1
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多学点技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值