0. 课件来源
课件最后指出本周作业是 "mstp-eth-trunk-vrrp 综合作业"。本节将 MSTP、Eth-Trunk、VRRP 三大特性整合到一个真实场景中,搭建具备 防环、冗余、快速切换、最优路径、负载分担 五大特性的企业网典型架构。
1. 综合场景拓扑
┌──────────── CORE ────────────┐
│ SW1 SW2 │
VLAN10 │ vlanif10 vlanif10 │ VLAN20
.254 │ VRRP10-M VRRP10-B │ .253
│ VRRP20-B VRRP20-M │
│ │
│ └─── Eth-Trunk1 ───┘ │
│ (g0/0/23+g0/0/24 LACP) │
└────────────────────────────────┘
│ │
vlan10/20 trunk vlan10/20 trunk
│ │
┌──────── SW3 ──────── 接入 ──────┐
│ PC1(vlan10) PC2(vlan20) │
└──────────────────────────────────┘| 设备 | 角色 | 关键配置 |
|---|---|---|
| SW1 | 核心(主 VLAN10 网关) | MSTP 根 + VRRP10 Master + VRRP20 Backup |
| SW2 | 核心(主 VLAN20 网关) | MSTP 备根 + VRRP10 Backup + VRRP20 Master |
| SW3 | 接入 | 连接 PC1 (VLAN10), PC2 (VLAN20) |
2. 综合需求与方案对照
| 需求 | STP 怎么解决 | 链路层怎么解决 | 网关层怎么解决 |
|---|---|---|---|
| 防环 | MSTP 每个实例一棵树 | Eth-Trunk 内部防环 | — |
| 冗余备份 | AP 端口备份 | 物理链路备份 | VRRP Backup |
| 快速切换 | RSTP P/A 秒切 | 物理链路 down 立即切换成员 | VRRP skew-time/MDI |
| 最优路径 | 不同 Instance 选不同根 | — | VRRP 不同组 Master 不同设备 |
| 负载分担 | 不同 VLAN 走不同实例 | 多物理链路同时转发 | 一组主走 SW1,另一组主走 SW2 |
3. 配置步骤分解
3.1 Step 1 — MSTP 配置(防环 + 负载)
# SW1(主根 Instance 10,备根 Instance 20)
stp mode mstp
stp region-configuration
region-name HCIP
instance 10 vlan 10
instance 20 vlan 20
active region-configuration
stp instance 10 root primary
stp instance 20 root secondary
# SW2(备根 Instance 10,主根 Instance 20)
stp mode mstp
stp region-configuration
region-name HCIP
instance 10 vlan 10
instance 20 vlan 20
active region-configuration
stp instance 10 root secondary
stp instance 20 root primary
# SW3
stp mode mstp
stp region-configuration
region-name HCIP
instance 10 vlan 10
instance 20 vlan 20
active region-configuration
# SW3 不需要配 root,自动参与选举⚠️ 同域 3 要素
三台交换机必须 region-name、revision、VLAN-Instance 映射表完全一致 才能属于同一 MST 域,否则 MSTP 负载分担失效。
3.2 Step 2 — Eth-Trunk 配置(SW1 ↔ SW2)
# SW1 和 SW2 都需要
# 先初始化物理接口
clear configuration interface g0/0/23 y
clear configuration interface g0/0/24 y
# 创建 Eth-Trunk 1(LACP 静态)
interface eth-trunk 1
mode lacp-static
port link-type trunk
port trunk allow-pass vlan 10 20
# 加入成员口
interface g0/0/23
eth-trunk 1
interface g0/0/24
eth-trunk 1
# 在希望成为 Master 的设备上调整 System Priority
lacp system-priority 100 # SW1 配置(默认 SW1 成为主)💡 为什么要配 Eth-Trunk
没有 Eth-Trunk 时 SW1↔SW2 之间两根链路在 STP 看来是 两条链路,一条 forward 一条 block,浪费带宽。聚合后视为一条逻辑链路,两条物理链路同时转发,带宽是 2G。
3.3 Step 3 — 三层互联接口放行 VLAN
# SW1
vlan 10
vlan 20
interface eth-trunk 1
port link-type trunk
port trunk allow-pass vlan 10 20
interface g0/0/21 # 与 SW3 互联的接口
port link-type trunk
port trunk allow-pass vlan 10 20
# SW2
interface eth-trunk 1
port link-type trunk
port trunk allow-pass vlan 10 20
interface g0/0/21 # 与 SW3 互联
port link-type trunk
port trunk allow-pass vlan 10 20
# SW3
interface g0/0/1 # 上联 SW1
port link-type trunk
port trunk allow-pass vlan 10 20
interface g0/0/2 # 上联 SW2
port link-type trunk
port trunk allow-pass vlan 10 203.4 Step 4 — VRRP 配置(网关冗余 + 负载分担)
# SW1
interface vlanif10
ip address 192.168.1.254 24
vrrp vrid 10 virtual-ip 192.168.1.254 # VIP=物理IP → Owner → priority=255(Master)
vrrp vrid 10 authentication-mode md5 huahua123
interface vlanif20
ip address 192.168.2.254 24
vrrp vrid 20 virtual-ip 192.168.2.253 # VIP=SW2 物理IP → 不是 Owner → Backup
vrrp vrid 20 authentication-mode md5 huahua123
# SW2
interface vlanif10
ip address 192.168.1.253 24
vrrp vrid 10 virtual-ip 192.168.1.254 # 不是 Owner → Backup
vrrp vrid 10 authentication-mode md5 huahua123
interface vlanif20
ip address 192.168.2.253 24
vrrp vrid 20 virtual-ip 192.168.2.253 # VIP=物理IP → Owner → Master
vrrp vrid 20 authentication-mode md5 huahua123💡 为什么这里用 VIP = 物理接口 IP
这样做让两台交换机各自在一个 VRID 上成为 Owner(priority=255 自动 Master),无需协商即可转发:
- VLAN10 → SW1 是 Master(VRID 10),流量优先走 SW1
- VLAN20 → SW2 是 Master(VRID 20),流量优先走 SW2
VRRP 负载分担 + MSTP 负载分担 方向一致 → VLAN10 走 SW1 时 STP 选路也走 SW1 Side → 实现真正的最优路径。
3.5 Step 5 — VRRP Track 监控上游
# SW1
interface vlanif10
vrrp vrid 10 track interface g0/0/24 # 假设 g0/0/24 是 SW1 上联外网接口
# 若 SW1 上游 down,priority -10 → 从 255 变 245 → SW2 Owner 仍然是 255 → SW2 接管
# 实际上由于这里 SW2 是 VLAN10 的 Backup,priority 默认 100;
# SW1 Owner 是 255,即使 -10 也有 245 仍 > 100,不会切换。
# 若要 Owner 故障时切换,需配更大的 reduced:
vrrp vrid 10 track interface g0/0/24 reduced 200
# 此时 SW1 上游 down → priority 255-200=55 → SW2 (100) > 55 → SW2 接管⚠️ Owner 场景的 Track 坑
VIP=物理 IP 时 Owner priority 自动 255。若 Track 减 10 变 245,仍然比 Backup 默认 100 高,不会切换。需将 reduced 调到使 priority < Backup 的值(如 200)。
3.6 Step 6 — STP 防护(可选但推荐)
# 终端接口配 EP + BPDU 保护
interface g0/0/10 # SW3 连接 PC 接口
stp edged-port enable
# 全局开启 BPDU 保护
stp bpdu-protection
error-down auto-recovery cause bpdu-protection interval 30
# SW1 / SW2 互联接口配根保护
interface eth-trunk 1 # 是 DP(根上端口)方向
stp root-protection4. 验证与观察
4.1 STP 状态
[SW1] dis stp brief
MSTID Port Role STP State
0 Eth-Trunk1 DESI FORWARDING # SW1 是 Instance10 根,Eth-Trunk 为 DP
10 Eth-Trunk1 DESI FORWARDING # Instance10 → SW1 根 → 全 DP
20 Eth-Trunk1 ROOT FORWARDING # Instance20 → SW2 根 → SW1 上是 RP[SW3] dis stp brief
MSTID Port Role STP State
10 GigabitEthernet0/0/1 ROOT FORWARDING # VLAN10 → 走 SW1
20 GigabitEthernet0/0/2 ROOT FORWARDING # VLAN20 → 走 SW24.2 VRRP 状态
[SW1] dis vrrp brief
VRID State Interface Type Virtual IP
10 Master Vlanif10 Normal 192.168.1.254
20 Backup Vlanif20 Normal 192.168.2.253[SW2] dis vrrp brief
VRID State Interface Type Virtual IP
10 Backup Vlanif10 Normal 192.168.1.254
20 Master Vlanif20 Normal 192.168.2.2534.3 PC 配置与连通性
| PC | 所属 VLAN | IP | 网关(VIP) |
|---|---|---|---|
| PC1 | 10 | 192.168.1.1/24 | 192.168.1.254 |
| PC2 | 20 | 192.168.2.1/24 | 192.168.2.253 |
PC1> ping 192.168.1.254 # 通 → SW1 是 Master
PC2> ping 192.168.2.253 # 通 → SW2 是 Master
# 模拟 SW1 上游故障
[SW1] interface g0/0/24
[SW1-G0/0/24] shutdown
# 观察
[SW1] dis vrrp brief # VRID10 -> Backup(减 200 回到 55)
[SW2] dis vrrp brief # VRID10 -> Master(100 > 55 接管)
PC1> ping 192.168.1.254 # 仍通,但走 SW2 转发5. 故障切换时间分析
| 故障类型 | 切换速度 | 机制 |
|---|---|---|
| SW1↔SW2 单根物理链路 | 0 秒(秒切) | Eth-Trunk 成员自动切换 |
| SW1 上游接口 down | skew-time | VRRP Track + priority 减 |
| SW1 整机 down | MDI (3.6 秒) | VRRP Backup 等待 MDI 超时切换 |
| SW3 上联 SW1 链路 down | 0 秒 | RSTP P/A → SW3 AP 转 RP |
| 私接交换机 | 立即 Shutdown | BPDU 保护 |
| 双点双向故障 | 30 秒 | STP 重新选举 |
6. 综合命令清单
# ── SW1 ──
# MSTP
stp mode mstp
stp region-configuration
region-name HCIP
instance 10 vlan 10
instance 20 vlan 20
active region-configuration
stp instance 10 root primary
stp instance 20 root secondary
# STP 防护
stp bpdu-protection
error-down auto-recovery cause bpdu-protection interval 30
# Eth-Trunk
clear configuration interface g0/0/23 y
clear configuration interface g0/0/24 y
interface eth-trunk 1
mode lacp-static
port link-type trunk
port trunk allow-pass vlan 10 20
interface g0/0/23
eth-trunk 1
interface g0/0/24
eth-trunk 1
lacp system-priority 100
# 互联接口
interface g0/0/21
port link-type trunk
port trunk allow-pass vlan 10 20
# VRRP
interface vlanif10
ip address 192.168.1.254 24
vrrp vrid 10 virtual-ip 192.168.1.254
vrrp vrid 10 authentication-mode md5 huahua123
vrrp vrid 10 track interface g0/0/24 reduced 200
interface vlanif20
ip address 192.168.2.254 24
vrrp vrid 20 virtual-ip 192.168.2.253
vrrp vrid 20 authentication-mode md5 huahua1237. 易混淆点与考前速记
| 对比项 | 结论 |
|---|---|
| 三大特性各自职责 | MSTP→防环负载,Eth-Trunk→带宽冗余,VRRP→网关冗余 |
| 方向一致性 | VLAN10 走 SW1 时 STP、VRRP 都应首选 SW1 → 综合设计中必须让 MSTP 根和 VRRP Master 保持一致 |
| Owner 的 Track 坑 | Owner priority=255,Track 减 10 没用,需减到大于 Backup 的值(如 reduced 200) |
| MSTP 同域 3 要素 | region-name + revision + VLAN-Instance 映射完全一致 |
| Eth-Trunk 默认 Hybrid | 若承载多 VLAN 必须改 Trunk,否则 STP 只在 Instance 0 看到 |
| LACP System Priority 双端配 | 只在希望成为 Master 的一端配更小值 |
| LACP 抢占延时默认 | 30 秒,防端口抖动频繁切换 |
考前速记 8 条:
三大特性职责:MSTP 防环、Eth-Trunk 带宽冗余、VRRP 网关冗余MSTP 不同 Instance 不同根 → VLAN10/20 走不同路径 → 负载分担MSTP 同域 3 要素:region-name + revision + VLAN 映射Eth-Trunk 必须配 Trunk 承载多 VLAN,默认 Hybrid 会让 STP 只在 Instance 0 看到LACP 主动端:System Priority 小(默认32768),再比 System MACLACP 抢占延时默认 30 秒,防端口抖动频繁切换VRRP 方向与 MSTP 方向需保持一致:VLAN10 STP 根在 SW1,VRRP10 Master 也在 SW1VIP=物理IP → 自动 Owner,priority=255;Track 对 Owner 需 reduced 足够大才切换
🤖 AI 伴学
综合作业看起来复杂,其实只是三大特性的"乐高拼装"。可以让 AI 用一张图让你理解它们如何协作:
"请用乐高积木的思路,把 MSTP、Eth-Trunk、VRRP 解释为三块不同形状的积木,分别承担"防止环路、增加带宽、网关冗余"的功能,最后拼装到一张'两大核心交换机连接接入交换机并带两个 VLAN 用户'的拓扑里,用一句话点出三大特性必须'方向一致'(VLAN 10 一切都优先走 SW1)才能避免次优路径。"
