您的位置:首页 > 教育 > 锐评 > 【思科】HSRP实验配置

【思科】HSRP实验配置

2024/10/6 5:55:38 来源:https://blog.csdn.net/2301_77161465/article/details/140382406  浏览:    关键词:【思科】HSRP实验配置

【思科】HSRP实验配置

  • 背景
  • 工作原理
  • 特点和优势
  • 实验准备
    • DSW 1
    • DSW 2
  • 配置
    • R1
    • DSW1
    • DSW2
    • ASW1
    • ASW2
    • PC1
    • PC2
    • ISP
    • 测试

在这里插入图片描述

背景

HSRP(Hot Standby Router Protocol,热备份路由协议)是由思科系统(Cisco Systems)开发的一种专有协议,用于增强网络的可靠性和冗余度。HSRP的主要目标是在网络中提供一个虚拟的默认网关,即使物理路由器发生故障,也能保持网络通信的连续性。

在HSRP出现之前,网络通常依赖单一的默认网关(通常是路由器)来处理所有出站流量。这意味着如果这台路由器出现故障,整个网络的连通性将受到严重影响,因为没有其他路径可以替代,其实就是防止单点故障造成业务中断。

为了解决这个问题,思科设计了HSRP,以提供一种机制,使得多个路由器可以共享一个虚拟的IP地址,从而在主路由器失败时,备用路由器能够无缝地接管其功能,保证网络服务的持续性。

在这里插入图片描述

工作原理

HSRP允许多台路由器(称为“HSRP路由器”)组成一个组,其中一台被指定为活跃路由器(Active Router),也就是主网关,负责转发数据包。

同时,还有一台或几台处于待机状态的路由器(Standby Routers),也就是备网关,它们时刻准备着在活跃路由器发生故障时接管其角色。

这些路由器共同维护一个虚拟的MAC地址和IP地址,对外表现为单一的默认网关。
在这里插入图片描述

特点和优势

01 冗余
HSRP提供了高度的冗余,确保了即使在路由器硬件或软件故障的情况下,网络仍然可以正常运行

02 透明性
对于终端用户和主机来说,HSRP的切换是透明的,不会造成网络中断或重新配置

03 可扩展性
可以通过增加更多的路由器来增强网络的可靠性,而且HSRP组可以跨越不同的物理位置

实验准备

实验环境

EVE-community

设备镜像

路由器:i86bi LinuxL3-AdvEnterpriseK9-M2 157 3 May 2018.bin

交换机:i86bi linuxl2-adventerprisek9-ms.SSA.high iron 20190423.bin

PC:用路由器来模拟电脑PC,只需要关闭路由功能即可

实验目的

① 能让PC获取到地址 – DHCP

② 以DSW1和DSW2用HSRP虚拟冗余成两个VLAN的网关 — HSRP

③ R1和DSW1、DSW2通过OSPF实现内网互通 —OSPF

④ 然后实现PC 能上网,能Ping通ISP — Easy-IP(NAT)

DSW 1

VLANIF 10
IP地址:192.168.10.252
虚拟地址:192.168.10.254
优先级:150

VLANIF 20
IP地址:192.168.20.252
虚拟地址:192.168.10.254
优先级:100(默认)

DSW 2

VLANIF 10
IP地址:192.168.10.253
虚拟地址:192.168.10.254
优先级:100(默认)

VLANIF 20
IP地址:192.168.20.253
虚拟地址:192.168.10.254
优先级:150

配置

在这里插入图片描述

R1

