1. 进入全局配置模式:
```
Switch> enable
Switch configure terminal
```
```
Switch(config) spanning-tree vlan 1
```
思科交换机默认使用的是Rapid Spanning Tree Protocol(RSTP),但你可以选择其他算法,如802.1D(STP)或802.1w(RSTP):
```
Switch(config-stp) mode [rstp stp 802.1d 802.1w]
```
例如,选择RSTP:
```
Switch(config-stp) mode rstp
```
```
Switch(config-stp) priority [0-65535]
```
例如,将优先级设置为4096:
```
Switch(config-stp) priority 4096
```
5. 设置交换机的桥ID:
桥ID由优先级和MAC地址组成。默认情况下,交换机的MAC地址会被用作桥ID的MAC地址部分。如果你想改变这一点,可以使用以下命令:
```
Switch(config-stp) mac-address [MAC地址]
```
例如,设置MAC地址为00:1A:2B:3C:4D:5E:
```
Switch(config-stp) mac-address 00:1A:2B:3C:4D:5E
```
6. 设置端口角色:
你可以手动设置端口的角色,例如指定端口为根端口、指定端口为非指定端口等。以下是如何设置端口角色:
```
Switch(config-if) spanning-tree portfast [enable disable]
Switch(config-if) spanning-tree bpdu-guard [enable disable]
Switch(config-if) spanning-tree cost [1-20000]
```
例如,设置端口为根端口,并设置端口成本为10:
```
Switch(config-if) spanning-tree portfast enable
Switch(config-if) spanning-tree cost 10
```
7. 保存配置:
在配置完成后,不要忘记保存配置:
```
Switch(config) end
Switch write memory
```