vrrp 虚拟路由冗余协议:解决网关出现单点故障
默认情况,所有数据包交给master处理,出现故障时,通过热备份的方式切换线路,保证通信的连续和稳定。
基本拓扑
基本配置:
sw3
# 创建vlan 10
[Huawei]vlan 10
[Huawei-vlan10]sy sw3
[sw3]vlan 10
[sw3-vlan10]quit
# 配置Ethernet 0/0/1 接口
[sw3]int e 0/0/1
[sw3-Ethernet0/0/1]port link-type trunk
[sw3-Ethernet0/0/1]port trunk allow-pass vlan all
[sw3-Ethernet0/0/1]quit
# 配置Ethernet 0/0/2 接口
[sw3]int e 0/0/2
[sw3-Ethernet0/0/2]port link-type trunk
[sw3-Ethernet0/0/2]port trunk allow-pass vlan all
[sw3-Ethernet0/0/2]quit
# 配置Ethernet 0/0/3 接口
[sw3]int e 0/0/3
[sw3-Ethernet0/0/3]port link-type access
[sw3-Ethernet0/0/3]port default vlan 10
[sw3-Ethernet0/0/3]
sw1
[Huawei]un in en
[Huawei]sy sw1
[sw1]vlan 10
[sw1-vlan10]quit
# 配置GigabitEthernet 0/0/2 接口
[sw1]int g 0/0/2
[sw1-GigabitEthernet0/0/2]port link-type trunk
[sw1-GigabitEthernet0/0/2]port trunk allow-pass vlan all
[sw1-GigabitEthernet0/0/2]quit
# 配置vlan 10 的虚拟网关地址
[sw1]int vlanif 10
[sw1-Vlanif10]ip add 10.1.10.251 24
[sw1-Vlanif10]quit
[sw1]quit
sw2
[Huawei]un in en
[Huawei]sy sw2
[sw2]vlan 10
[sw2-vlan10]quit
[sw2]int giga 0/0/2
[sw2-GigabitEthernet0/0/2]port link-type trunk
[sw2-GigabitEthernet0/0/2]port trunk allow-pass vlan all
[sw2-GigabitEthernet0/0/2]quit
[sw2]int vlanif 10
[sw2-Vlanif10]ip add 10.1.10.252 24
[sw2-Vlanif10]quit
[sw2]quit
vrrp虚拟网关配置操作
sw1
<sw1>sy
[sw1]int vlanif 10
# 创建工作组10并给定虚拟ip地址
[sw1-Vlanif10]vrrp vrid 10 virtual-ip 10.1.10.254
# 给工作组10配置优先级,默认为100,此处给定120使sw1成为了master
[sw1-Vlanif10]vrrp vrid 10 priority 120
[sw1-Vlanif10]quit
sw2
<sw2>sy
[sw2]int vlanif10
[sw2-Vlanif10]vrrp vrid 10 virtual-ip 10.1.10.254
[sw2-Vlanif10]quit
[sw2]
使用dis vrrp
查看vrrp配置
sw1的vrrp信息
sw2的vrrp信息
当然,也可以直接查看简略信息dis vrrp bri
测试通信情况
使用PC1 ping 网关,发现可以ping通,同时查看arp信息,发现是经过10.1.10.251(master)获得mac地址的
通过查看sw3上的mac地址,也能证实,数据是走的eth 0/0/1 接口(与sw1 master相连)出去的
测试:将sw1关机来模拟故障状态
再用pc1去ping网关,测试vrrp是否正常工作,同时查看arp信息,发现确实是从eth 0/0/2 (与sw2 backup相连)出去的
当前是模拟的sw1设备出现故障,那么如果是链路出现故障该怎么办呢?那么就需要配置链路检测功能来解决了
先恢复到之前的状态,可以知道PC1到网关是走的sw1
配置链路检测功能
[sw1]int vlanif 10
# 删除之前配置的优先级
[sw1-Vlanif10]undo vrrp vrid 10 priority
# 配置当上行链路故障后,将优先级降低30
[sw1-Vlanif10]vrrp vrid 10 track int giga 0/0/1 reduced 30
# 配置此接口来做链路跟踪
[sw1-Vlanif10]vrrp vrid 10 track int giga 0/0/1
# 配置优先级为120
[sw1-Vlanif10]vrrp vrid 10 priority 120
[sw1-Vlanif10]quit
手动关闭sw1的giga 0/0/1来模拟链路发生故障
此时,查询sw1上的vrrp信息,发现状态已经改变为backup,运行优先级从120变为了90
而sw2的状态变为master,运行优先级为100高于sw1
在pc1上ping网关发现是通过sw2去来连接的
负载均衡的配置
vrrp 默认优先级为100【0~255】,越大,越可能成为master,若vrrp虚拟ip地址与接口的ip地址相同,那么优先级会自动变为255
基本拓扑
sw3增加配置
<sw3>sys
[sw3]vlan 20
[sw3-vlan20]quit
[sw3]int e 0/0/4
[sw3-Ethernet0/0/4]port link-type access
[sw3-Ethernet0/0/4]port default vlan 20
sw1增加配置
<sw1>sy
[sw1]vlan 20
[sw1-vlan20]int vlanif 20
[sw1-Vlanif20]ip add 10.1.20.251 24
[sw1-Vlanif20]vrrp vrid 20 virtual-ip 10.1.20.254
[sw1-Vlanif20]quit
sw2增加的配置
<sw2>sy
[sw2]vlan 20
[sw2-vlan20]int vlanif 20
[sw2-Vlanif20]ip add 10.1.20.252 24
[sw2-Vlanif20]vrrp vrid 20 virtual-ip 10.1.20.254
[sw2-Vlanif20]vrrp vrid 20 priority 105
[sw2-Vlanif20]quit
查看sw1的vrrp信息
<sw1>sy
Enter system view, return user view with Ctrl+Z.
[sw1]dis vrrp
Vlanif10 | Virtual Router 10
State : Master #sw1在工作组10中为master
Virtual IP : 10.1.10.254
Master IP : 10.1.10.251
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-010a
Check TTL : YES
Config type : normal-vrrp
Track IF : GigabitEthernet0/0/1 Priority reduced : 30
IF state : UP
Create time : 2024-07-31 15:52:45 UTC-08:00
Last change time : 2024-07-31 15:54:08 UTC-08:00
Vlanif20 | Virtual Router 20
State : Backup # sw1在工作组20中为backup
Virtual IP : 10.1.20.254
Master IP : 10.1.20.252
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 105
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0114
Check TTL : YES
Config type : normal-vrrp
Create time : 2024-07-31 15:58:14 UTC-08:00
Last change time : 2024-07-31 16:01:00 UTC-08:00
[sw1]
查看sw2的vrrp信息
[sw2]dis vrrp
Vlanif10 | Virtual Router 10
State : Backup # sw2在工作组10中为backup
Virtual IP : 10.1.10.254
Master IP : 10.1.10.251
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-010a
Check TTL : YES
Config type : normal-vrrp
Create time : 2024-07-31 15:05:14 UTC-08:00
Last change time : 2024-07-31 15:54:08 UTC-08:00
Vlanif20 | Virtual Router 20
State : Master # sw2在工作组20中为master
Virtual IP : 10.1.20.254
Master IP : 10.1.20.252
PriorityRun : 105
PriorityConfig : 105
MasterPriority : 105
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0114
Check TTL : YES
Config type : normal-vrrp
Create time : 2024-07-31 16:00:43 UTC-08:00
Last change time : 2024-07-31 16:01:00 UTC-08:00
[sw2]
测试pc1和pc2之间的通信