Router>enable
Router#conf t
Router(config)#hostname R1R1(config)#int e0/0
R1(config-if)#no shutdown 
R1(config-if)#ip address 192.168.100.1 255.255.255.0
R1(config-if)#exitR1(config)#int e0/1
R1(config-if)#no shutdown 
R1(config-if)#ip address 192.168.200.1 255.255.255.0
R1(config-if)#exitR1(config)#int e0/2
R1(config-if)#no shutdown 
R1(config-if)#ip address 202.101.12.2 255.255.255.0
R1(config-if)#exit## OSPF
R1(config)#router ospf 110
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 192.168.100.0 0.0.0.255 area 0
R1(config-router)#network 192.168.200.0 0.0.0.255 area 0
R1(config-router)#exit## NAT配置
R1(config)#int e0/0
R1(config-if)#ip nat inside 
R1(config-if)#exitR1(config)#int e0/1       
R1(config-if)#ip nat inside 
R1(config-if)#exitR1(config)#int e0/2
R1(config-if)#ip nat outside 
R1(config-if)#exitR1(config)#access-list 1 permit 192.168.0.0 0.0.255.255R1(config)#ip nat inside source list 1 interface e0/2 overload R1(config)#ip route 0.0.0.0 0.0.0.0 202.101.12.1

DSW1

Switch>en
Switch>enable 
Switch#conf t
Switch(config)#hostname DSW1DSW1(config)#vlan 10,20
DSW1(config-vlan)#exit## 因为三层交换机是有路由功能又有交换功能的
## 关闭端口的交换功能,那就可以使用路由功能了
DSW1(config)#int e0/0
DSW1(config-if)#no switchport   ## 关闭交换功能,使用路由功能
DSW1(config-if)#no shutdown 
DSW1(config-if)#ip address 192.168.100.2 255.255.255.0
DSW1(config-if)#exitDSW1(config)#int range e0/1-3
DSW1(config-if-range)#switchport trunk encapsulation dot1q
DSW1(config-if-range)#switchport mode trunk 
DSW1(config-if-range)#exit## HSRP配置
## 选举活跃路由器(主):优先级大的为活跃路由器,默认优先级100DSW1(config)#int vlan 10
DSW1(config-if)#no shutdown ## 打开接口
## VLANIF10接口IP为“192.168.10.252DSW1(config-if)#ip address 192.168.10.252 255.255.255.0
## HSRP组10虚拟的IP地址为“192.168.10.254DSW1(config-if)#standby 10 ip 192.168.10.254
DSW1(config-if)#standby 10 priority 150   ## 优先级设置为“150DSW1(config-if)#standby 10 preempt        ## 开启抢占功能
DSW1(config-if)#exit## 这边没有指定优先级的话,默认为100
DSW1(config)#int vlan20
DSW1(config-if)#no shutdown 
DSW1(config-if)#standby 20 ip 192.168.20.254
DSW1(config-if)#standby 20 preempt 
DSW1(config-if)#exit## OSPF
DSW1(config)#router ospf 110
DSW1(config-router)#router-id 11.11.11.11
DSW1(config-router)#network 192.168.0.0 0.0.255.255 area 0
DSW1(config-router)#exit## DHCP
## 这边要注意的是,DSW1和DSW2的话,都要创建多个地址池
## 不管是不是主网关,因为到时候活跃路由器挂掉了,
## 流量到时候就都走备网关了,
## 但这个时候又没有地址池下发地址,那就会导致业务中断
## 所以地址池的话,就是都要创建DSW1(config)#ip dhcp pool vlan10
DSW1(dhcp-config)#network 192.168.10.0 255.255.255.0
DSW1(dhcp-config)#default-router 192.168.10.254
DSW1(dhcp-config)#dns-server 8.8.8.8
DSW1(dhcp-config)#exitDSW1(config)#ip dhcp pool vlan20               
DSW1(dhcp-config)#network 192.168.20.0 255.255.255.0
DSW1(dhcp-config)#default-router 192.168.20.254     
DSW1(dhcp-config)#dns-server 8.8.8.8                
DSW1(dhcp-config)#exit## 上网需要的默认路由
DSW1(config)#ip route 0.0.0.0 0.0.0.0 192.168.100.1

DSW2

