组网要求:PC1通过Switch双归属到SwitchA和SwitchB。为保证用户的各种业务在网络传输中不中断,需在SwitchA和SwitchB上配置VRRP主备备份功能。正常情况下,主机以SwitchA为默认网关接入Internet,当SwitchA故障时,SwitchB接替SwitchA作为网关继续进行工作,实现网关的冗余备份。SwitchA故障恢复后,其延时20秒通过抢占的方式重新成为Master,承担数据传输。
一、主要知识点:
VRRP主备备份简介
通常,同一网段内的所有主机上都存在一条相同的、以网关为下一跳的缺省路由。主机发往其他网段的报文将通过缺省路由发往网关,再由网关进行转发,从而实现主机与外部网络的通信。当网关发生故障时,本网段内所有以网关为缺省路由的主机将无法与外部网络通信。增加出口网关是提高系统可靠性的常见方法,此时如何在多个出口之间进行选路就成为需要解决的问题。
VRRP的出现很好的解决了这个问题。VRRP能够在不改变组网的情况下,采用将多台路由设备组成一个虚拟路由器,通过配置虚拟路由器的IP地址为默认网关,实现默认网关的备份。当网关设备发生故障时,VRRP机制能够选举新的网关设备承担数据流量,从而保障网络通信的可靠性。在配置VRRP备份组内各交换机时,建议将Backup配置为立即抢占,即不延迟(延迟时间为0),而将Master配置为延时抢占,并且配置15秒以上的延迟时间。这样配置的目的是为了在网络环境不稳定时,在上下行链路的状态恢复一致性期间等待一定时间,避免由于双方频繁抢占导致用户设备学习到错误的Master设备地址而导致流量中断问题。
抢占模式:在抢占模式下,如果Backup设备的优先级比当前Master设备的优先级高,则主动将自己切换成Master。
非抢占模式:在非抢占模式下,只要Master设备没有出现故障,Backup设备即使随后被配置了更高的优先级也不会成为Master设备。
配置注意事项:
保证同一备份组的设备上配置相同的备份组号(virtual-router-id)。
不同备份组之间的虚拟IP地址不能重复,并且必须和接口的IP地址在同一网段。
请确保该场景下互联接口的STP处于未使能状态。同时将互连接口退出VLAN1,避免形成环路。因为在使能STP的环形网络中,如果用交换机的VLANIF接口构建三层网络,会导致某个端口被阻塞,从而导致三层业务不能正常运行。
二、配置思路:
1. 配置各设备接口IP地址及路由协议,使各设备间网络层连通。
2. 在SwitchA和SwitchB上配置VRRP备份组。其中,SwitchA上配置较高优先级和20秒抢占延时,作为Master设备承担流量转发;SwitchB上配置较低优先级,作为备用交换机,实现网关冗余备份。
三、IP设置:
1、PC1:192.168.10.253/24,vlan10
2、switch:vlan10
3、swithcA:
VLANif10:192.168.10.1/24 ,vlan10
Vlanif20:192.168.20.1/24 ,vlan20
3、switchB:
VLANif10:192.168.10.2/24 ,vlan10
Vlanif30:192.168.30.1/24 ,vlan30
4、switchC:
VLANif20:192.168.20.2/24 ,vlan20
Vlanif30:192.168.30.2/24 ,vlan30
Vlanif40:192.168.40.1/24 ,vlan40
5、Virtual IP address:192.168.10.254/24
四、华为模拟器实操录像:
五、switch交换机的主要配置文件:
#
sysname switch
#
vlan batch 10
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 10
#
interface GigabitEthernet0/0/2
port hybrid pvid vlan 10
port hybrid untagged vlan 10
#
interface GigabitEthernet0/0/3
port hybrid pvid vlan 10
port hybrid untagged vlan 10
#
user-interface con 0
user-interface vty 0 4
#
return
六、switchA交换机的主要配置文件:
#
sysname siwthcA
#
vlan batch 10 20
#
stp disable
#
interface Vlanif10
ip address 192.168.10.1 255.255.255.0
vrrp vrid 1 virtual-ip 192.168.10.254
vrrp vrid 1 priority 120
vrrp vrid 1 preempt-mode timer delay 20
#
interface Vlanif20
ip address 192.168.20.1 255.255.255.0
#
interface MEth0/0/1
#
interface GigabitEthernet0/0/1
port hybrid pvid vlan 10
port hybrid untagged vlan 10
#
interface GigabitEthernet0/0/2
port hybrid pvid vlan 20
port hybrid untagged vlan 20
#
ospf 1
area 0.0.0.0
network 192.168.10.0 0.0.0.255
network 192.168.20.0 0.0.0.255
#
user-interface con 0
user-interface vty 0 4
#
return
七、switchB交换机的主要配置文件:
#
sysname switchB
#
vlan batch 10 30
#
interface Vlanif10
ip address 192.168.10.2 255.255.255.0
vrrp vrid 1 virtual-ip 192.168.10.254
#
interface Vlanif30
ip address 192.168.30.1 255.255.255.0
#
interface MEth0/0/1
#
interface GigabitEthernet0/0/1
port hybrid pvid vlan 10
port hybrid untagged vlan 10
#
interface GigabitEthernet0/0/2
port hybrid pvid vlan 30
port hybrid untagged vlan 30
#
ospf 1
area 0.0.0.0
network 192.168.10.0 0.0.0.255
network 192.168.30.0 0.0.0.255
#
user-interface con 0
user-interface vty 0 4
#
return
八、switchC交换机的主要配置文件:
#
sysname switchC
#
vlan batch 20 30 40
#
interface Vlanif20
ip address 192.168.20.2 255.255.255.0
#
interface Vlanif30
ip address 192.168.30.2 255.255.255.0
#
interface Vlanif40
ip address 192.168.40.1 255.255.255.0
#
interface MEth0/0/1
#
interface GigabitEthernet0/0/1
port hybrid pvid vlan 20
port hybrid untagged vlan 20
#
interface GigabitEthernet0/0/2
port hybrid pvid vlan 30
port hybrid untagged vlan 30
#
interface GigabitEthernet0/0/3
port link-type access
port default vlan 40
#
ospf 1
area 0.0.0.0
network 192.168.20.0 0.0.0.255
network 192.168.30.0 0.0.0.255
network 192.168.40.0 0.0.0.255
#
user-interface con 0
user-interface vty 0 4
#
return
九、验证配置结果:
1、完成上述配置以后,在SwitchA和SwitchB上分别执行display vrrp命令,可以看到SwitchA在备份组中的状态为Master,SwitchB在备份组中的状态为Backup。
[siwthcA]disp vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 192.168.10.254
Master IP : 192.168.10.1
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 20 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-10-21 13:38:15 UTC-08:00
Last change time : 2020-10-21 13:55:15 UTC-08:00
[switchB]disp vrrp
Vlanif10 | Virtual Router 1
State : Backup
Virtual IP : 192.168.10.254
Master IP : 192.168.10.1
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-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-10-21 13:41:00 UTC-08:00
Last change time : 2020-10-21 13:55:39 UTC-08:00
2、在SwitchA和SwitchB上执行display ip routing-table命令,SwitchA上可以看到路由表中有一条目的地址为虚拟IP地址的直连路由,而SwitchB上该路由为OSPF路由。SwitchA和SwitchB上的显示信息如下。
[siwthcA]disp ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 9 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.10.0/24 Direct 0 0 D 192.168.10.1 Vlanif10
192.168.10.1/32 Direct 0 0 D 127.0.0.1 Vlanif10
192.168.10.254/32 Direct 0 0 D 127.0.0.1 Vlanif10
192.168.20.0/24 Direct 0 0 D 192.168.20.1 Vlanif20
192.168.20.1/32 Direct 0 0 D 127.0.0.1 Vlanif20
192.168.30.0/24 OSPF 10 2 D 192.168.20.2 Vlanif20
OSPF 10 2 D 192.168.10.2 Vlanif10
192.168.40.0/24 OSPF 10 2 D 192.168.20.2 Vlanif20
[switchB]disp ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 9 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.10.0/24 Direct 0 0 D 192.168.10.2 Vlanif10
192.168.10.2/32 Direct 0 0 D 127.0.0.1 Vlanif10
192.168.10.254/32 OSPF 10 2 D 192.168.10.1 Vlanif10
192.168.20.0/24 OSPF 10 2 D 192.168.30.2 Vlanif30
OSPF 10 2 D 192.168.10.1 Vlanif10
192.168.30.0/24 Direct 0 0 D 192.168.30.1 Vlanif30
192.168.30.1/32 Direct 0 0 D 127.0.0.1 Vlanif30
192.168.40.0/24 OSPF 10 2 D 192.168.30.2 Vlanif30
3、在SwitchA的接口GE0/0/1上执行shutdown命令,模拟SwitchA出现故障。
[SwitchA]interface gigabitethernet/0/1
[SwitchA-GigabitEthernet0/0/1]shutdown
[SwitchA-GigabitEthernet0/0/1]quit
4、在SwitchB上执行display vrrp命令查看VRRP状态信息,可以看到SwitchB的状态是Master。
[switchB]disp vrrp
Vlanif10 | Virtual Router 1
State : Master
Virtual IP : 192.168.10.254
Master IP : 192.168.10.2
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 100
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Create time : 2020-10-21 13:41:00 UTC-08:00
Last change time : 2020-10-21 14:08:52 UTC-08:00
领取专属 10元无门槛券
私享最新 技术干货