当前位置: 首页 > news >正文

网络基础15-16:MSTP +VRRP综合实验

MSTP 、VRRP综合实验,MSTP涵盖根桥选举、边缘端口、BPDU 保护、根保护、TC 保护 等功能验证。

一、实验拓扑与设备规划

  • 核心层:LSW1(VLAN10 根桥、VLAN20 备份根)、LSW2(VLAN20 根桥、VLAN10 备份根)。
  • 接入层:LSW3(连 PC1、PC2)、LSW4(连 PC3、PC4)、LSW5(连 PC5、PC6)。
  • 测试设备:LSW6(测试 BPDU 保护)、LSW7(测试根保护)、LSW5开启TC保护。

二、基础网络配置(VLAN、接口模式)

1. 核心交换机(LSW1、LSW2)
# LSW1配置 (LSW2的优先级改变)
system-view
vlan batch 10 20
port-group group-member GigabitEthernet 0/0/1 to GigabitEthernet 0/0/4  #简写p g g0/0/1 to g0/0/4
port link-type trunk
port trunk allow-pass vlan all

2. 接入交换机(LSW3、LSW4、LSW5)
# LSW3配置(连PC1、PC2;PC1→VLAN10,PC2→VLAN20)
system-view
vlan batch 10 20
interface Ethernet 0/0/3  
port link-type access
port default vlan 10
interface Ethernet 0/0/4
port link-type access
port default vlan 10
quit
port-group group-member Ethernet 0/0/1 Ethernet 0/0/2    #简写p g e0/0/1 e0/0/2
port link-type trunk
port trunk allow-pass vlan all

三、MSTP 核心配置(多实例与根桥选举)

1. 核心交换机(LSW1、LSW2)
# LSW1:Instance10(VLAN10)根桥,Instance20(VLAN20)备份根
stp enable
stp mode mstp
stp region-configurationregion-name A        # 区域名统一为Aregion-level 2       # 区域级别2instance 10 vlan 10  # 实例10映射VLAN10instance 20 vlan 20  # 实例20映射VLAN20active region-configuration  # 激活配置
quit
stp instance 10 priority 4096  # 实例10优先级(最小,成为根)
stp instance 20 priority 8192  # 实例20优先级(大于LSW2的4096,成为备份)
stp instance 0 priority 4096   # 实例0(默认)优先级,成为根# LSW2:Instance20(VLAN20)根桥,Instance10(VLAN10)备份根
stp enable
stp mode mstp
stp region-configurationregion-name Aregion-level 2instance 10 vlan 10instance 20 vlan 20active region-configuration
quit
stp instance 10 priority 8192  # 实例10备份根
stp instance 20 priority 4096  # 实例20根桥
stp instance 0 priority 8192   # 实例0备份根
2. 接入交换机(LSW3、LSW4、LSW5)
stp enable
stp mode mstp
stp region-configurationregion-name Aregion-level 2instance 10 vlan 10instance 20 vlan 20active region-configuration
quit
# 实例优先级默认,由核心自动选举根桥
验证 1:根桥与链路状态
  • 在 LSW3 上执行:display stp brief
    MSTID  Port                        Role  STP State     Protection0    Ethernet0/0/1               ROOT  FORWARDING      NONE  # 确认Instance0根桥为LSW10    Ethernet0/0/2               ALTE  DISCARDING      NONE0    Ethernet0/0/3               DESI  FORWARDING      BPDU0    Ethernet0/0/4               DESI  FORWARDING      BPDU10    Ethernet0/0/1               ROOT  FORWARDING      NONE  # 确认Instance10根桥为LSW10    Ethernet0/0/2               ALTE  DISCARDING      NONE10    Ethernet0/0/3               DESI  FORWARDING      BPDU20    Ethernet0/0/1               ALTE  DISCARDING      NONE20    Ethernet0/0/2               ROOT  FORWARDING      NONE  # 确认Instance10根桥为LSW20    Ethernet0/0/4               DESI  FORWARDING      BPDU
  • 观察核心间链路(如 GE0/0/1、GE0/0/4)在不同实例中 阻塞 / 转发,实现负载均衡。

四、边缘端口与 BPDU 保护(LSW3)

  配置
