HSRP
路由器双机热备(Router Hot Standby)是一种网络设备冗余配置方式,其中两个路由器组成一对,一个为活动路由器(Active Router),另一个为备用路由器(Standby Router)。活动路由器处理所有数据流量和网络操作,而备用路由器则监控活动路由器的状态,并在必要时快速接管其职责以保持网络连通性。这种配置方式可以提高网络的可用性和鲁棒性。
HSRP(Hot Standby Router Protocol)是一种Cisco开发的路由器双机热备协议,用于提高默认网关的可用性和冗余性。在HSRP配置中,多个路由器组成一个虚拟路由器组,并且其中一个路由器被选为活动路由器来处理数据流量,而其他路由器则作为备用路由器等待接管职责。HSRP使用虚拟IP地址和虚拟MAC地址来实现无感知的故障转移。如果活动路由器失效,备用路由器将立即接管职责并继续为网络设备提供默认网关服务。
语法
interface <interface>
vrrp <group-number> ip <virtual-ip-address>
standby <group-number> priority <priority-value>
track <object-number> decrement <value>
interface <interface>
standby <group-number> ip <virtual-ip-address>
standby <group-number> preempt
standby <group-number> priority <priority-value>
track <object-number> decrement <value>
类型 | 端口 | 地址 |
---|---|---|
PC10-1 | FastEthernet0/1 | 172.17.165.2/24 |
PC10-2 | FastEthernet0/1 | 172.17.165.1/24 |
PC10-3 | FastEthernet0/1 | dhcp |
r0 | GigabitEthernet0/0 | 172.17.165.253/24 |
r0 | GigabitEthernet0/1 | 200.200.200.10/30 |
r1 | GigabitEthernet0/0 | 172.17.165.252/24 |
r1 | GigabitEthernet0/1 | 200.200.200.1/30 |
r2 | GigabitEthernet0/1 | 200.200.200.2/30 |
r2 | GigabitEthernet0/2 | 200.200.200.9/30 |
r2 | GigabitEthernet0/0 | 192.168.1.254/24 |
r0
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
#给路由器改名称
Router(config)#hostname r0
#给接口添加地址
r0(config)#int g0/0
r0(config-if)#ip add 172.17.165.253 255.255.255.0
r0(config-if)#no sh
r0(config-if)#ex
r0(config)#int g0/1
r0(config-if)#ip add 200.200.200.10 255.255.255.252
r0(config-if)#no sh
r0(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up
r0(config-if)#
#配置静态路由
r0(config)#ip route 192.168.1.0 255.255.255.0 200.200.200.9
r0(config)#
#配置HSRP
r0(config)#int g0/0
#配置虚拟网关
r0(config-if)#standby 10 ip 172.17.165.254
#配置优先级,优先级范围1-255,数字越大表示优先级越高,监听端口如果不可用,优先级默认自降10
r0(config-if)#standby 10 priority 195
#配置抢占模式
r0(config-if)#standby 10 preempt
#配置端口监听(监听端口是否可用)
r0(config-if)#standby 10 track g0/1
r0(config-if)#ex
r0(config)#
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 10 state Speak -> Standby
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 10 state Standby -> Active
r1
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname r1
r1(config)#int g0/0
r1(config-if)#ip add 172.17.165.252 255.255.255.0
r1(config-if)#no sh
r1(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
r1(config-if)#ex
r1(config)#int g0/1
r1(config-if)#ip add 200.200.200.1 255.255.255.252
r1(config-if)#no sh
r1(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
r1(config-if)#
r1(config)#ip route 192.168.1.0 255.255.255.0 200.200.200.2
r1(config)#
r1(config)#int g0/0
r1(config-if)#standby 10 ip 172.17.165.254
r1(config-if)#standby 10 priority 200
r1(config-if)#standby 10 preempt
r1(config-if)#standby 10 track g0/1
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 10 state Speak -> Standby
ta
r1(config-if)#
r2
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname r2
r2(config)#int g0/1
r2(config-if)#ip add 200.200.200.2 255.255.255.252
r2(config-if)#no sh
r2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up
r2(config-if)#ex
r2(config)#int g0/2
r2(config-if)#ip add 200.200.200.9 255.255.255.252
r2(config-if)#no sh
r2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up
r2(config-if)#ex
r2(config)#int g0/0
r2(config-if)#ip add 192.168.1.254 255.255.255.0
r2(config-if)#no sh
r2(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
r2(config-if)#ex
r2(config)#ip dhcp pool 1-254
r2(dhcp-config)#network 192.168.1.0 255.255.255.0
r2(dhcp-config)#default-router 192.168.1.254
r2(dhcp-config)#ex
r2(config)#ip dhcp excluded-address 192.168.1.240 192.168.1.254
r2(config)#ip route 172.17.165.0 255.255.255.0 200.200.200.1
r2(config)#ip route 172.17.165.0 255.255.255.0 200.200.200.10
r2(config)#
测试结果
ping -t 192.168.1.1一直法宝测试,手动断开r1的g0/1端口测试结果如下
三层交换机双机热备
ISP
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname isp
isp(config)#int g0/2
isp(config-if)#ip add 100.1.1.254 255.255.255.0
isp(config-if)#no sh
isp(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
isp(config-if)#ex
isp(config)#ip dhcp pool isp
isp(dhcp-config)#network 100.1.1.0 255.255.255.0
isp(dhcp-config)#default-router 100.1.1.254
isp(dhcp-config)#dns-server 114.114.114.114
isp(dhcp-config)#ex
isp(config)#ip dhcp ex
isp(config)#ip dhcp excluded-address 100.1.1.240 100.1.1.254
isp(config)#
isp(config)#int g0/1
isp(config-if)#ip add 200.1.1.10 255.255.255.252
isp(config-if)#no sh
isp(config-if)#ex
isp(config)#int g0/0
isp(config-if)#ip add 200.1.1.2 255.255.255.252
isp(config-if)#no sh
isp(config-if)#ex
isp(config)#ip route 0.0.0.0 0.0.0.0 200.1.1.1
isp(config)#ip route 0.0.0.0 0.0.0.0 200.1.1.9
isp(config)#
r1-1
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#no sh
Router(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
Router(config-if)#ip add 172.17.166.2 255.255.255.252
Router(config-if)#ex
Router(config)#int g0/2
Router(config-if)#no sh
Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up
Router(config-if)#ip add 172.17.166.26 255.255.255.252
Router(config-if)#ex
Router(config)#
#这里只是为了方便,实际上应该用ospf
Router(config)#ip route 172.17.165.0 255.255.255.0 172.17.166.1
Router(config)#ip route 172.17.165.0 255.255.255.0 172.17.166.25
Router(config)#
Router(config)#int g0/1
Router(config-if)#no sh
Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
Router(config-if)#ip add 200.1.1.1 255.255.255.252
Router(config-if)#ex
#这里按需求即可,不一定要使用ospf
Router(config)#ip route 100.1.1.0 255.255.255.0 200.1.1.2
Router(config)#
r1-2
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#no sh
Router(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
Router(config-if)#ip add 172.17.166.6 255.255.255.252
Router(config-if)#ex
Router(config)#int g0/2
Router(config-if)#no sh
Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up
Router(config-if)#ip add 172.17.166.22 255.255.255.252
Router(config-if)#ex
Router(config)#
#这里只是为了方便,实际上应该用ospf
Router(config)#ip route 172.17.165.0 255.255.255.0 172.17.166.5
Router(config)#ip route 172.17.165.0 255.255.255.0 172.17.166.21
Router(config)#
r1-2(config)#int g0/1
r1-2(config-if)#no sh
r1-2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up
r1-2(config-if)#ip add 200.1.1.9 255.255.255.252
r1-2(config-if)#ex
#这里按需求即可,不一定要使用ospf
r1-2(config)#ip route 100.1.1.0 255.255.255.0 200.1.1.10
r1-2(config)#
msw1
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname msw1
msw1(config)#int port-channel 1
msw1(config-if)#int range g1/0/21-24
msw1(config-if-range)#channel-group 1 mode on
msw1(config-if-range)#
%LINK-5-CHANGED: Interface Port-channel1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Port-channel1, changed state to up
msw1(config-if-range)#ex
msw1(config)#int vlan 1
msw1(config-if)#ip add 172.17.165.252 255.255.255.0
msw1(config-if)#standby 1 ip 172.17.165.254
msw1(config-if)#standby 1 priority 200
msw1(config-if)#standby 1 preempt
msw1(config-if)#standby 1 track g1/0/1
msw1(config-if)#standby 1 track g1/0/2
msw1(config-if)#ex
msw1(config)#
msw1(config)#int g1/0/1
msw1(config-if)#no sw
msw1(config-if)#no sh
msw1(config-if)#ip add 172.17.166.1 255.255.255.252
msw1(config-if)#ex
msw1(config)#int g1/0/2
msw1(config-if)#no sw
msw1(config-if)#no sh
msw1(config-if)#ip add 172.17.166.5 255.255.255.252
msw1(config-if)#ex
#这里只是为了方便,实际上应该用ospf
msw1(config)#ip route 0.0.0.0 0.0.0.0 172.17.166.2
msw1(config)#ip route 0.0.0.0 0.0.0.0 172.17.166.6
msw1(config)#spanning-tree vlan 1 root primary
msw2
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname msw2
msw2(config)#int port
msw2(config)#int port-channel 1
msw2(config-if)#int range g1/0/21-24
msw2(config-if-range)#channel-group 1 mode on
msw2(config-if-range)#
%LINK-5-CHANGED: Interface Port-channel1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Port-channel1, changed state to up
msw2(config-if-range)#
%LINK-5-CHANGED: Interface Port-channel1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Port-channel1, changed state to up
msw2(config-if-range)#ex
msw2(config-if)#standby 1 ip 172.17.165.254
msw2(config-if)#standby 1 priority 195
msw2(config-if)#standby 1 preempt
msw2(config-if)#standby 1 track g1/0/1
msw2(config-if)#standby 1 track g1/0/2
msw2(config)#int g1/0/1
msw2(config-if)#no sw
msw2(config-if)#no sh
msw2(config-if)#ip add 172.17.166.21 255.255.255.252
msw2(config-if)#ex
msw2(config)#int g1/0/2
msw2(config-if)#no sw
msw2(config-if)#no sh
msw2(config-if)#ip add 172.17.166.25 255.255.255.252
msw2(config-if)#ex
#这里只是为了方便,实际上应该用ospf
msw2(config)#ip route 0.0.0.0 0.0.0.0 172.17.166.22
msw2(config)#ip route 0.0.0.0 0.0.0.0 172.17.166.26
msw2(config)#ip routing
msw2(config)#spanning-tree vlan 1 root secondary