Switch>enable 
Switch#conf t
Switch(config)#hostname DSW2DSW2(config)#vlan 10,20
DSW2(config-vlan)#exitDSW2(config)#int e0/0
DSW2(config-if)#no switchport 
DSW2(config-if)#no shutdown 
DSW2(config-if)#ip address 192.168.200.2 255.255.255.0
DSW2(config-if)#exitDSW2(config)#int range e0/1-3
DSW2(config-if-range)#switchport trunk encapsulation dot1q 
DSW2(config-if-range)#switchport mode trunk 
DSW2(config-if-range)#exit## HSRP
DSW2(config)#interface Vlan10
DSW2(config-if)#no shutdown
DSW2(config-if)#ip address 192.168.10.253 255.255.255.0
DSW2(config-if)#standby 10 ip 192.168.10.254
DSW2(config-if)#standby 10 preempt
DSW2(config-if)#exitDSW2(config)#interface Vlan20
DSW2(config-if)#no shutdown
DSW2(config-if)#ip address 192.168.20.253 255.255.255.0
DSW2(config-if)#standby 20 ip 192.168.20.254
DSW2(config-if)#standby 20 priority 150
DSW2(config-if)#standby 20 preempt
DSW2(config-if)#exit## OSPF
DSW2(config)#router ospf 110
DSW2(config-router)#router-id 12.12.12.12
DSW2(config-router)#network 192.168.0.0 0.0.255.255 area 0
DSW2(config-router)#exit## DHCP
DSW2(config)#ip dhcp pool vlan10
DSW2(dhcp-config)#network 192.168.10.0 255.255.255.0
DSW2(dhcp-config)#default-router 192.168.10.254 
DSW2(dhcp-config)#dns-server 8.8.8.8 
DSW2(dhcp-config)#exitDSW2(dhcp)#ip dhcp pool vlan20
DSW2(dhcp-config)#network 192.168.20.0 255.255.255.0
DSW2(dhcp-config)#default-router 192.168.20.254 
DSW2(dhcp-config)#dns-server 8.8.8.8 
DSW2(dhcp-config)#exit## 上网需要的默认路由
DSW2(config)#ip route 0.0.0.0 0.0.0.0 192.168.200.1

ASW1

Switch>enable 
Switch#conf t
Switch(config)#hostname ASW1ASW1(config)#vlan 10
ASW1(config-vlan)#exitASW1(config)#int e0/1
ASW1(config-if)#switchport mode access 
ASW1(config-if)#switchport access vlan 10
ASW1(config-if)#exitASW1(config)#int range e0/0,e0/2
ASW1(config-if-range)#switchport trunk encapsulation dot1q 
ASW1(config-if-range)#switchport mode trunk
ASW1(config-if-range)#exit

ASW2

Switch>enable 
Switch#conf t
Switch(config)#hostname ASW2ASW2(config)#vlan 20
ASW2(config-vlan)#exitASW2(config)#int e0/1
ASW2(config-if)#switchport mode access 
ASW2(config-if)#switchport access vlan 20
ASW2(config-if)#exitASW2(config)#int range e0/0,e0/2
ASW2(config-if-range)#switchport trunk encapsulation dot1q 
ASW2(config-if-range)#switchport mode trunk
ASW2(config-if-range)#exit

PC1


Router>enable
Router#conf t
Router(config)#hostname PC1
## 关闭路由功能
PC1(config)#no ip routing ## 用DHCP方式获取上网地址
PC1(config)#int e0/0
PC1(config-if)#no shutdown 
PC1(config-if)#ip address dhcp
PC1(config-if)#exit

PC2


Router>enable
Router#conf t
Router(config)#hostname PC2## 关闭路由功能
PC2(config)#no ip routing PC2(config)#int e0/0
PC2(config-if)#no shutdown 
PC2(config-if)#ip address dhcp
PC2(config-if)#exit

ISP

Router>en
Router#conf t
Router(config)#host ISPISP(config)#int e0/0
ISP(config-if)#no shutdown 
ISP(config-if)#ip address 202.101.12.1 255.255.255.0
ISP(config-if)#exit

测试

查看HSRP的简要信息

DSW1作为VLAN10的活跃路由器,VLAN20的备网关
在这里插入图片描述
DSW1作为VLAN10的活跃路由器,VLAN20的备网关
在这里插入图片描述

查看PC接口地址

在这里插入图片描述
在这里插入图片描述

PC上网通信测试

图片

在这里插入图片描述

查看PC是否按照路径走

PC1优先走DSW1:192.168.10.252

图片

PC2优先走DSW2:192.168.20.253

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com