STP实验
核心功能
- 防止环路
在复杂的网络拓扑(如冗余链路)中,STP 通过阻塞部分端口,消除物理环路带来的广播风暴。 - 自动冗余切换
当主链路故障时,STP 能快速激活备份链路,保障网络连通性。
关键概念
- Bridge ID:由优先级(默认32768)和 MAC 地址组成,用于选举根桥。
- 根桥(Root Bridge):网络中的逻辑中心,所有数据路径以此为中心展开。
- 路径开销(Path Cost):根据链路带宽计算,用于选择最优路径。
- BPDU(Bridge Protocol Data Unit):交换机之间发送的控制报文,用于协商拓扑信息。
工作流程
- 选举根桥:网络中 Bridge ID 最小的交换机成为根桥。
- 选举根端口(Root Port):每个非根桥选择到根桥开销最小的端口。
- 选举指定端口(Designated Port):每个网段选择到根桥开销最小的端口。
- 阻塞其他端口:非根端口和非指定端口被阻塞。
STP 变种
- RSTP(Rapid STP):快速生成树,收敛时间缩短至秒级(IEEE 802.1w)。
- MSTP(Multiple STP):多实例生成树,支持多个 VLAN 映射到不同生成树(IEEE 802.1s)。
实验拓扑
实验需求
- 开启所有设备,等待STP收敛后观察STP状态
- 使交换机SW4成为根网桥
- 使闭塞端口出现在交换机SW2上
- 把交换机SW1上连接的PC的端口配置为边缘端口
实验步骤
1.等待STP收敛后,查看STP运行状态,找出根网桥,闭塞端口
在SW1上,根据HCL模拟器的运行机制,SW1的Mac地址应该是最小的,会成为根网桥,在SW1上查看STP运行状态,确认SW1为根网桥
<H3C>system-view
System View: return to User View with Ctrl+Z.
[H3C]sysname SW1
[SW1]display stp
-------[CIST Global Info][Mode MSTP]-------Bridge ID : 32768.4cea-c0bf-0100Bridge times : Hello 2s MaxAge 20s FwdDelay 15s MaxHops 20Root ID/ERPC : 32768.4cea-c0bf-0100, 0RegRoot ID/IRPC : 32768.4cea-c0bf-0100, 0RootPort ID : 0.0BPDU-Protection : DisabledBPDU Filter : DisabledBridge Config-Digest-Snooping : DisabledTC or TCN received : 7Time since last TC : 0 days 0h:3m:52s
2.根据STP计算机制,所有链路开销一致,闭塞端口应该会出现在SW4上。在SW4上查看端口状态,确认SW4的g1/0/2被闭塞
在SW4上
<H3C>system-view
System View: return to User View with Ctrl+Z.
[H3C]sysname SW4
[SW4]display stp briefMST ID Port Role STP State Protection0 GigabitEthernet1/0/1 ROOT FORWARDING NONE0 GigabitEthernet1/0/2 ALTE DISCARDING NONE
[SW4]
3.使SW4成为新的根网桥
要想使SW4成为根网桥,最好的办法就是让SW4的优先级成为全网最小。默认优先级都为32768,只要把SW4的优先级改成比32768小的数值就可以了
在SW4上
[SW4]stp priority 4096
[SW4]%Mar 13 16:41:33:497 2025 SW4 STP/6/STP_DETECTED_TC: Instance 0's port GigabitEthernet1/0/2 detected a topology change.
4.在SW4上查看STP运行状态,发现SW4已经成为新的根网桥
在SW4上
[SW4]display stp
-------[CIST Global Info][Mode MSTP]-------Bridge ID : 4096.4cea-dcf0-0400Bridge times : Hello 2s MaxAge 20s FwdDelay 15s MaxHops 20Root ID/ERPC : 4096.4cea-dcf0-0400, 0 //成为新的根网桥RegRoot ID/IRPC : 4096.4cea-dcf0-0400, 0RootPort ID : 0.0BPDU-Protection : DisabledBPDU Filter : DisabledBridge Config-Digest-Snooping : DisabledTC or TCN received : 8Time since last TC : 0 days 0h:0m:53s
5.使闭塞端口出现在SW2上
SW4成为了根网桥,按照STP计算机制,此时闭塞端口应该在SW1上。如果要使闭塞端口到SW2上,就必须让SW2到SW1的cost比SW4到SW1更大。H3C交换机千兆口的cost默认是20,我们可以把SW2的g1/0/2接口的cost改为2000
在SW2上
<H3C>system-view
System View: return to User View with Ctrl+Z.
[H3C]sysname SW2
[SW2]int g1/0/2
[SW2-GigabitEthernet1/0/2]stp cost 2000
[SW2-GigabitEthernet1/0/2]%Mar 13 16:45:14:610 2025 SW2 STP/6/STP_NOTIFIED_TC: Instance 0's port GigabitEthernet1/0/1 was notified a topology change.
6.在SW2上查看STP接口状态,发现SW2的g1/0/2接口已经成为了新的闭塞端口
在SW2上
[SW2]display stp briefMST ID Port Role STP State Protection0 GigabitEthernet1/0/1 ROOT FORWARDING NONE0 GigabitEthernet1/0/2 ALTE DISCARDING NONE
[SW2]
7.把SW1连接PC的所有接口配置为边缘接口
在SW1上
[SW1]int g1/0/3
[SW1-GigabitEthernet1/0/3]stp edged-port
Edge 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]int g1/0/4
[SW1-GigabitEthernet1/0/4]stp edged-port
Edge 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]