⚠️ Commands are based on Cisco IOS / IOS XE documentation and haven't been run in a lab here. Interface names vary by platform.
1. Choose the mode
spanning-tree mode pvstClassic 802.1D, one tree per VLAN. For Rapid PVST+ (the Rapid Spanning Tree lessons), use 'spanning-tree mode rapid-pvst'. Use the same mode on every switch.
2. Choose the root bridge yourself
Why: if you do nothing, the switch with the lowest MAC becomes the root. That might be an old access switch in a cupboard. The root should be a strong, central switch, such as a core or distribution switch.
spanning-tree vlan 10 root primary
spanning-tree vlan 20 root secondaryOn SW1. 'root primary' is a shortcut. It sets priority 24576, or 4096 lower than the current root if that's needed to win. 'root secondary' sets 28672, so this switch takes over if the main root fails.
spanning-tree vlan 10 priority 24576The other way: set the number yourself. It must be a multiple of 4096 (0, 4096, 8192 … 61440).
The shortcut only checks the current root once, when you type it. Setting the number yourself gives a more predictable result, so many engineers prefer it.
What happens if you don't choose
Situation: three switches, all with the default priority 32768, and VLANs 1, 10, 20 and 30. Each switch adds the VLAN number to its priority. So the same switch shows a different number in each VLAN. But all switches add the same VLAN number, so the MAC address always decides:
SW3#show spanning-tree root Root Hello Max Fwd Vlan Root ID Cost Time Age Dly Root Port ---------------- -------------------- --------- ----- --- --- ------------ VLAN0001 32769 0200.0000.0001 4 2 20 15 Gi1/0/1 VLAN0010 32778 0200.0000.0001 4 2 20 15 Gi1/0/1 VLAN0020 32788 0200.0000.0001 4 2 20 15 Gi1/0/1 VLAN0030 32798 0200.0000.0001 4 2 20 15 Gi1/0/1
Spread the roots
! SW1
spanning-tree vlan 1,10 priority 0
! SW2
spanning-tree vlan 20 priority 0
! SW3
spanning-tree vlan 30 priority 0Now each VLAN has its own root. Also set a backup root for each VLAN on another switch ('root secondary' or priority 4096), so you choose the backup too.
Shortcut or your own number? root primary looks at the current root only once. If the root's priority is above 24576, it sets 24576. If not, it sets a value 4096 lower than the root. It doesn't keep checking, so a switch added later with a lower priority can still win. Setting priority 0 (or 4096) yourself is more predictable. Most designs do this.
3. Change the path with port cost
Port cost changes which port a switch chooses as its root port. It only affects the switch where you set it.
interface GigabitEthernet1/0/1
spanning-tree vlan 10 cost 30On SW3's port toward SW1. In VLAN 10 this path now costs 30, so the path through SW2 (4 + 4 = 8) wins.
- 1. New root port. SW3's best VLAN 10 path now goes through SW2 (8 is less than 30).
- 2. The old path is blocked. On the SW1–SW3 link, SW1 (cost 0) is designated. So SW3's end is now blocked for VLAN 10.
4. Port priority: set it on the switch above
interface GigabitEthernet1/0/2
spanning-tree vlan 10 port-priority 64The default is 128. Lower is better. On most Catalyst switches you set it in steps of 16.
Watch out: port priority is sent in the BPDUs as the sender port ID. So it changes the choice of the neighbour switch, not your own switch. Use it on the switch closer to the root, when two cables go to the same switch below it and the costs are equal.
5. Verify
SW1#show spanning-tree root Root Hello Max Fwd Vlan Root ID Cost Time Age Dly Root Port ---------------- -------------------- --------- ----- --- --- ------------ VLAN0010 24586 0200.0000.0001 0 2 20 15 VLAN0020 24596 0200.0000.0002 4 2 20 15 Gi1/0/1
show spanning-tree vlan 10Shows the root ID, this switch's bridge ID, and the role (Root/Desg/Altn), state and cost of every port.
show spanning-tree summaryShows the mode, the VLANs this switch is root for, and global settings such as PortFast.
Check yourself
You want SW3 to stop using its direct link to SW1 for VLAN 10. Where do you change the cost?
Which priority value is NOT valid?