VRRP和MSTP协议详解及配置实例
VRRP和MSTP协议详解及配置实例
本文主要介绍了VRRP(虚拟路由器冗余协议)和MSTP(多生成树协议)的概念、作用及配置方法,并通过一个具体的实验项目进行了实践演示。文章内容详尽,涵盖了协议的基本原理、应用场景以及具体的配置步骤,适合网络工程技术人员学习和参考。
实验要求及拓扑
实验拓扑如上所示,现在要求S1和S2使用VRRP配置虚拟网关冗余备份,并实现底层PC的负载分担。为了实现VLAN间数据流量的负载均衡,要求配置MSTP来实现。
VRRP协议
1. VRRP介绍
VRRP(虚拟路由器备份协议)是由IETF提出的解决局域网中配置静态网关出现单点失效现象的路由协议,VRRP广泛应用在边缘网络中。
2. VRRP的作用
(1)为了防止单点故障。
(2)网关冗余,当网关发生故障的时候,能让PC快速的切换。
3. VRRP的协议版本
VRRP协议包括两个版本:VRRPv2和VRRPv3。VRRPv2仅适用于IPv4网络,VRRPv3适用于IPv4和IPv6两种网络。
4. VRRP组成员
(1)Master路由器
活动状态(Master)
当VRRP设备处于Master状态时,它将会承担虚拟路由设备的所有转发工作,并定期向整个虚拟内发送VRRP通告报文。
(2)Backup路由器
备份状态(Backup)
当VRRP设备处于Backup状态时,它不会承担虚拟路由设备的转发工作,并定期接受Master设备的VRRP通告报文,判断Master的工作状态是否正常。
(3)虚拟路由器
虚拟路由器是VRRP备份组中所有路由器的集合,它是一个逻辑概念,并不是正真存在的。
(4)其他路由器
5. VRRP协议报文
只有一种报文:Advertisement报文;其目的IP地址是224.0.0.18,目的MAC地址是01-00-5e-00-00-12,协议号是112。
6. VRRP应用场景
(1)与接口状态联动
VRRP可以与上行接口的状态绑定在一起,当承担转发任务的Master设备的上行接口出现异常时,Master设备会降低一定的优先级,当优先级低于Backup设备的优先级时,Backup设备就会切换为Master设备,从而防止因为上行接口的异常导致业务受损。
(2)与路由状态联动
VRRP可以与上行路由的状态绑定在一起,当上行路由出现异常时,Master设备可以降低一定的优先级,当优先级低于Backup设备的优先级时,Backup设备就会切换为Master设备,从而防止因为上行路由的异常导致业务受损。
MSTP协议
1. MSTP介绍
MSTP(Multiple Spanning tree Algorithm and protocol)是多生成树技术,为了弥补STP和RSTP的缺陷,IEEE于2002年发布的802.1s标准定义了MSTP。MSTP兼容STP和RSTP,既可以快速收敛,又提供了数据转发的多个冗余路径,在数据转发过程中实现VLAN数据的负载均衡。
2. 端口角色
(1)根端口
非根交换机上到根交换机开销最小的端口就是该交换机的根端口。
(2)指定端口
该交换机向下游交换机发送BPDU或者数据流量的端口。
(3)边缘端口
位于网络最边缘处,不参与生成树计算,一般作为连接非交换机设备。
(4)预备端口
从转发流量的角度来看,预备端口提供了到达根交换机的一个备份链路。其接口状态为阻塞,不转发数据流量。
(5)备份端口
当同一台交换机的两个端口互相连接时就会形成一个环路,此时交换机会将其中一个端口堵塞,备份端口就是被堵塞的端口。
3. MSTP的端口状态
(1)Forwarding
在这种状态下,端口既转发用户流量,又接收/发送BPDU报文,称为转发状态。
(2)Learning
这是一种过渡状态。在Learning状态下,交换机会根据收到的用户流量,学习MAC地址表,但不转发用户流量,所以称为学习状态。Learning状态的端口接收/发送BPDU报文,但不转发用户流量。
(3)Discarding
在这种状态下,端口只接收BPDU报文,称为丢弃状态。
实例配置
1. 底层PC配置
2. S3, S4配置
S3
sysname S3
vlan batch 2 to 3
stp mode mstp #设置stp为mstp
stp region-configuration
region-name RG1
instance 2 vlan 2
instance 3 vlan 3
active region-configuration
#配置vlan中继
interface Ethernet0/0/1
port link-type access
port default vlan 2
interface Ethernet0/0/2
port link-type access
port default vlan 3
interface Ethernet0/0/14
port link-type trunk
port trunk allow-pass vlan 2 to 3
interface Ethernet0/0/15
port link-type trunk
port trunk allow-pass vlan 2 to 3
S4
sysname S4
vlan batch 2 4
##配置mstp
stp mode mstp
stp region-configuration
region-name RG1
instance 2 vlan 2
instance 4 vlan 4
active region-configuration
#配置vlan中继
interface Ethernet0/0/1
port link-type access
port default vlan 2
interface Ethernet0/0/2
port link-type access
port default vlan 4
interface Ethernet0/0/14
port link-type trunk
port trunk allow-pass vlan 2 4
interface Ethernet0/0/15
port link-type trunk
port trunk allow-pass vlan 2 4
3. S1,S2配置
S1
sysname S1
vlan batch 2 to 4 100
#配置mstp
stp mode mstp
stp region-configuration
region-name RG1
instance 2 vlan 2
instance 3 vlan 3
active region-configuration
#配置主根和从根
stp instance 2 root primary
stp instance 3 root secondary
#配置vrrp
interface Vlanif2
ip address 192.219.20.1 255.255.255.0
vrrp vrid 2 virtual-ip 192.219.20.254
vrrp vrid 2 priority 200
vrrp vrid 2 preempt-mode timer delay 1
vrrp vrid 2 track interface GigabitEthernet0/0/1 reduced 100
interface Vlanif3
ip address 192.219.30.1 255.255.255.0
vrrp vrid 3 virtual-ip 192.219.30.254
vrrp vrid 3 priority 150
vrrp vrid 3 preempt-mode timer delay 1
interface Vlanif4
ip address 192.219.40.2 255.255.255.0
vrrp vrid 4 virtual-ip 192.219.40.254
vrrp vrid 4 priority 150
vrrp vrid 4 preempt-mode timer delay 1
interface Vlanif100
ip address 192.219.100.1 255.255.255.252
#配置中继
interface GigabitEthernet0/0/1
port link-type access
port default vlan 100
interface GigabitEthernet0/0/13
port link-type trunk
port trunk allow-pass vlan 2 to 4
interface GigabitEthernet0/0/14
port link-type trunk
port trunk allow-pass vlan 2 to 3
interface GigabitEthernet0/0/15
port link-type trunk
port trunk allow-pass vlan 2 to 4
#配置默认路由
ip route-static 0.0.0.0 0.0.0.0 192.219.100.2
S2
sysname S2
vlan batch 2 to 4 100
#配置mstp
syp mode mstp
stp region-configuration
region-name RG1
instance 2 vlan 2
instance 4 vlan 4
active region-configuration
#配置主根和从根
stp instance 2 root secondary
stp instance 4 root primary
#配置vrrp
interface Vlanif2
ip address 192.219.20.2 255.255.255.0
vrrp vrid 2 virtual-ip 192.219.20.254
vrrp vrid 2 priority 150
vrrp vrid 2 preempt-mode timer delay 1
interface Vlanif3
ip address 192.219.30.2 255.255.255.0
vrrp vrid 3 virtual-ip 192.219.30.254
vrrp vrid 3 priority 150
interface Vlanif4
ip address 192.219.40.1 255.255.255.0
vrrp vrid 4 virtual-ip 192.219.40.254
vrrp vrid 4 priority 200
vrrp vrid 4 preempt-mode timer delay 1
vrrp vrid 4 track interface GigabitEthernet0/0/1 reduced 100
interface Vlanif100
ip address 192.219.100.6 255.255.255.252
#配置中继
interface GigabitEthernet0/0/1
port link-type access
port default vlan 100
interface GigabitEthernet0/0/13
port link-type trunk
port trunk allow-pass vlan 2 to 4
interface GigabitEthernet0/0/14
port link-type trunk
port trunk allow-pass vlan 2 4
interface GigabitEthernet0/0/15
port link-type trunk
port trunk allow-pass vlan 2 to 4
#配置默认路由
ip route-static 0.0.0.0 0.0.0.0 192.219.100.5
4. R1配置
sysname R1
interface GigabitEthernet0/0/0
ip address 192.219.100.2 255.255.255.252
interface GigabitEthernet0/0/1
ip address 192.219.100.5 255.255.255.252
interface LoopBack0
ip address 222.219.225.1 255.255.255.252
#配置静态路由和指定优先级为70
ip route-static 192.219.20.0 255.255.255.0 192.219.100.1
ip route-static 192.219.20.0 255.255.255.0 192.219.100.6 preference 70
ip route-static 192.219.30.0 255.255.255.0 192.219.100.1
ip route-static 192.219.40.0 255.255.255.0 192.219.100.6
ip route-static 192.219.40.0 255.255.255.0 192.219.100.1 preference 70
备注:本文部分内容来源于网络,如有侵权请联系本人。