# LSW3:将PC连接端口标记为边缘端口,启用BPDU保护
port-group group-member Ethernet 0/0/3 Ethernet 0/0/4  # 假设这两个端口连PCstp edged-port enable  # 边缘端口:跳过STP协商,直接转发
quit
stp bpdu-protection  # 启用BPDU保护:边缘端口收BPDU则关闭
   验证 2:边缘端口行为
  1. 正常状态

    [Huawei]display stp brief  MSTID  Port                        Role  STP State     Protection0    Ethernet0/0/1               ROOT  FORWARDING      NONE0    Ethernet0/0/2               ALTE  DISCARDING      NONE0    Ethernet0/0/3               DESI  FORWARDING      BPDU0    Ethernet0/0/4               DESI  FORWARDING      BPDU10    Ethernet0/0/1               ROOT  FORWARDING      NONE10    Ethernet0/0/2               ALTE  DISCARDING      NONE10    Ethernet0/0/3               DESI  FORWARDING      BPDU   #e0/0/3为指定端口20    Ethernet0/0/1               ALTE  DISCARDING      NONE20    Ethernet0/0/2               ROOT  FORWARDING      NONE20    Ethernet0/0/4               DESI  FORWARDING      BPDU   #e0/0/4为指定端口
    
  2. 模拟攻击LSW6 连 LSW3 的 E0/0/3

            连接后,LSW3 的 E0/0/3 因收 BPDU 触发保护:Ethernet0/0/3 接口消失了(关闭了)

[Huawei]display stp briefMSTID  Port                        Role  STP State     Protection0    Ethernet0/0/1               ROOT  FORWARDING      NONE0    Ethernet0/0/2               ALTE  DISCARDING      NONE0    Ethernet0/0/4               DESI  FORWARDING      BPDU10    Ethernet0/0/1               ROOT  FORWARDING      NONE10    Ethernet0/0/2               ALTE  DISCARDING      NONE20    Ethernet0/0/1               ALTE  DISCARDING      NONE20    Ethernet0/0/2               ROOT  FORWARDING      NONE20    Ethernet0/0/4               DESI  FORWARDING      BPDU

        恢复

interface Ethernet 0/0/3undo stp bpdu-protection  

五、根保护(LSW4 的 E0/0/3 接口,连 LSW7)

# LSW4:对连接下游的端口启用根保护
interface Ethernet 0/0/3stp root-protection  # 防止下游设备抢占根桥
quit# LSW7:模拟恶意根桥(优先级更低,试图抢占)
system-view
stp enable
stp mode mstp
stp instance 10 priority 0  # 优先级0(比LSW1的4096小)
验证 3:根保护生效

       连接 LSW7 与 LSW4 的 E0/0/3 后,在 LSW4 上执行:

<Huawei>display stp briefMSTID  Port                        Role  STP State     Protection0    Ethernet0/0/1               ROOT  FORWARDING      NONE0    Ethernet0/0/2               ALTE  DISCARDING      NONE0    Ethernet0/0/3               DESI  DISCARDING      ROOT0    Ethernet0/0/4               DESI  FORWARDING      NONE10    Ethernet0/0/1               ROOT  FORWARDING      NONE  # 根桥仍为LSW1(未被抢占)10    Ethernet0/0/2               ALTE  DISCARDING      NONE10    Ethernet0/0/3               DESI  DISCARDING      ROOT # Ethernet0/0/3状态变为DISCARDING(拒绝更优BPDU)20    Ethernet0/0/1               ALTE  DISCARDING      NONE20    Ethernet0/0/2               ROOT  FORWARDING      NONE20    Ethernet0/0/4               DESI  FORWARDING      NONE

       恢复:移除 LSW7,E0/0/3 自动恢复 FORWARDING。

六、TC 保护(LSW5)

配置
# LSW5:限制TC报文频率,防止MAC表频繁刷新
stp tc-protection threshold 5  # TC报文阈值设为5,超过后抑制
验证 4:TC 保护   
  1. 模拟攻击:通过工具(或频繁插拔链路)向 LSW5 发送大量 TC BPDU。
  2. 查看状态
    display stp tc-protection  # 查看阈值配置
    display stp statistics     # 观察TC报文计数,超过5后触发抑制
    
  3. 攻击停止后,TC 计数回落,保护自动解除。

七、VRRP 配置

  1.、VRRP 设计逻辑

  • VLAN10:LSW1 作为 MSTP 根桥,同时担任 VRRP 主网关(优先级 110),LSW2 为备用。
  • VLAN20:LSW2 作为 MSTP 根桥,同时担任 VRRP 主网关(优先级 110),LSW1 为备用。
  • 虚拟 IP:192.168.10.1(VLAN10)、192.168.20.1(VLAN20),与主机网关一致。

  2.、LSW1(核心交换机 1)配置

