1 理解 STP 工作原理
1.1 问题
如何选择根网桥、根端口、指定端口、被阻塞的端口?
1.2 方案
使用 eNSP 搭建实全环境,如图 - 1 所示。

图 - 1
1.3 步骤
实现此案例需要按照如下步骤进行。
1)选择根网桥
- 网桥 ID 最小
- 选择根端口 (非根网桥)
- 此端口到达根网桥路径成本最低
- 此端口直连网桥 ID 最小
3)选择指定端口 (每根网线)
- 根网桥上所有端口都是指定端口
- 此端口所在交换机到达根网桥成本最低
- 此端口所在的换机的网桥 ID 最小
2 配置 STP
2.1 问题
首先查看当前根网桥,然后通过修改交换机的优先级来分配根网桥。
2.2 方案
使用 eNSP 搭建实验环境,如图 - 2 所示。

图 - 2
2.3 步骤
实现此案例需要按照如下步骤进行。
1)配置 STP
1. \[SW1\]stp mode stp2. \[SW2\]stp mode stp3. \[SW3\]stp mode stp4. \[SW4\]stp mode stp
2)查看根网桥
1. \[SW1\]display stp2. -------\[CIST Global Info\]\[Mode STP\]-------3. CIST Bridge :32768.4c1f-cc59-0ca44. Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 205. Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 206. CIST Root/ERPC :32768.4c1f-cc16-2fc4 / 2000007. CIST RegRoot/IRPC :32768.4c1f-cc16-2fc4 / 08. CIST RootPortId :128.29. BPDU-Protection :Disabled10. TC or TCN received :10611. TC count per hello :012. STP Converge Mode :Normal13. Time since last TC :0 days 0h:9m:8s14. Number of TC :1215. Last TC occurred :Ethernet0/0/217. \[SW2\]display stp18. -------\[CIST Global Info\]\[Mode STP\]-------19. CIST Bridge :32768.4c1f-cc16-2fc420. Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 2021. Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 2022. CIST Root/ERPC :32768.4c1f-cc16-2fc4 / 023. CIST RegRoot/IRPC :32768.4c1f-cc16-2fc4 / 024. CIST RootPortId :0.025. BPDU-Protection :Disabled26. TC or TCN received :2327. TC count per hello :028. STP Converge Mode :Normal29. Time since last TC :0 days 0h:9m:52s30. Number of TC :1331. Last TC occurred :Ethernet0/0/433. \[SW3\]display stp34. -------\[CIST Global Info\]\[Mode STP\]-------35. CIST Bridge :32768.4c1f-cc6d-7de536. Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 2037. Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 2038. CIST Root/ERPC :32768.4c1f-cc16-2fc4 / 40000039. CIST RegRoot/IRPC :32768.4c1f-cc16-2fc4 / 040. CIST RootPortId :128.441. BPDU-Protection :Disabled42. TC or TCN received :9243. TC count per hello :044. STP Converge Mode :Normal45. Time since last TC :0 days 0h:10m:26s46. Number of TC :1147. Last TC occurred :Ethernet0/0/449. \[SW4\]display stp50. -------\[CIST Global Info\]\[Mode STP\]-------51. CIST Bridge :32768.4c1f-cc5f-35c852. Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 2053. Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 2054. CIST Root/ERPC :32768.4c1f-cc16-2fc4 / 20000055. CIST RegRoot/IRPC :32768.4c1f-cc16-2fc4 / 056. CIST RootPortId :128.257. BPDU-Protection :Disabled58. TC or TCN received :4959. TC count per hello :060. STP Converge Mode :Normal61. Time since last TC :0 days 0h:11m:12s62. Number of TC :1363. Last TC occurred :Ethernet0/0/2
可以看出,交换机 SW2 是根网桥。
3)配置交换机 SW3 为根网桥
1. \[SW3\]stp priority 03. \[SW3\]display stp4. -------\[CIST Global Info\]\[Mode STP\]-------5. CIST Bridge :0.4c1f-cc6d-7de56. Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 207. Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 208. CIST Root/ERPC :0.4c1f-cc6d-7de5 / 09. CIST RegRoot/IRPC :0.4c1f-cc6d-7de5 / 010. CIST RootPortId :0.011. BPDU-Protection :Disabled12. TC or TCN received :10813. TC count per hello :014. STP Converge Mode :Normal15. Time since last TC :0 days 0h:0m:14s16. Number of TC :1517. Last TC occurred :Ethernet0/0/3
此时,根网桥已经是交换机 SW3 了。
3 MSTP 配置实例
3.1 问题
1)PC1 属于 vlan 10,IP 地址为 192.168.10.1/24
2)PC2 属于 vlan 20,IP 地址为 192.168.20.1/24
3)配置 MSTP,实现 VLAN 10 的终端通信路径是:SW1-SW2
4)配置 MSTP,实现 VLAN 20 的终端通信路径是:SW3-SW4
3.2 方案
使用 eNSP 搭建实验环境,如图 - 3 所示。

