STP生成树协议实验
STP生成树协议实验
实验拓扑

实验需求
- 开启所有设备,等待 STP 收敛后观察 STP 状态
- 使 SW4 成为根网桥
- 使闭塞端口出现在 SW2 上
- 把 SW1 上连接的 PC 的端口配置为边缘端口
配置步骤
1. 等待 STP 收敛后,查看 STP 运行状态,找出根网桥与闭塞端口
分析:根据 HCL 模拟器的运行机制,SW1 的 MAC 地址最小,会成为根网桥。
步骤1:在 SW1 上查看 STP 运行状态,确认 SW1 为根网桥。
[SW1]dis stp-------[CIST Global Info][Mode MSTP]------- Bridge ID : 32768.908d-e11e-0100 Bridge times : Hello 2s MaxAge 20s FwdDelay 15s MaxHops 20 Root ID/ERPC : 32768.908d-e11e-0100, 0 RegRoot ID/IRPC : 32768.908d-e11e-0100, 0 RootPort ID : 0.0 BPDU-Protection : Disabled Bridge Config- Digest-Snooping : Disabled TC or TCN received : 7 Time since last TC : 0 days 0h:6m:12s步骤2:根据 STP 计算机制,所有链路开销一致时,闭塞端口应出现在 SW4 上。在 SW4 上查看端口状态,确认 SW4 的 g1/0/2 被阻塞。
[SW4]dis stp brief MST ID Port Role STP State Protection 0 GigabitEthernet1/0/1 ROOT FORWARDING NONE 0 GigabitEthernet1/0/2 ALTE DISCARDING NONE2. 使 SW4 成为新的根网桥
分析:要使 SW4 成为根网桥,需将其优先级改为全网最小。默认优先级均为 32768,将 SW4 的优先级改为 4096 即可。
步骤1:修改 SW4 的优先级为 4096。
[SW4]stp priority 4096[SW4]%Aug 26 16:33:54:232 2026 SW4 STP/6/STP_DETECTED_TC: Instance 0's port GigabitEthernet1/0/2 detected a topology change.步骤2:在 SW4 上查看 STP 运行状态,确认 SW4 已成为新的根网桥。
[SW4]display stp-------[CIST Global Info][Mode MSTP]------- Bridge ID : 4096.908d-ea02-0400 Bridge times : Hello 2s MaxAge 20s FwdDelay 15s MaxHops 20 Root ID/ERPC : 4096.908d-ea02-0400, 0 RegRoot ID/IRPC : 4096.908d-ea02-0400, 0 RootPort ID : 0.0 BPDU-Protection : Disabled Bridge Config- Digest-Snooping : Disabled TC or TCN received : 6 Time since last TC : 0 days 0h:0m:32s3. 使闭塞端口出现在 SW2 上
分析:SW4 成为根网桥后,按照 STP 计算机制,闭塞端口此时应在 SW1 上。要使闭塞端口转移到 SW2 上,需让 SW2 到 SW1 的路径开销 大于 SW4 到 SW1 的路径开销。H3C 交换机千兆口的默认开销为 20,可将 SW2 的 g1/0/2 接口开销改为 1000。
步骤1:在 SW2 上进入 g1/0/2 接口视图,修改 STP Cost 为 1000。
[SW2]interface g1/0/2[SW2-GigabitEthernet1/0/2]stp cost 1000[SW2-GigabitEthernet1/0/2]%Aug 26 16:38:27:908 2026 SW2 STP/6/STP_NOTIFIED_TC: Instance 0's port GigabitEthernet1/0/1 was notified a topology change.步骤2:在 SW2 上查看 STP 接口状态,确认 g1/0/2 已成为新的阻塞端口。
[SW2-GigabitEthernet1/0/2]display stp brief MST ID Port Role STP State Protection 0 GigabitEthernet1/0/1 ROOT FORWARDING NONE 0 GigabitEthernet1/0/2 ALTE DISCARDING NONE4. 把 SW1 连接 PC 的所有接口配置为边缘端口
分析:连接终端的端口应配置为边缘端口,以加快收敛速度并避免不必要的拓扑变化通知。
步骤1:在 SW1 上进入连接 PC 的接口(g1/0/3 和 g1/0/4),配置为边缘端口。
[SW1]interface g1/0/3[SW1-GigabitEthernet1/0/3]stp edged-portEdge port should only be connected to terminal. It will cause temporary loops if port GigabitEthernet1/0/3 is connected to bridges. Please use it carefully.[SW1-GigabitEthernet1/0/3]interface g1/0/4[SW1-GigabitEthernet1/0/4]stp edged-portEdge port should only be connected to terminal. It will cause temporary loops if port GigabitEthernet1/0/4 is connected to bridges. Please use it carefully.[SW1-GigabitEthernet1/0/4]