system-view
sysname LSW1# ========== 先完成MSTP配置(参考之前“三”) ========== ## ---------- VLAN10 三层接口(主网关) ---------- #
interface Vlanif10ip address 192.168.10.4 255.255.255.0  # 物理IP(唯一,与LSW2的192.168.10.5区分)vrrp vrid 10 virtual-ip 192.168.10.1    # 虚拟IP,主机默认网关vrrp vrid 10 priority 110               # 优先级高于备用(默认100),成为主网关vrrp vrid 10 preempt-mode               # 默认开启抢占,恢复后夺回主角色
quit# ---------- VLAN20 三层接口(备网关) ---------- #
interface Vlanif20ip address 192.168.20.4 255.255.255.0  # 物理IPvrrp vrid 20 virtual-ip 192.168.20.1    # 虚拟IP# 优先级默认100,LSW2的VLAN20优先级110,故此处为备用
quit

3、LSW2(核心交换机 2)配置

system-view
sysname LSW2# ========== 先完成MSTP配置(参考之前“三”) ========== ## ---------- VLAN10 三层接口(备网关) ---------- #
interface Vlanif10ip address 192.168.10.5 255.255.255.0  # 物理IPvrrp vrid 10 virtual-ip 192.168.10.1    # 与LSW1一致的虚拟IP# 优先级默认100,LSW1的VLAN10优先级110,故此处为备用
quit# ---------- VLAN20 三层接口(主网关) ---------- #
interface Vlanif20ip address 192.168.20.5 255.255.255.0  # 物理IPvrrp vrid 20 virtual-ip 192.168.20.1    # 虚拟IPvrrp vrid 20 priority 110               # 优先级高于备用(LSW1的100),成为主网关vrrp vrid 20 preempt-mode               # 开启抢占
quit

4、关键验证步骤

(1)查看 VRRP 状态
  • LSW1 上

    # Vlanif10 → VRID 10 → Master(优先级110)
    # Vlanif20 → VRID 20 → Backup(优先级100)[Huawei-Vlanif10]display vrrp brief
    VRID  State        Interface                Type     Virtual IP     
    ----------------------------------------------------------------
    10    Master       Vlanif10                 Normal   192.168.10.1   
    20    Backup       Vlanif20                 Normal   192.168.20.1   
    ----------------------------------------------------------------
    Total:2     Master:1     Backup:1     Non-active:0     
    
  • LSW2 上

    # Vlanif10 → VRID 10 → Backup(优先级100)
    # Vlanif20 → VRID 20 → Master(优先级110)[Huawei]dis vrrp brief
    VRID  State        Interface                Type     Virtual IP     
    ----------------------------------------------------------------
    10    Backup       Vlanif10                 Normal   192.168.10.1   
    20    Master       Vlanif20                 Normal   192.168.20.1   
    ----------------------------------------------------------------
    Total:2     Master:1     Backup:1     Non-active:0     
    
(2)故障切换测试
  • 模拟 LSW1 故障(断开 g0/0/1接口)

    LSW1: 
    int vlan 10
    [Huawei-Vlanif10]vrrp vrid 10 track interface g0/0/1 reduced 11  #track interface 多接口跟踪, reduced 11 断开优先级减11
    [Huawei-Vlanif10]quit
    [Huawei]int g0/0/1
    [Huawei-GigabitEthernet0/0/1]shutdown  
  •  验证
