Skip to content

Intermediate · Spanning Tree and EtherChannel · topic 29 of 57 · 25 min

Protecting spanning tree: PortFast, BPDU Guard, Root Guard and Loop Guard

Explanation

PortFast makes a port to an end device forward at once instead of waiting 30 seconds. BPDU Guard err-disables a port the moment a BPDU arrives on it, which stops loops and rogue switches on user ports. Root Guard stops another switch from becoming root through a port, and Loop Guard stops a port from forwarding just because BPDUs stopped arriving. An err-disabled port comes back with shutdown and no shutdown, or automatically with errdisable recovery.

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.

output
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 default
Cisco IOS: per interface, or globally for all access ports. On some newer IOS versions the keyword edge is added (spanning-tree portfast edge).
Careful: Enable PortFast only on ports to end devices. On a port to another switch it can create a temporary loop, because the port forwards before STP has checked it. IOS prints a warning saying the same when you enable it.

BPDU 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.

output
SW1(config)# interface fastEthernet 0/5
SW1(config-if)# spanning-tree bpduguard enable
SW1(config-if)# exit
SW1(config)# spanning-tree portfast bpduguard default
Cisco IOS: on one port, or globally on every PortFast port. PortFast and BPDU Guard together are the standard setting for user ports.

Root 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.

output
DSW1(config)# interface gigabitEthernet 1/0/10
DSW1(config-if)# spanning-tree guard root
Cisco IOS: this port may connect switches, but never one that wants to be root.

Loop 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.

FeatureWhereTriggered byAction
PortFastPorts to end devicesPort coming upForward at once
BPDU GuardPortFast portsAny BPDU receivederr-disable the port
Root GuardPorts where a root must never beA superior BPDUroot-inconsistent until BPDUs stop
Loop GuardRoot and alternate portsBPDUs stop arrivingloop-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).

output
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 300
Cisco IOS: manual recovery with shutdown / no shutdown, then optional automatic recovery after 300 seconds.
Careful: Common mistakes: re-enabling an err-disabled port without removing the cause (it shuts again at once); turning on PortFast on uplinks; and using automatic recovery with a very short interval, which can make a looped port flap up and down all day.

Need 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

Protecting STP

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.

output
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 300
Cisco IOS: the standard desk-port template.

Practice (0/3 done)

Task 1 · Question

A user port has PortFast and BPDU Guard. A user connects a managed switch that sends BPDUs. What happens?

Task 2 · Code · Javascript

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).

Task 3 · Practice

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

Question 1

1.On which ports should you enable PortFast?

Question 2

2.What does Root Guard do when a superior BPDU arrives?

Question 3

3.Which command enables BPDU Guard on every PortFast port at once?

Question 4

4.A port was err-disabled by BPDU Guard and you have removed the rogue switch. How do you bring it back by hand?

Question 5

5.What problem does Loop Guard protect against?

Read more (free)

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.

From STP port states, RSTP and Rapid PVST+

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.

From Why layer 2 loops are deadly

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.

From Layer 2 security: port security, DHCP snooping, DAI

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.

From Root bridge election, root ports and designated ports

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. 1 more topic in “Spanning Tree and EtherChannel” before its exam: EtherChannel: bundling links.
  2. Module 6 exam: Spanning Tree and EtherChannel · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Routing: static routes and OSPF. 57 topics left in the course before the final exam.

← Previous: STP port states, RSTP and Rapid PVST+