Hey there! If you're working with network switches, especially in environments where redundancy is key, configuring the **Spanning Tree Protocol (STP)** is essential. STP prevents network loops by creating a loop-free logical topology. In this guide, we'll cover the basics of configuring STP on Cisco switches, including how to set up a root bridge, configure a secondary root bridge, and use verification commands to ensure your network is operating correctly. ## Understanding the Importance of STP Configuration Before we dive into the configurations, let's briefly recap why STP is critical: - **Preventing Loops**: In networks with redundant paths, loops can occur, causing broadcast storms and MAC address table instability. - **Root Bridge**: The root bridge is the logical center of the STP topology. All path calculations are made from the perspective of the root bridge. - **Optimizing Paths**: Proper configuration ensures that traffic flows efficiently through the network. ## Configuring the STP Mode First, you need to decide which version of STP to use. Cisco switches support multiple versions: - **PVSTP+**: Per-VLAN Spanning Tree Protocol Plus (default on Cisco switches) - **RSTP**: Rapid Spanning Tree Protocol (IEEE 802.1w) - **MSTP**: Multiple Spanning Tree Protocol (IEEE 802.1s) ### Setting the STP Mode Use the `spanning-tree mode` command to set the STP mode. **Syntax:** ```shell Switch(config)# spanning-tree mode {pvst | rapid-pvst | mst} ``` **Examples:** - To set Rapid PVST+: ```shell Switch(config)# spanning-tree mode rapid-pvst ``` - To set MST: ```shell Switch(config)# spanning-tree mode mst ``` **Note:** On Cisco switches, `pvst` is the default mode. ## Configuring the Root Bridge To influence which switch becomes the root bridge, you can set the bridge priority. The switch with the lowest bridge priority becomes the root bridge. ### Setting the Bridge Priority Use the `spanning-tree vlan [vlan-id] priority [value]` command to set the priority. **Syntax:** ```shell Switch(config)# spanning-tree vlan [vlan-id] priority [value] ``` - **[vlan-id]**: Specifies the VLAN ID. Use `1-4094` or `1-4094, except reserved VLANs`. - **[value]**: The priority value. Must be a multiple of 4096, ranging from 0 to 61440. **Example:** To configure a switch as the primary root bridge for VLAN 10: ```shell Switch(config)# spanning-tree vlan 10 priority 0 ``` Alternatively, you can use the `root primary` keyword to automatically set the priority to a value lower than other switches. **Example:** ```shell Switch(config)# spanning-tree vlan 10 root primary ``` This command adjusts the priority to ensure this switch becomes the root bridge for VLAN 10. ## Configuring a Secondary Root Bridge In case the primary root bridge fails, you can configure a secondary root bridge. This switch will become the root bridge if the primary fails. **Example:** ```shell Switch(config)# spanning-tree vlan 10 root secondary ``` This sets the bridge priority to a value less than the default (32768), but higher than the primary root bridge. ## Adjusting Port Costs and Priorities To influence STP path selection, you can adjust port costs and port priorities. ### Adjusting Port Cost Use the `spanning-tree [vlan vlan-id] cost [cost]` command in interface configuration mode to set the port cost. **Syntax:** ```shell Switch(config-if)# spanning-tree [vlan vlan-id] cost [cost] ``` - **[vlan vlan-id]**: (Optional) Specifies the VLAN ID. - **[cost]**: The cost value. Range varies based on STP mode. **Example:** Set the STP cost of an interface for VLAN 10: ```shell Switch(config)# interface GigabitEthernet0/1 Switch(config-if)# spanning-tree vlan 10 cost 19 ``` ### Adjusting Port Priority Use the `spanning-tree [vlan vlan-id] port-priority [value]` command in interface configuration mode to set the port priority. **Syntax:** ```shell Switch(config-if)# spanning-tree [vlan vlan-id] port-priority [value] ``` - **[value]**: Priority value. Must be in increments of 16, ranging from 0 to 240. **Example:** Set the port priority for an interface in VLAN 10: ```shell Switch(config)# interface GigabitEthernet0/1 Switch(config-if)# spanning-tree vlan 10 port-priority 16 ``` ## Verification Commands After configuring STP, it's crucial to verify that your settings are effective and that the network topology is as expected. ### Using `show spanning-tree` The `show spanning-tree` command displays the STP status and topology. **Example:** ```shell Switch# show spanning-tree ``` **Sample Output:** ``` VLAN0010 Spanning tree enabled protocol ieee Root ID Priority 24576 Address 0011.2233.4455 Cost 19 Port 1 (GigabitEthernet0/1) Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32768 (priority 32768 sys-id-ext 10) Address 00AA.BBCC.DDEE Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec ``` ### Using `show spanning-tree vlan [vlan-id]` To view STP information for a specific VLAN: ```shell Switch# show spanning-tree vlan 10 ``` ### Using `show spanning-tree interface [interface]` To display STP information for a specific interface: ```shell Switch# show spanning-tree interface GigabitEthernet0/1 ``` ### Using `show spanning-tree summary` Provides a summary of STP status: ```shell Switch# show spanning-tree summary ``` ### Using `show spanning-tree bridge` Displays bridge priority and root information. ### Alternative Command: `show spanning-tree detail` For detailed STP information. **Note:** The command `show switch spanning-tree` is not a standard Cisco IOS command. The correct command is `show spanning-tree`. ## Example Configuration: Setting Up Primary and Secondary Root Bridges Let's put it all together with an example. ### On Switch1 (Primary Root Bridge) ```shell Switch1# configure terminal Switch1(config)# spanning-tree mode rapid-pvst Switch1(config)# spanning-tree vlan 10 root primary Switch1(config)# end ``` ### On Switch2 (Secondary Root Bridge) ```shell Switch2# configure terminal Switch2(config)# spanning-tree mode rapid-pvst Switch2(config)# spanning-tree vlan 10 root secondary Switch2(config)# end ``` ### Verification on Switch1 ```shell Switch1# show spanning-tree vlan 10 ``` **Expected Output:** - Switch1 should be the root bridge for VLAN 10. - The bridge ID should show a lower priority value. ### Verification on Switch2 ```shell Switch2# show spanning-tree vlan 10 ``` **Expected Output:** - Switch2 should recognize Switch1 as the root bridge. - Switch2's root port should point towards Switch1. ## Conclusion Configuring STP correctly is vital for maintaining a stable and efficient network. By setting the root bridge and adjusting priorities and costs, you can control the STP topology to optimize traffic flow and ensure redundancy. **Key Takeaways:** - Use the `spanning-tree mode` command to set the STP version. - Configure the root bridge using `spanning-tree vlan [vlan-id] root primary`. - Set a secondary root bridge for redundancy. - Adjust port costs and priorities to influence path selection. - Always verify your configuration with `show spanning-tree` commands. --- **Need further assistance?** Feel free to ask more questions or explore advanced STP configurations, such as BPDU Guard, Root Guard, and other STP enhancements. ## Additional resources - Spanning Tree Commands: [https://www.cisco.com/c/en/us/td/docs/routers/nfvis/switch_command/b-nfvis-switch-command-reference/spanning_tree_commands.html](https://www.cisco.com/c/en/us/td/docs/routers/nfvis/switch_command/b-nfvis-switch-command-reference/spanning_tree_commands.html)