Don't leave it to chance
By default the switch with the lowest MAC (often the oldest, slowest one) becomes root. Choose it instead, usually a core or distribution switch:
| Command | Effect |
|---|---|
| spanning-tree vlan 1 priority 4096 | Sets the priority (a multiple of 4096: 0, 4096 ... 61440) |
| spanning-tree vlan 1 root primary | Sets 24576, or 4096 less than the current root if that's lower |
| spanning-tree vlan 1 root secondary | Sets 28672: takes over if the primary fails |
In NetLab
▶ SW1 SW1>enable SW1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#spanning-tree vlan 1 root primary SW1(config)#end *Mar 1 00:00:04.000: %SYS-5-CONFIG_I: Configured from console by console SW1#show spanning-tree vlan 1 | include Root ID|Priority|This Root ID Priority 24577 This bridge is the root Bridge ID Priority 24577 (priority 24576 sys-id-ext 1) ▶ SW3 SW3>enable SW3#show spanning-tree vlan 1 | begin Interface Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Fa0/1 Desg FWD 19 128.1 P2p Gi0/1 Root FWD 4 128.25 P2p Gi0/2 Desg FWD 4 128.26 P2p
One root per VLAN
With PVST+ each VLAN has its own tree, so you can make SW1 root for VLAN 10 and SW2 root for VLAN 20. Each VLAN then blocks a different link, and both links carry traffic.
Cost and port priority
spanning-tree cost 10 on an interface changes its cost, steering which path a switch prefers to the root. spanning-tree port-priority 64 (multiples of 16, default 128) breaks ties on the neighbour's side when two links reach the same switch.
In NetLab
▶ SW2 SW2>enable SW2#show spanning-tree vlan 1 | begin Interface Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Fa0/1 Desg FWD 19 128.1 P2p Gi0/1 Desg FWD 4 128.25 P2p Gi0/2 Root FWD 4 128.26 P2p SW2#configure terminal Enter configuration commands, one per line. End with CNTL/Z. SW2(config)#interface g0/2 SW2(config-if)#spanning-tree cost 30 SW2(config-if)#end *Mar 1 00:00:06.000: %SYS-5-CONFIG_I: Configured from console by console SW2#show spanning-tree vlan 1 | begin Interface Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Fa0/1 Desg FWD 19 128.1 P2p Gi0/1 Root FWD 4 128.25 P2p Gi0/2 Altn BLK 30 128.26 P2p
SW2 used to reach the root (SW3) directly on Gi0/2. With that cost raised to 30, going round through SW1 (4 + 4 = 8) is cheaper, so Gi0/1 becomes the root port and Gi0/2 the alternate.