图 - 3
3.3 步骤
实现此案例需要按照如下步骤进行。
1)配置 PC1/2/3/4 的 IP 地址
2)配置 SW1/2/3/4 的 VLAN 、Trunk、Access
1. <Huawei>undo terminal monitor2. <Huawei>system-view3. \[Huawei\]sysname SW14. \[SW1\]vlan batch 10 205. \[SW1\]interface gi0/0/126. \[SW1-GigabitEthernet0/0/12\]port link-type trunk7. \[SW1-GigabitEthernet0/0/12\]port trunk allow-pass vlan all8. \[SW1-GigabitEthernet0/0/12\]quit9. \[SW1\]interface gi0/0/1310. \[SW1-GigabitEthernet0/0/13\]port link-type trunk11. \[SW1-GigabitEthernet0/0/13\]port trunk allow-pass vlan all12. \[SW1-GigabitEthernet0/0/13\]quit13. \[SW1\]interface gi0/0/114. \[SW1-GigabitEthernet0/0/1\]port link-type access15. \[SW1-GigabitEthernet0/0/1\]port default vlan 1016. \[SW1-GigabitEthernet0/0/1\]quit18. <Huawei>undo terminal monitor19. <Huawei>system-view20. \[Huawei\]sysname SW221. \[SW2\]vlan batch 10 2022. \[SW2\]interface gi0/0/1223. \[SW2-GigabitEthernet0/0/12\]port link-type trunk24. \[SW2-GigabitEthernet0/0/12\]port trunk allow-pass vlan all25. \[SW2-GigabitEthernet0/0/12\]quit26. \[SW2\]interface gi0/0/1327. \[SW2-GigabitEthernet0/0/13\]port link-type trunk28. \[SW2-GigabitEthernet0/0/13\]port trunk allow-pass vlan all29. \[SW2-GigabitEthernet0/0/13\]quit30. \[SW2\]interface gi0/0/131. \[SW2-GigabitEthernet0/0/1\]port link-type access32. \[SW2-GigabitEthernet0/0/1\]port default vlan 1033. \[SW2-GigabitEthernet0/0/1\]quit35. <Huawei>undo terminal monitor36. <Huawei>system-view37. \[Huawei\]sysname SW338. \[SW3\]vlan batch 10 2039. \[SW3\]interface gi0/0/1240. \[SW3-GigabitEthernet0/0/12\]port link-type trunk41. \[SW3-GigabitEthernet0/0/12\]port trunk allow-pass vlan all42. \[SW3-GigabitEthernet0/0/12\]quit43. \[SW3\]interface gi0/0/1344. \[SW3-GigabitEthernet0/0/13\]port link-type trunk45. \[SW3-GigabitEthernet0/0/13\]port trunk allow-pass vlan all46. \[SW3-GigabitEthernet0/0/13\]quit47. \[SW3\]interface gi0/0/148. \[SW3-GigabitEthernet0/0/1\]port link-type access49. \[SW3-GigabitEthernet0/0/1\]port default vlan 2050. \[SW3-GigabitEthernet0/0/1\]quit52. <Huawei>undo terminal monitor53. <Huawei>system-view54. \[Huawei\]sysname SW455. \[SW4\]vlan batch 10 2056. \[SW4\]interface gi0/0/1257. \[SW4-GigabitEthernet0/0/12\]port link-type trunk58. \[SW4-GigabitEthernet0/0/12\]port trunk allow-pass vlan all59. \[SW4-GigabitEthernet0/0/12\]quit60. \[SW4\]interface gi0/0/1361. \[SW4-GigabitEthernet0/0/13\]port link-type trunk62. \[SW4-GigabitEthernet0/0/13\]port trunk allow-pass vlan all63. \[SW4-GigabitEthernet0/0/13\]quit64. \[SW4\]interface gi0/0/165. \[SW4-GigabitEthernet0/0/1\]port link-type access66. \[SW4-GigabitEthernet0/0/1\]port default vlan 2067. \[SW4-GigabitEthernet0/0/1\]quit
3)配置 MSTP(SW1/2/3/4 的基本 MSTP 配置,都相同)
1. \[sw1\]stp mode mstp2. \[sw1\]stp region-configuration3. \[sw1-mst-region\]region-name HCIE4. \[sw1-mst-region\]instance 1 vlan 105. \[sw1-mst-region\]instance 2 vlan 206. \[sw1-mst-region\]active region-configuration
4)配置 SW1 为 VLAN 10 的根交换机
1. \[sw1\]stp instance 1 priority 0
配置 SW3 为 VLAN 20 的根交换机
1. \[sw3\]stp instance 2 priority 0
4 MSTP 负载均衡
4.1 问题
1)PC1 属于 vlan 10 ,IP 地址为 192.168.10.1/24,网关为 192.168.10.254
2)PC2 属于 vlan 20 ,IP 地址为 192.168.20.1/24,网关为 192.168.20.254
3)确保 PC1 与 PC2 互通
4)合理配置 MSTP ,确保 PC1 与 PC2 之间的互通路径是最优的
4.2 方案
使用 eNSP 搭建实验环境,如图 - 4 所示。

