I hate Spanning Tree. Every time I have to study it again for another certification, I remember how much I hate it. For some reason, it just never sticks. I learn the port roles, states, and how everything works, then a few months later I come back to it and feel like I'm starting from scratch again.
Spanning Tree Protocol (STP) is a Layer 2 protocol that prevents switching loops in networks with redundant links. It does this by electing a root bridge, calculating the best path back to that root, and blocking redundant paths that could create loops. If an active link fails, STP can bring a previously blocked path into forwarding state to restore connectivity. The idea is simple enough, but things get more complicated once you start dealing with root bridge elections, path costs, port roles, and different STP versions.
We'll start with a PVST+ topology, configure the root bridge and path selection, then move to Rapid-PVST+, test BPDU Guard and Root Guard, and finish with MST.
Topology
The topology consists of two distribution switches, two access switches, and a fifth switch used to test STP protection features.
DSW1 and DSW2 are connected directly to each other. ASW1 and ASW2 each have an uplink to both distribution switches. ROGUE connects to an initially disabled access port on ASW1.
VLANs 10 and 20 are configured on all four main switches, and the inter-switch links are static 802.1Q trunks.
ASW1 Gi1/1 is an access port in VLAN 10, and ASW2 Gi1/1 is in VLAN 20. The interface connecting ROGUE to ASW1 starts administratively shut.
All links operate at 1 Gbps. PVST+ and Rapid-PVST+ use a path cost of 4, while MST uses a cost of 20000.
The initial STP configuration is:
spanning-tree mode pvstTask 1: Identify the Root Bridge and Port Roles
Objective: Determine the root bridge for VLAN 10, identify the root ports, and find which interfaces are blocking.
We will start by checking the current STP topology:
show spanning-tree rootshow spanning-tree vlan 10show spanning-tree blockedportsRoot bridge election
STP elects the switch with the lowest Bridge ID (BID).
The BID consists of the bridge priority, extended system ID, and MAC address. With the extended system ID, the displayed default priority for VLAN 10 is:
32768 + 10 = 32778Since all switches have the default configured priority of 32768, the MAC address determines the root bridge.
| Switch | Bridge MAC |
|---|---|
| ASW2 | 5000.0001.0000 |
| ASW1 | 5000.0002.0000 |
| DSW2 | 5000.0003.0000 |
| DSW1 | 5000.0004.0000 |
ASW2 has the lowest MAC address, so it becomes the root bridge.
Root port selection
Each non-root switch selects the port with the lowest total path cost toward the root bridge.
All links have a cost of 4.
DSW1 and DSW2 have direct connections to ASW2, so their root path costs are both 4.
ASW1 has two possible paths:
- ASW1 → DSW1 → ASW2: cost 8
- ASW1 → DSW2 → ASW2: cost 8
Since the path costs are equal, ASW1 compares the sender Bridge IDs. DSW2 has the lower BID, so ASW1 selects Gi0/1 as its root port.
On the link between DSW1 and DSW2, both advertise a root path cost of 4. DSW2 wins the designated-port election because it has the lower BID, leaving DSW1 Gi0/0 blocked.
The resulting port roles are:
| Switch | Root port | Blocked port |
|---|---|---|
| ASW2 | Root bridge | None |
| ASW1 | Gi0/1 | Gi0/0 |
| DSW2 | Gi0/2 | None |
| DSW1 | Gi0/2 | Gi0/0 |
Task 2: Configure Primary and Secondary Root Bridges
Objective: Configure DSW1 as the primary root for VLANs 1 and 10, and DSW2 as the primary root for VLAN 20.
Each distribution switch should also act as the secondary root for the other's VLANs.
| VLAN | Primary root | Secondary root |
|---|---|---|
| 1 | DSW1 | DSW2 |
| 10 | DSW1 | DSW2 |
| 20 | DSW2 | DSW1 |
Configuration
On DSW1:
configure terminalspanning-tree vlan 1,10 root primaryspanning-tree vlan 20 root secondaryendOn DSW2:
configure terminalspanning-tree vlan 20 root primaryspanning-tree vlan 1,10 root secondaryendThe root primary and root secondary commands are shortcuts for configuring STP bridge priorities without manually calculating the values. The root primary command checks the current root bridge priority and adjusts the local switch's priority to make it the preferred root. The root secondary command sets the priority to 28672, making the switch a potential backup root if the primary fails. These commands do not assign permanent roles; the root bridge is still elected based on the lowest bridge ID.
In this topology, the primary priority becomes 24576, while the secondary becomes 28672.
For VLAN 10, DSW1's displayed priority is:
24576 + 10 = 24586DSW2's displayed priority is:
28672 + 10 = 28682DSW1 has the lower priority and becomes the root for VLAN 10.
Verification
show spanning-tree rootshow spanning-tree vlan 10show spanning-tree vlan 20The resulting topology should be:
| Switch | VLAN 10 | VLAN 20 |
|---|---|---|
| DSW1 | Root bridge | Root port Gi0/0 |
| DSW2 | Root port Gi0/0 | Root bridge |
| ASW1 | Root port Gi0/0 | Root port Gi0/1 |
| ASW2 | Root port Gi0/0 | Root port Gi0/1 |
Both access switches now use DSW1 as their root bridge for VLAN 10 and DSW2 for VLAN 20. Since STP calculates a separate topology for each VLAN, the same physical link can be forwarding for one VLAN and blocking for another.
This allows us to distribute traffic across both distribution switches instead of sending everything through a single switch. VLAN 10 traffic takes the path through DSW1, while VLAN 20 traffic takes the path through DSW2. If one of the active paths fails, STP can unblock a previously blocked port and restore connectivity through the remaining path.
Task 3: Change Root Port Selection Using STP Cost
Objective: Make ASW2 use Gi0/1 toward DSW2 as its VLAN 10 root port instead of Gi0/0 toward DSW1.
VLAN 20 must remain unchanged.
Path cost calculation
STP selects the root port based on the lowest total path cost to the root bridge. In our topology, DSW1 is the root bridge for VLAN 10, and ASW2 has two possible paths to reach it.
| Path | Total cost |
|---|---|
| Gi0/0 directly to DSW1 | 4 |
| Gi0/1 through DSW2 | 8 |
The direct connection to DSW1 has a cost of 4, so ASW2 currently selects Gi0/0 as its root port.
The second path goes through DSW2. Since DSW2 is not the root bridge for VLAN 10, traffic must pass through DSW2 before reaching DSW1. Each Gigabit link adds a cost of 4, bringing the total to 8.
We want ASW2 to prefer the path through DSW2 without changing the root bridge. We can do this by increasing the STP cost of Gi0/0 to a value higher than 8.
Configuration
On ASW2:
configure terminalinterface GigabitEthernet0/0 spanning-tree vlan 10 cost 10endASW2 should now select Gi0/1 as its root port because the path through DSW2 has a total cost of 8.
Gi0/0 becomes an alternate port.
Verification
show spanning-tree vlan 10show spanning-tree vlan 20Verify that:
- Gi0/1 is the root port for VLAN 10.
- Gi0/0 is the alternate port for VLAN 10.
- VLAN 20 still uses Gi0/1 toward DSW2.
For VLAN 10, Gi0/1 should now be the root port, while Gi0/0 should be the alternate port. VLAN 20 should remain unchanged, with Gi0/1 as its root port.
We changed the cost only for VLAN 10. Using spanning-tree cost 10 without specifying a VLAN would affect all applicable VLANs on the interface.
Bridge priority determines which switch becomes the root bridge, while port cost determines the preferred path toward it. Port priority is used as a later tie-breaker when path costs are equal.
Task 4: Configure Rapid-PVST+ and Test Convergence
Objective: Convert the topology to Rapid-PVST+ and test how an alternate port takes over when the active uplink fails.
Configuration
On all five switches:
configure terminalspanning-tree mode rapid-pvstendRapid-PVST+ uses RSTP for each VLAN.
The root election and path selection rules are essentially the same as classic STP. The main difference is how ports transition into forwarding.
Classic 802.1D STP uses listening and learning timers during normal convergence. RSTP introduces proposal/agreement on point-to-point links and can rapidly transition eligible ports into forwarding.
RSTP also uses three port states:
- Discarding
- Learning
- Forwarding
An alternate port provides a backup path to the root bridge and can replace the root port when the active path fails.
Verification
On ASW1:
show spanning-tree summaryshow spanning-tree vlan 10For VLAN 10, verify that Gi0/0 is the root port and Gi0/1 is the alternate port.
Check that both uplinks are identified as point-to-point (P2p).
Test the failover
Enable STP event debugging on ASW1:
debug spanning-tree eventsShut down the active VLAN 10 uplink:
configure terminalinterface GigabitEthernet0/0 shutdownendCheck the new port roles:
show spanning-tree vlan 10Gi0/1 should become the root port and transition to forwarding.
Since we shut down the interface directly, ASW1 detects the link failure immediately. If the physical link stays up but BPDUs stop arriving, RSTP may take longer to detect the failure and reconverge.
Task 5: Configure PortFast and BPDU Guard
Objective: Enable PortFast on user-facing access ports and configure BPDU Guard to prevent another switch from being connected to those ports.
Configuration
On ASW1 and ASW2:
configure terminalspanning-tree portfast edge defaultspanning-tree portfast edge bpduguard defaultendPortFast allows a port connected to an end device, such as a PC or server, to enter the forwarding state immediately when the link comes up. Without PortFast, traditional STP would make the port go through listening and learning before forwarding traffic. There is no reason for an end device to wait for STP convergence, since it shouldn't be creating any Layer 2 loops.
PortFast doesn't disable STP. The port still participates in STP and can receive BPDUs. The problem is that someone could connect another switch to a PortFast-enabled port, potentially introducing a switching loop.
This is where BPDU Guard comes in. If a protected port receives a BPDU, BPDU Guard puts it into the err-disabled state, effectively shutting it down to prevent a potential loop.
With BPDU Guard enabled globally, it applies to ports operating as PortFast edge ports. Regular switch-to-switch links are not affected unless BPDU Guard is explicitly configured on those interfaces.
Verification
show spanning-tree summaryshow spanning-tree interface GigabitEthernet1/1 detailshow spanning-tree vlan 10Check that the user-facing ports have edge behavior enabled and that the uplinks remain normal point-to-point STP ports.
Test BPDU Guard
ASW1 Gi1/0 connects to the ROGUE switch. The interface is currently shut down.
configure terminalinterface GigabitEthernet1/0 no shutdownendWith ROGUE Gi0/0 enabled, ROGUE sends BPDUs toward ASW1.
ASW1 should detect the BPDU and place Gi1/0 into the err-disabled state.
Check:
show interfaces status err-disabledshow loggingThe logs should indicate that BPDU Guard disabled the interface.
ROGUE doesn't need a lower bridge priority to trigger BPDU Guard. Receiving any BPDU is sufficient.
Test automatic recovery
On ASW1:
configure terminalerrdisable recovery cause bpduguarderrdisable recovery interval 30endCheck the recovery status:
show errdisable recoveryAfter the recovery interval, the switch attempts to re-enable the interface.
If ROGUE is still sending BPDUs, BPDU Guard should disable it again.
Automatic recovery only brings the interface back up. It doesn't remove the condition that triggered the protection.
To recover manually, remove the offending connection and reset the interface:
configure terminalinterface GigabitEthernet1/0 shutdown no shutdownendTask 6: Configure Root Guard
Objective: Prevent an access switch from becoming the root bridge, even if it advertises a lower bridge priority than the distribution switches.
Root Guard prevents an unexpected switch from becoming the root bridge. It is typically configured on designated ports facing switches that should never become the root.
For example, if an access switch starts advertising a superior BPDU with a lower bridge ID, it could become the new root bridge and change the STP topology.
With Root Guard enabled, the distribution switch places the affected port into the root-inconsistent state when it receives a superior BPDU. The port stops forwarding traffic but is not shut down. Once the superior BPDUs stop arriving, the port automatically returns to its normal STP state.
Configuration
On DSW1 and DSW2:
configure terminalinterface range GigabitEthernet0/1 - 2 spanning-tree guard rootendThis enables Root Guard on the distribution downlinks toward ASW1 and ASW2.
Test Root Guard
On ASW2, change the VLAN 10 bridge priority to 0:
configure terminalspanning-tree vlan 10 priority 0endASW2 now advertises a superior Bridge ID for VLAN 10.
The distribution switches should detect these superior BPDUs on their downlinks toward ASW2.
On DSW1 and DSW2:
show spanning-tree inconsistentportsshow spanning-tree vlan 10show spanning-tree vlan 20Both distribution switches should place Gi0/2 into the root-inconsistent state for VLAN 10.
The VLAN 10 STP output may display the affected port as BKN* with a ROOT_Inc indication.
VLAN 20 should remain unaffected because ASW2 isn't advertising a superior root for that VLAN.
Root Guard blocks the affected VLAN on the interface instead of err-disabling the entire physical port.
ASW2 loses VLAN 10 connectivity to the rest of the topology during this test. Root Guard prevents the incorrect root placement, but it doesn't preserve connectivity through the offending path.
BPDU Guard vs Root Guard
| Feature | BPDU Guard | Root Guard |
|---|---|---|
| Typical location | User-facing access ports | Downstream switch links |
| Trigger | Any received BPDU | Superior received BPDU |
| Result | Interface err-disabled | Root-inconsistent state |
| Recovery | Manual or configured errdisable recovery | Automatic after the condition clears |
Task 7: Configure MST
Objective: Replace Rapid-PVST+ with MST, configure two MST instances, and distribute VLANs 10 and 20 between them.
Rapid-PVST+ runs a separate spanning-tree instance for every VLAN. Each VLAN has its own root bridge, port roles, and forwarding topology. This gives us flexibility when configuring per-VLAN load sharing, but it also means switches have to maintain a separate STP topology for every VLAN.
Multiple Spanning Tree (MST) solves this by allowing multiple VLANs to share a single spanning-tree instance. For example, we can map VLANs 10, 30, and 50 to MST instance 1, and VLANs 20, 40, and 60 to instance 2. Instead of maintaining six separate spanning trees, the switches only need to maintain two. Each instance can have its own root bridge and forwarding topology, so we can still distribute traffic across different paths.
MST switches are organized into regions. Switches belong to the same MST region only when their region name, revision number, and VLAN-to-instance mappings match. If any of these settings differ, the switches are treated as belonging to different regions, even if they are physically connected.
All switches within a region must agree on these settings so they can calculate a consistent spanning-tree topology for each instance.
We'll configure:
| Instance | VLANs | Root bridge |
|---|---|---|
| MST 0 | All VLANs not mapped elsewhere | DSW1 |
| MST 1 | 10 | DSW1 |
| MST 2 | 20 | DSW2 |
MST 0 is the Internal Spanning Tree (IST).
Configure the MST region
On DSW1, DSW2, ASW1, and ASW2:
configure terminalspanning-tree mst configuration name ENCOR revision 1 instance 1 vlan 10 instance 2 vlan 20 exitspanning-tree mode mstendThe region configuration must match on all four switches.
The instance mapping doesn't create VLANs in the VLAN database. It only assigns VLANs to STP instances.
Configure the MST roots
On DSW1:
configure terminalspanning-tree mst 0-1 root primaryspanning-tree mst 2 root secondaryendOn DSW2:
configure terminalspanning-tree mst 2 root primaryspanning-tree mst 0-1 root secondaryendThe root bridge priorities we configured earlier for PVST+ do not carry over to MST. MST uses its own bridge priorities for each instance, so we need to configure the root bridges again.
We also need to configure instance 0, which is the Internal Spanning Tree (IST) and is used by MST for the Common and Internal Spanning Tree (CIST).
By default, all switches have a bridge priority of 32768. If we leave instance 0 at its default priority, the switch with the lowest MAC address wins the root election. This means ASW2 could become the root even though we want the distribution switches to handle that role.
To avoid this, we'll explicitly configure the root bridge priorities for instances 0, 1, and 2.
Verification
show spanning-tree mst configurationshow spanning-tree mst 0show spanning-tree mst 1show spanning-tree mst 2The displayed root priority for MST 1 on DSW1 should be 24577. For MST 2 on DSW2, it should be 24578.
With MST, the extended system ID is the instance number rather than the VLAN number.
On the access switches, check that:
- MST 1 uses Gi0/0 toward DSW1.
- MST 2 uses Gi0/1 toward DSW2.
- MST 0 uses DSW1 as the root.
The 1 Gbps uplinks should use a path cost of 20000 with the long cost method.
We have three spanning-tree instances in total, including the IST. With only VLANs 10 and 20 configured, the reduction compared to Rapid-PVST+ is limited. The benefit becomes more significant when multiple VLANs are mapped to each MST instance.
