Sub topic 16
Placing the Root Bridge on Purpose
This chapter assumes you know how switches learn MAC addresses, what a VLAN and a trunk are, and how to read a switch command line. It also assumes you have seen how the bridge ID, path cost and port roles work in spanning tree. Here we use that knowledge to decide where the root bridge should be, and to configure it.
Why the default election is a bad plan
The root bridge election picks the switch with the lowest bridge ID. The bridge ID is the priority followed by the MAC address. Every switch ships with the default priority of 32768. If you change nothing, the MAC address breaks the tie, and the lowest MAC address wins.
Lower MAC addresses usually belong to older hardware. So an unplanned network often elects the oldest, slowest switch in the building. That switch might be an access switch in a closet at the edge of the network.
The root bridge matters because every other switch builds its paths toward it. Traffic between two access switches often has to cross the root, or travel a path chosen relative to the root. A poorly placed root can cause these problems:
- Traffic takes long, indirect paths through switches that were never meant to carry it.
- Uplinks that should be busy get blocked, and slow links get used.
- The root can change when a new switch with a lower MAC address is plugged in, which triggers a topology change across the network.
Placing the root on purpose removes these surprises.
Where the root should go
In a typical campus design with access, distribution and core layers, the root belongs at the center of the Layer 2 domain. This is usually a distribution or core switch. It should be:
- Well connected, with fast links to the other switches.
- Reliable, with redundant power and stable hardware.
- Powerful enough to forward traffic at line rate.
You should also choose a backup root. If the primary root fails, the next lowest bridge ID wins. Without a planned backup, that could be any switch. Set the backup's priority higher than the primary's but still far below the default, so it is the clear second choice.
The following diagram shows a common layout. Two distribution switches are the primary and secondary root, and the access switches connect to both.
Setting the priority
Bridge priority is a number from 0 to 61440, and it must be a multiple of 4096. The reason is the extended system ID. On Cisco switches running per-VLAN spanning tree, 12 bits of the priority field hold the VLAN number. Only the top 4 bits are left for the priority, which gives 16 steps of 4096.
This means the real priority value for a VLAN is the configured priority plus the VLAN number. For VLAN 10 with a configured priority of 4096, the switch advertises 4106. You will see this number in the show spanning-tree output.
There are two ways to set it. The first is the root macro:
! Cisco IOS: use Rapid PVST+ and make this switch the root for VLAN 10
configure terminal
spanning-tree mode rapid-pvst
spanning-tree vlan 10 root primary
end
! Or set the priority explicitly (must be a multiple of 4096)
configure terminal
spanning-tree vlan 10 priority 4096
endThe first command selects Rapid PVST+. The root primary macro looks at the current root's priority and sets this switch's priority lower. It normally sets 24576, or 4096 less than the current root if that root is already at or below 24576. The root secondary form sets 28672.
The macro has a weakness. It sets a value once, when you run it. It does not keep watching. If someone later configures another switch with a lower priority, your switch loses the election and nothing warns you. For that reason many teams prefer explicit priorities, such as 4096 on the primary and 8192 on the secondary, because the intent is visible in the configuration.
Root placement per VLAN
With Rapid PVST+, each VLAN has its own tree, so each VLAN can have its own root. This lets you balance load. Distribution 1 can be the root for odd-numbered VLANs and Distribution 2 the root for even-numbered VLANs. Each access switch then blocks a different uplink in each VLAN, so both uplinks carry traffic.
! Distribution 1
spanning-tree vlan 10,30 priority 4096
spanning-tree vlan 20,40 priority 8192
! Distribution 2
spanning-tree vlan 20,40 priority 4096
spanning-tree vlan 10,30 priority 8192Each switch is the primary root for two VLANs and the secondary for the other two. If either switch fails, the other becomes root for all four VLANs.
Keeping the root where you put it
Setting a low priority wins the election today. It does not prevent someone from winning it tomorrow. A switch added with priority 0, or a misconfigured device that sends BPDUs, could take over the root role. Root Guard protects against this. It is applied to ports that face switches that must never become the root, such as distribution-to-access links:
! Cisco IOS: access port facing an end host
interface GigabitEthernet0/5
switchport mode access
switchport access vlan 10
spanning-tree portfast
spanning-tree bpduguard enable
! Distribution-to-access port that must never lead to the root
interface GigabitEthernet0/24
spanning-tree guard rootIf a superior BPDU arrives on a Root Guard port, the port moves to a root-inconsistent state. It stops forwarding traffic until the superior BPDUs stop, and then it recovers on its own. Priority 0 on a rogue switch can still win elsewhere in the network, so Root Guard belongs on every port that points away from the intended root.
Verifying the result
After a change, confirm the root with these commands:
! Cisco IOS: inspect spanning tree state
show spanning-tree vlan 10
show spanning-tree summary
show spanning-tree interface GigabitEthernet0/1 detail
show spanning-tree inconsistentportsIn show spanning-tree vlan 10, the "Root ID" block describes the current root. On the root itself, the output states "This bridge is the root". On other switches, the block shows the root's priority and address, and the cost and port that lead toward it. Then check that the priority shown matches what you configured, remembering the VLAN number is added to it.
Use show spanning-tree inconsistentports to see ports that Root Guard or another guard has blocked.
Linux bridges
Linux software bridges follow the same rules. A lower priority makes the bridge more likely to be root:
# Linux bridge with STP enabled
sudo ip link add name br0 type bridge stp_state 1
sudo ip link set dev eth0 master br0
sudo ip link set dev eth1 master br0
sudo ip link set dev br0 type bridge priority 4096
sudo ip link set dev br0 up
# Inspect the bridge and its ports
ip -d link show br0
bridge link showThe Linux priority is a plain 16-bit value and the default is 32768. It uses classic single-tree spanning tree here, not per-VLAN trees.
Common errors
| Mistake | Effect | Fix |
|---|---|---|
| Leaving all priorities at default | Lowest MAC address wins, often an old access switch | Set explicit priorities on the intended root and backup |
| Setting only a primary root | Failure elects an arbitrary switch | Configure a secondary root |
| Using a value not divisible by 4096 | The command is rejected | Use 4096, 8192, 12288, and so on |
| Setting priority 0 everywhere | A new switch cannot be placed above your root | Keep some headroom, such as 4096 |
| Forgetting Root Guard | A new or rogue switch can take over the root role | Apply Root Guard on ports facing away from the root |
| Setting the root on one VLAN only | Other VLANs still use the default election | Configure every active VLAN, or use a range |
Exercise
A network has two distribution switches, D1 and D2, and several access switches. All switches use the default priority. You want D1 as the primary root and D2 as the backup for VLAN 20. Which priorities would you configure, and what priority value will show spanning-tree vlan 20 display on D1?
Show answer
Set D1 to spanning-tree vlan 20 priority 4096 and D2 to spanning-tree vlan 20 priority 8192. Both values are multiples of 4096 and far below the default of 32768. D1 displays 4116, which is the configured priority 4096 plus the VLAN number 20 (the extended system ID). You would also apply Root Guard to the distribution ports that face the access switches.
Exercise
Why can the root primary macro still leave you with the wrong root some weeks later?
Show answer
The macro sets a priority once, based on what it sees at the time. It does not track later changes. If another switch is configured with a lower priority, it wins the election and the macro does not react. Explicit priorities, plus Root Guard on the right ports, keep the placement stable.