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:邊緣端口行為
正常狀態:
[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為指定端口
模擬攻擊: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 保護? ?
- 模擬攻擊:通過工具(或頻繁插拔鏈路)向 LSW5 發送大量 TC BPDU。
- 查看狀態:
display stp tc-protection # 查看閾值配置 display stp statistics # 觀察TC報文計數,超過5后觸發抑制
- 攻擊停止后,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
?(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 brief 、display stp instance X brief |