Sub topic 17
BPDU Guard, Root Guard and Loop Guard
This chapter assumes you know how the root bridge is elected, what the root, designated and alternate port roles mean, and what PortFast does on an edge port. It also assumes you can read a switch command-line interface. Spanning tree trusts every BPDU it receives and trusts the links to behave. The three guard features below remove that trust where it is not justified.
Why spanning tree needs guards
Spanning tree has no authentication by default. Any device that sends BPDUs can take part in the election. A switch plugged in by mistake, a laptop running bridging software, or an attacker with a crafted BPDU can all change the topology. A second failure mode is the opposite: a link stops delivering BPDUs, and a switch concludes that the path is free of loops when it is not.
Each guard covers one case:
| Feature | Threat it covers | Where it is applied | Reaction |
|---|---|---|---|
| BPDU Guard | A BPDU arrives where no switch should exist | Edge ports (PortFast) | Port goes to err-disabled |
| Root Guard | A superior BPDU would displace the intended root | Designated ports facing switches that must never lead to the root | Port goes to root-inconsistent (blocked) |
| Loop Guard | BPDUs stop arriving on a non-designated port | Root and alternate ports | Port goes to loop-inconsistent (blocked) |
BPDU Guard
An edge port connects to a host, and a host does not send BPDUs. If a BPDU arrives on a PortFast port, someone has connected a switch. That switch may be unmanaged, or it may have a lower bridge ID than your root. PortFast would put the port straight into forwarding, so a loop could form before spanning tree reacts.
BPDU Guard shuts the port down the moment it sees any BPDU. The port enters the err-disabled state and stays down until an administrator intervenes or an automatic recovery timer expires.
! Cisco IOS: access port facing an end host
interface GigabitEthernet0/5
switchport mode access
switchport access vlan 10
spanning-tree portfast
spanning-tree bpduguard enableYou can also enable it globally for every PortFast port:
configure terminal
spanning-tree portfast default
spanning-tree portfast bpduguard default
endWith the global form, BPDU Guard applies only to ports that are operationally in PortFast. With the interface form, it applies to that port whether or not PortFast is on. Automatic recovery is optional:
errdisable recovery cause bpduguard
errdisable recovery interval 300Use recovery with care. If the cause is a loop that someone built under a desk, the port will come back up after 300 seconds and shut down again. That is acceptable for a nuisance, but it is poor behavior if you wanted the event to be noticed.
Root Guard
Placing the root deliberately is only useful if it stays where you put it. Suppose the distribution layer is the root for VLAN 10. A switch added in an access closet, or at a customer or provider edge, may have a lower priority than your root and win the election. The tree then reshapes around a switch you did not choose.
Root Guard is applied to a port that should only ever be designated. If a superior BPDU arrives on that port, the switch does not accept it. It moves the port to the root-inconsistent state, which blocks traffic. When the superior BPDUs stop, the port recovers on its own after the normal timers, with no manual action.
! Distribution-to-access port that must never lead to the root
interface GigabitEthernet0/24
spanning-tree guard rootTwo points matter in practice:
- Root Guard is per port and applies to every VLAN on that port. In per-VLAN spanning tree, the port is blocked only for the VLANs where the superior BPDU was seen.
- Never configure Root Guard on a port that is, or may legitimately become, the root port. It will block the path to the real root.
Loop Guard
Spanning tree depends on BPDUs flowing in one direction. A non-designated port (root or alternate) keeps its role as long as BPDUs arrive from the designated port on the other end. If a unidirectional link fault, a software fault or a congested CPU stops those BPDUs, the alternate port ages out its information. It then assumes there is no neighbor sending BPDUs, makes itself designated and starts forwarding. The loop that spanning tree was blocking is now open, and traffic flows in only one direction on the broken link.
Loop Guard changes this. If a root or alternate port stops receiving BPDUs, it moves to the loop-inconsistent state instead of becoming designated. The port stays blocked, and it recovers automatically once BPDUs return.
! Per interface
interface GigabitEthernet0/1
spanning-tree guard loop
! Or globally for all point-to-point ports
configure terminal
spanning-tree loopguard default
endLoop Guard does not belong on designated ports. A designated port is the one that sends BPDUs, so a lack of received BPDUs is normal for it. Do not combine Loop Guard with Root Guard on the same port, because the two features assume opposite roles.
Many deployments also use UDLD (Unidirectional Link Detection) to find unidirectional links at the physical layer. UDLD and Loop Guard overlap but are not the same. UDLD tests the link itself, while Loop Guard reacts to missing BPDUs, which also covers software faults that UDLD cannot see.
Where each guard belongs
The diagram shows a typical three-layer design. Guards go on the ports whose purpose they match.
Summary of placement:
- Host-facing ports: PortFast and BPDU Guard.
- Downlinks from the root toward switches you do not control or must not lead to the root: Root Guard.
- Uplinks on access switches, which are root or alternate ports: Loop Guard.
- Core-to-distribution links, where the root is meant to be: no Root Guard.
Verifying and recovering
Guards report their state in the usual spanning tree commands. A port held by a guard shows an inconsistent state rather than a normal role.
show spanning-tree inconsistentports
show spanning-tree vlan 10
show interfaces status err-disabledThe first command lists ports in root-inconsistent or loop-inconsistent state, with the VLAN involved. The last lists ports shut by BPDU Guard. The log message names the port, for example %SPANTREE-2-BLOCK_BPDUGUARD, %SPANTREE-2-ROOTGUARD_BLOCK or %SPANTREE-2-LOOPGUARD_BLOCK.
To recover a BPDU Guard port, remove the offending device first. Then reset the port:
configure terminal
interface GigabitEthernet0/5
shutdown
no shutdown
endIf you reset the port while the switch is still connected, BPDU Guard will shut it down again.
Common mistakes
- Enabling BPDU Guard on a trunk to another switch. The first BPDU disables the uplink.
- Enabling Root Guard on the real root port, which blocks the path to the root.
- Forgetting that Root Guard blocks only until the superior BPDUs stop, so a flapping rogue device causes repeated outages instead of one clean failure.
- Filtering BPDUs on a port (BPDU Filter) and expecting BPDU Guard to still fire. Filtering drops BPDUs before they can trigger the guard, and on an edge port it hides loops.
- Relying on automatic err-disable recovery and never reading the logs.
Exercise
An access switch has two uplinks to the root. One is the root port and the other is an alternate port in blocking. The link carrying the alternate port develops a fault in which the far end stops sending BPDUs but the link stays up. Without a guard, what happens to the alternate port, and which feature prevents it?
Show answer
After max age expires, the alternate port stops receiving BPDUs and no longer has a better path to point to. It then becomes designated and moves toward forwarding, which opens a loop between the two uplinks. Loop Guard prevents this. The port goes to loop-inconsistent and stays blocked until BPDUs return.
Exercise
You enable BPDU Guard on GigabitEthernet0/5, which has PortFast on. A user plugs in a small switch. Describe what you see and the correct recovery steps.
Show answer
The port goes to err-disabled and the log shows a BPDU Guard message. The command show interfaces status err-disabled lists the port. Remove the small switch, then run shutdown followed by no shutdown on the interface. If errdisable recovery for bpduguard is enabled, the port recovers after the interval, but only reconnecting the switch would trigger it again.