图 - 4
4.3 步骤
实现此案例需要按照如下步骤进行。
1)配置 PC1/2 的 IP 地址
2)配置 SW1/2/3 的基本信息
- 创建 VLAN 10 和 20
- 配置交换机之间的链路为 Trunk,并允许 vlan 10 和 20
- 配置交换机与 PC / 路由器之间的链路为 Access,并加入到正确的 VLAN
3)配置 MSTP(SW1/2/3 的配置相同)
1. stp mode mstp2. stp region-configuration3. region-name HCIE4. instance 1 vlan 105. instance 2 vlan 206. active region-configuration7. quit
4)配置主根与次根
1. \[SW1\]stp instance 2 priority 40962. \[SW1\]stp instance 1 priority 81924. \[SW2\]stp instance 1 priority 40965. \[SW2\]stp instance 2 priority 8192
5)查看负载均衡
1. \[SW1\]display stp brief2. MSTID Port Role STP State Protection3. 1 Ethernet0/0/3 DESI FORWARDING NONE4. 1 Ethernet0/0/10 ROOT FORWARDING NONE5. 2 Ethernet0/0/1 DESI FORWARDING NONE6. 2 Ethernet0/0/3 DESI FORWARDING NONE7. 2 Ethernet0/0/10 DESI FORWARDING NONE9. \[SW2\]display stp brief10. MSTID Port Role STP State Protection11. 1 Ethernet0/0/2 DESI FORWARDING NONE12. 1 Ethernet0/0/4 DESI FORWARDING NONE13. 1 Ethernet0/0/10 DESI FORWARDING NONE14. 2 Ethernet0/0/4 DESI FORWARDING NONE15. 2 Ethernet0/0/10 ROOT FORWARDING NONE17. \[SW3\]display stp brief18. MSTID Port Role STP State Protection19. 1 Ethernet0/0/1 DESI FORWARDING NONE20. 1 Ethernet0/0/3 ALTE DISCARDING NONE21. 1 Ethernet0/0/4 ROOT FORWARDING NONE22. 2 Ethernet0/0/2 DESI FORWARDING NONE23. 2 Ethernet0/0/3 ROOT FORWARDING NONE24. 2 Ethernet0/0/4 ALTE DISCARDING NONE
https://tts.tmooc.cn/ttsPage/NTD/NTDTN202109/TCNA/DAY01/CASE/01/index.html