LSW1: 
<Huawei>display vrrp brief
VRID  State        Interface                Type     Virtual IP     
----------------------------------------------------------------
10    Backup       Vlanif10                 Normal   192.168.10.1   
20    Backup       Vlanif20                 Normal   192.168.20.1   
----------------------------------------------------------------
Total:2     Master:0     Backup:2     Non-active:0     LSW2: 
<Huawei>display vrrp brief
VRID  State        Interface                Type     Virtual IP     
----------------------------------------------------------------
10    Master       Vlanif10                 Normal   192.168.10.1   
20    Master       Vlanif20                 Normal   192.168.20.1   
----------------------------------------------------------------
Total:2     Master:2     Backup:0     Non-active:0     

        reduced 值的选择:需确保 优先级 - reduced 后 低于 Backup 设备,否则无法触发切换。在 LSW2 上观察:Vlanif10 的 VRRP 状态切换为 Master,PC1(VLAN10)仍可 ping 通 192.168.10.1

          抢占模式:若不希望频繁抢占(如避免流量瞬断),可配置 vrrp vrid 10 preempt-mode timer delay 5(延迟 5 秒抢占)。

  • 恢复 LSW1

    LSW1: interface Vlanif10undo shutdown
    
    LSW1 的 Vlanif10 因 抢占模式 重新成为 Master,业务无中断。
 (3)联动 MSTP 验证
  • 断开 LSW1 与 LSW2 的物理链路(如 GE0/0/1),MSTP 会重新计算拓扑,阻塞备用链路;
  • 同时 VRRP 会根据 接口状态 或 BFD 联动(若配置)快速切换,确保网关冗余与二层拓扑一致。

5、扩展优化(可选)

  (1)BFD 与 VRRP 联动

为加速故障检测(默认 VRRP 心跳 2 秒,可通过 BFD 压缩到毫秒级):

# LSW1 Vlanif10示例:
interface Vlanif10vrrp vrid 10 bfd enable  # 启用BFD联动vrrp vrid 10 bfd session-name lsw1-lsw2  # BFD会话名
quit# LSW2 对称配置,实现双向检测
(2) _track 接口状态

监控物理链路状态,链路故障时自动降低 VRRP 优先级:

# LSW1 Vlanif10:若GE0/0/2(连LSW3)故障,VRRP优先级降为90
interface Vlanif10vrrp vrid 10 track interface GigabitEthernet 0/0/2 reduced 20  # 优先级减20
quit

核心价值

  • MSTP+VRRP 联动:二层根桥与三层网关角色对齐,减少跨设备转发,提升效率。
  • 双活冗余:VLAN10 和 VLAN20 的主网关分别由 LSW1、LSW2 承担,实现负载均衡。
  • 快速收敛:通过 BFD 或 Track 机制,故障切换时间压缩至百毫秒级,保障业务连续性。

以上配置完整覆盖 二层冗余(MSTP)+ 三层冗余(VRRP),适配园区网核心层高可用设计。


 

关键命令速查

功能命令示例
MSTP 区域配置stp region-configuration
实例映射instance 10 vlan 10
根桥优先级stp instance 10 priority 4096
边缘端口stp edged-port enable
BPDU 保护stp bpdu-protection
根保护stp root-protection(接口下)
TC 保护stp tc-protection threshold 5
状态验证display stp briefdisplay stp instance X brief
http://www.dtcms.com/a/292516.html

相关文章:

  • 单张显卡运行多个vllm模型
  • 零基础数据结构与算法——第五章:高级算法-回溯算法子集全排列问题
  • ZooKeeper学习专栏(六):集群模式部署与解析
  • C++ new 创建数组的内在原理详解
  • linux 环境服务发生文件句柄泄漏导致服务不可用
  • ELF 文件操作手册
  • python学习-读取csv文件
  • 如何验证分类模型输出概率P值的“好坏”:评估与校准示例
  • GitHub 上的开源项目 ticktick(滴答清单)
  • recvmsg函数的用法
  • 算法学习--滑动窗口
  • 学习python中离线安装pip及下载package的方法
  • C语言:函数基础
  • day059-zabbix自定义监控与自动发现
  • Node.js:Web模块、Express框架
  • es6中的symbol基础知识
  • 在Android开发中,如何获取到手机设备的PIN码?
  • 如何安装CMake较新的版本
  • Apache Ignite 长事务终止机制
  • 精密全波整流电路(一)
  • torchvision.transforms 与 MONAI 数据增强的异同
  • Cloud 与 VPS 的区别:如何选择最适合你的服务器解决方案?
  • stream流入门
  • 【打怪升级 - 01】保姆级机器视觉入门指南:硬件选型 + CUDA/cuDNN/Miniconda/PyTorch 安装全流程(附版本匹配秘籍)
  • vmware 克隆虚拟机,报错:克隆时出错:指定不存在的设备。然后电脑卡死,只能强制关机再开机。
  • FastDFS 6.11.0 单机环境搭建与测试(附 Nginx 集成)+ docker构建+k8s启动文件
  • 用org.apache.pdfbox 转换 PDF 到 图片格式
  • KafkaMQ 日志采集最佳实践
  • Python 正则表达式:入门到实战
  • 日常随笔-React摘要