Intermediate · Spanning Tree and EtherChannel · topic 29 of 57 · 25 min
Protecting spanning tree: PortFast, BPDU Guard, Root Guard and Loop Guard
Explanation
A story: the cheap switch under the desk
In a busy accounts office, Rakesh needs two more network sockets for his new printer and laptop. He buys a small 5-port unmanaged switch from the local market and plugs it into the wall socket. That part is harmless. Then, thinking "two cables will be faster", he plugs a second cable from the little switch into the other wall socket on his desk. Both sockets lead to the same access switch: he has just built a loop.
Most unmanaged switches do not run STP; they simply pass BPDUs along like any other multicast frame. Without protection, the access switch might take up to 30 seconds to sort things out, or worse, if spanning tree was tuned badly or disabled, a broadcast storm would take down the whole floor. With the protection in this topic, the access switch sees its own BPDU come back in on a user port and shuts that one port down in a fraction of a second. Rakesh loses one socket; everyone else keeps working.
PortFast: no waiting on edge ports
Normally a port that comes up spends 30 seconds in listening and learning (classic STP) before forwarding. For a PC, printer or server, that wait is pointless: a single end device cannot create a loop. It even causes trouble, because the PC may give up on DHCP before the port forwards. PortFast makes the port go straight to forwarding. In RSTP terms, it makes the port an edge port.
SW1(config)# interface range fastEthernet 0/1 - 24
SW1(config-if-range)# switchport mode access
SW1(config-if-range)# spanning-tree portfast
SW1(config-if-range)# exit
SW1(config)# spanning-tree portfast defaultBPDU Guard: switches not welcome here
End devices never send BPDUs. So if a BPDU arrives on a PortFast port, something is wrong: someone plugged in a switch, or a loop sent your own BPDU back. BPDU Guard reacts by putting the port into the err-disabled state, which is effectively shut down by the switch itself. This is what saved Rakesh's office.
SW1(config)# interface fastEthernet 0/5
SW1(config-if)# spanning-tree bpduguard enable
SW1(config-if)# exit
SW1(config)# spanning-tree portfast bpduguard defaultRoot Guard: keep the root where you put it
Suppose someone connects a lab switch with priority 0 to an access switch. Its BPDUs are superior (they claim a better root), and the whole network would rebuild its tree around this lab switch. Root Guard, configured on ports where a root should never appear (typically distribution ports facing access switches), ignores superior BPDUs and puts the port into a root-inconsistent state, where it does not forward. When the superior BPDUs stop, the port recovers on its own.
DSW1(config)# interface gigabitEthernet 1/0/10
DSW1(config-if)# spanning-tree guard rootLoop Guard, briefly
A blocked port stays blocked because it keeps receiving BPDUs. If a fibre fails in only one direction, BPDUs stop arriving even though the link is up, and the port would wrongly move to forwarding and create a loop. Loop Guard (spanning-tree guard loop, on root and alternate ports) puts such a port into a loop-inconsistent state instead, and lets it recover when BPDUs return.
| Feature | Where | Triggered by | Action |
|---|---|---|---|
| PortFast | Ports to end devices | Port coming up | Forward at once |
| BPDU Guard | PortFast ports | Any BPDU received | err-disable the port |
| Root Guard | Ports where a root must never be | A superior BPDU | root-inconsistent until BPDUs stop |
| Loop Guard | Root and alternate ports | BPDUs stop arriving | loop-inconsistent until BPDUs return |
Recovering an err-disabled port
First remove the cause (take away the extra cable or switch). Then bring the port back by hand, or let the switch try again automatically after an interval (300 seconds by default).
SW1# show interfaces status err-disabled
SW1# configure terminal
SW1(config)# interface fastEthernet 0/5
SW1(config-if)# shutdown
SW1(config-if)# no shutdown
SW1(config-if)# exit
SW1(config)# errdisable recovery cause bpduguard
SW1(config)# errdisable recovery interval 300Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Protecting spanning tree: PortFast, BPDU Guard, Root Guard and Loop Guard · 1/6
In this lesson you will learn the features that protect spanning tree from mistakes and rogue switches.
Prefer a video by a teacher? Find free videos on “portfast bpdu guard root guard loop guard explained cisco” on YouTube ↗
In real life: A coworking space in Bengaluru
A coworking space rents desks to forty startups, and members often bring their own small switches and routers. The operator configures every desk port with switchport mode access, spanning-tree portfast, spanning-tree bpduguard enable and errdisable recovery for bpduguard after 300 seconds. Root Guard sits on the core ports facing the floor switches. When a member plugs in a home lab switch that sends BPDUs, only that desk port shuts down, the operator gets a syslog message, and nobody else notices.
interface range gigabitEthernet 1/0/1 - 44
switchport mode access
switchport access vlan 30
spanning-tree portfast
spanning-tree bpduguard enable
!
errdisable recovery cause bpduguard
errdisable recovery interval 300Practice (0/3 done)
A user port has PortFast and BPDU Guard. A user connects a managed switch that sends BPDUs. What happens?
Write whatHappens(port, bpdu) for a BPDU that arrives on a switch port. port is an object like { portfast: true, bpduGuard: true, rootGuard: false } and bpdu is { superior: true or false }. Return "err-disabled" if BPDU Guard is on; otherwise "root-inconsistent" if Root Guard is on and the BPDU is superior; otherwise "normal-stp" (the port simply takes part in spanning tree, and a PortFast port loses its edge status).
Write the configuration for an access switch with 24 user ports (Fa0/1 to Fa0/24, VLAN 10) and two uplinks (Gi0/1, Gi0/2) to distribution switches. User ports must forward at once and shut down if a switch is connected; err-disabled ports should recover by themselves after 10 minutes. Uplinks must NOT have PortFast. Then explain how you would bring back Fa0/7 by hand after it err-disabled.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- EtherChannel: bundling linksSpanning Tree and EtherChannel · same module
- Layer 2 security: port security, DHCP snooping, DAINetwork security
- How a switch learns and forwardsEthernet, MAC addresses and the Cisco CLI
- Switch management and interface troubleshootingSwitching and VLANs
- VLANs: what they are and why we use themSwitching and VLANs
- Network devicesHow networks work
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
On which ports should you enable PortFast?
Answer: Ports to end devices such as PCs and printers
PortFast skips the loop checks, so it is only safe on ports to single end devices.
What does Root Guard do when a superior BPDU arrives?
Answer: Puts the port in a root-inconsistent state until the superior BPDUs stop
Root Guard blocks the port while superior BPDUs arrive and recovers automatically afterwards.
Which command enables BPDU Guard on every PortFast port at once?
Answer: spanning-tree portfast bpduguard default
spanning-tree portfast bpduguard default applies BPDU Guard to all PortFast-enabled ports.
A port was err-disabled by BPDU Guard and you have removed the rogue switch. How do you bring it back by hand?
Answer: shutdown, then no shutdown
shutdown followed by no shutdown resets an err-disabled port once the cause is gone.
What problem does Loop Guard protect against?
Answer: A blocked port forwarding because BPDUs stopped arriving, for example on a one-way fibre fault
Loop Guard keeps the port out of forwarding when BPDUs stop, instead of assuming the path is clear.
What priority does spanning-tree vlan 10 root secondary set?Related
Answer: 28672
root secondary sets 28672, just below the default 32768 and above the root primary value.
A switch log keeps saying a host is "flapping between port Gi0/1 and port Gi0/2". What does this suggest?Related
Answer: A layer 2 loop
MAC flapping means the same source MAC keeps arriving on different ports, a typical sign of a loop.
A port was err-disabled by port security. What brings it back up, after fixing the cause?Related
Answer: shutdown, then no shutdown
An err-disabled port is recovered with shutdown and no shutdown, or automatically with errdisable recovery.
Two ports on a switch have the same root path cost. What is compared next?Related
Answer: The neighbour (sender) bridge ID
Next comes the lowest sender bridge ID, then the sender port priority, then the sender port number.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 1 more topic in “Spanning Tree and EtherChannel” before its exam: EtherChannel: bundling links.
- Module 6 exam: Spanning Tree and EtherChannel · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Routing: static routes and OSPF. 57 topics left in the course before the final exam.