且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HSRP热备份路由协议配置详解

更新时间:2022-09-26 13:39:45

HSRP简介】
热待机路由协议的目的就是希望能在网络内提供趋于100%的数据转发能力,尽量保证在路由器出现故障的情况下,继续发往该路由器的数据包不会丢失,能够自动由其它路由器发送出去。
这是通过一个虚拟的路由器来实现的。子网内的主机以该虚拟路由器作为缺省网关并向其发送数据,而各个启动了HSRP的路由器通过竞争来担当该虚拟路由器的角色并负责这些数据的转发。负责转发发向虚拟路由器的数据包的那台路由器为Active状态,其它一个或多个路由器作为Standby状态。当Active路由器失效时,Standby路由器通过与Active路由器的信息交互和计时器来自动取缔原来的路由器,将自身变为Active,继续负责发往虚拟路由器的数据转发工作。然而,对用户来说,这种网络的变化是透明的,亦即可以达到一种。
【实验拓扑】
HSRP热备份路由协议配置详解
(点击图片查看完整大图) 
各个路由器之间运行RIP协议
PC的默认网关为192.168.1.1 ,也就是我们虚拟出来的网关为192.168.1.1
 
【配置步骤】
Internet
 
Router>enable
Router#conf terminal
//路由器基础配置
Router(config)#no ip domain-lookup
Router(config)#hostname Internet
Internet(config)#line con 0
Internet(config-line)#exec-timeout 0 0
Internet(config-line)#logging synchronous
Internet(config-line)#end
Internet#
Internet#conf t
// 配置路由器各个接口的IP地址
Internet(config)#int e0/0
Internet(config-if)#ip address 192.168.2.1 255.255.255.0
Internet(config-if)#no sh
Internet(config-if)#exit
Internet(config)#int e0/1
Internet(config-if)#ip address 192.168.3.1 255.255.255.0
Internet(config-if)#no sh
Internet(config-if)#exit
Internet(config)#int lo0
Internet(config-if)#ip address 100.1.1.1 255.255.255.0
Internet(config-if)#no sh
Internet(config-if)#exit
//启用RIP路由协议
Internet(config)#router rip
Internet(config-router)#version 2
Internet(config-router)#no auto-summary
Internet(config-router)#network 192.168.2.0
Internet(config-router)#network 192.168.3.0
Internet(config-router)#network 100.1.1.0
Internet(config-router)#end
Internet#write
Building configuration...
Internet#
 
 
 
R1
Router>enable
//路由器基础配置
Router(config)#no ip domain-lookup
Router(config)#hostname R1
R1(config)#line con 0
R1(config-line)#exec-timeout 0 0
R1(config-line)#logging synchronous
R1(config-line)#end
R1#conf t
//配置接口IP地址
R1(config)#int e0/0
R1(config-if)#ip address 192.168.2.2 255.255.255.0
R1(config-if)#no sh
R1(config-if)#int e0/1
R1(config-if)#ip address 192.168.1.2 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
//启用RIP路由协议
R1(config)#router rip
R1(config-router)#version 2
R1(config-router)#no auto-summary
R1(config-router)#network 192.168.2.0
R1(config-router)#network 192.168.1.0
R1(config-router)#end
R1#write
//配置HSRP
R1(config)#int e0/1 
R1(config-if)#standby 1 ip 192.168.1.1
R1(config-if)#end
//查看standby信息
R1#show standby
Ethernet0/1 - Group 1
  State is Standby   //状态为备份状态
    3 state changes, last state change 00:06:32
  Virtual IP address is 192.168.1.1  //虚拟出来的IP地址
  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.992 secs
  Preemption disabled
  Active router is 192.168.1.3, priority 100 (expires in 7.892 sec)
  Standby router is local
  Priority 100 (default 100)
  IP redundancy name is "hsrp-Et0/1-1" (default)
R1#
R2
 
Router>enable
Router#conf t
//路由器基本配置
Router(config)#no ip domain-lookup
Router(config)#hostname R2
R2(config)#line con 0
R2(config-line)#exec-timeout 0 0
R2(config-line)#logging synchronous
R2(config-line)#end
R2#conf t
//配置路由器接口IP
R2(config)#int e0/0
R2(config-if)#ip address 192.168.3.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#int e0/1
R2(config-if)#ip address 192.168.1.3 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
//启用RIP路由协议
R2(config)#router rip
R2(config-router)#version 2
R2(config-router)#no auto-summary
R2(config-router)#network 192.168.3.0
R2(config-router)#network 192.168.1.0
R2(config-router)#end
R2#write
R2#conf t
//配置HSRP
R2(config)#int e0/1
R2(config-if)#standby 1 ip 192.168.1.1
//查看Standby信息
R2#show standby
Ethernet0/1 - Group 1
  State is Active  //状态为活动状态
    2 state changes, last state change 00:06:11
  Virtual IP address is 192.168.1.1  //虚拟出来的IP地址
  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.148 secs
  Preemption disabled
  Active router is local
  Standby router is 192.168.1.2, priority 100 (expires in 7.316 sec)
  Priority 100 (default 100)
  IP redundancy name is "hsrp-Et0/1-1" (default)
R2#
 
 
 
【测试】
HSRP的目的是提高系统的可靠性,我们关掉一个端口,模拟网络出现故障,来看一下能否正常通信。关掉之前我们先来测试一下PC100.1.1.1之间能否正常通信
 
HSRP热备份路由协议配置详解 
现在我们断开R2E0/1,因为刚才的R2active,也就是我们的数据是从R2经过的。
R2(config)#int e0/1
R2(config-if)#shu
R2(config-if)#shutdown 
 
 
观察一下standby的信息
R1#show standby
Ethernet0/1 - Group 1
  State is Active //状态由standby转换为active
    4 state changes, last state change 00:00:22
  Virtual IP address is 192.168.1.1
  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 1.068 secs
  Preemption disabled
  Active router is local
  Standby router is unknown
  Priority 100 (default 100)
  IP redundancy name is "hsrp-Et0/1-1" (default)
R1#
 
再次用PCPing 100.1.1.1
C:\Users\Five>ping 100.1.1.1
 
正在 Ping 100.1.1.1 具有 32 字节的数据:
来自 100.1.1.1 的回复字节=32 时间=95ms TTL=254
来自 100.1.1.1 的回复字节=32 时间=63ms TTL=254
来自 100.1.1.1 的回复字节=32 时间=79ms TTL=254
来自 100.1.1.1 的回复字节=32 时间=125ms TTL=254
 
100.1.1.1  Ping 统计信息:
    数据包已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失)
往返行程的估计时间(以毫秒为单位):
    最短 = 63ms,最长 = 125ms,平均 = 90ms
 
C:\Users\Five>
 
发现依然可以Ping通,也就是说,系统自动为我们转换了网关,但是整个过程对用户来说确实透明的。这就是HSRP最大的好处。管理员可以及时修复出故障的端口,而不影响网络的正常运行。



本文转自 Jhuster 51CTO博客,原文链接:http://blog.51cto.com/xwnet/170056,如需转载请自行联系原作者