๐ŸŽฏ Lab Objectives

  • Understand why Layer 2 loops are catastrophic
  • Explain how STP elects a root bridge using BID
  • Identify root, designated, and non-designated port roles
  • Configure the root bridge manually for predictable topology
  • Compare STP (802.1D) with RSTP (802.1w) convergence

Step 1 โ€” Why STP Exists

# Without STP, redundant switch links cause broadcast storms
SW1 โ”€โ”€โ”€ SW2
 โ”‚         โ”‚
 โ””โ”€โ”€โ”€ SW3 โ”€โ”˜

PC sends a broadcast:
โ†’ SW1 floods to SW2 and SW3
โ†’ SW2 floods it back to SW3
โ†’ SW3 floods back to SW1 and SW2
โ†’ LOOP: infinite broadcast storm โ†’ network crash!

# STP fixes this by:
# 1. Electing a ROOT BRIDGE (central switch)
# 2. Finding the BEST PATH to root from every switch
# 3. BLOCKING redundant paths (ports in blocking state)

# STP versions:
802.1D  โ†’ Original STP (30-50 second convergence โ€” very slow)
802.1w  โ†’ RSTP - Rapid STP (1-2 second convergence โ€” modern standard)
802.1s  โ†’ MSTP - Multiple STP (different trees per VLAN group)
PVST+   โ†’ Cisco's STP per VLAN (runs separate STP instance per VLAN)

Step 2 โ€” Root Bridge Election

# Root Bridge = switch with LOWEST Bridge ID (BID)
# BID = Priority (4 bits) + VLAN ID (12 bits) + MAC Address (48 bits)

# Default priority: 32768 (+ VLAN ID)
SW1: Priority 32769 (32768 + VLAN1), MAC: AA:AA:AA:AA:AA:01
SW2: Priority 32769 (32768 + VLAN1), MAC: BB:BB:BB:BB:BB:02
SW3: Priority 32769 (32768 + VLAN1), MAC: CC:CC:CC:CC:CC:03

# All same priority โ†’ lowest MAC wins root bridge
# SW1 wins (AA < BB < CC)

# Switches send BPDUs (Bridge Protocol Data Units) every 2 seconds
# to exchange BID information and agree on root bridge

# Show which switch is root bridge:
show spanning-tree vlan 1
Root ID    Priority    32769
           Address     aabb.cc01.0000
           This bridge is the root    โ† You are root!

Bridge ID  Priority    32769
           Address     aabb.cc01.0000

Step 3 โ€” Port Roles

# Every switch port has a ROLE in STP:

Root Port (RP):
  โ†’ One per non-root switch
  โ†’ The port with the BEST (lowest cost) path to the root bridge
  โ†’ FORWARDING state

Designated Port (DP):
  โ†’ Best port on each network segment for traffic to/from root
  โ†’ Root bridge: ALL ports are designated
  โ†’ FORWARDING state

Non-Designated Port (NDP) / Alternate Port:
  โ†’ Redundant paths โ€” BLOCKED to prevent loops
  โ†’ BLOCKING state (still receives BPDUs, just doesn't forward data)

# Port cost (bandwidth โ†’ cost):
10 Mbps   โ†’ 100
100 Mbps  โ†’ 19
1 Gbps    โ†’ 4
10 Gbps   โ†’ 2

# Root path cost = sum of port costs from root to this switch

Step 4 โ€” Port States (802.1D STP)

# STP port state machine (this is why convergence is slow):

Blocking   (15 sec) โ†’ Listening (15 sec) โ†’ Learning (15 sec) โ†’ Forwarding
                                                                    โ”‚
                                                     Total: ~30-50 seconds

# State descriptions:
Blocking   โ†’ receives BPDUs only, no data forwarding
Listening  โ†’ processes BPDUs, no data, no MAC learning
Learning   โ†’ processes BPDUs, no data, LEARNS MAC addresses
Forwarding โ†’ normal operation โ€” forwards data AND learns MACs
Disabled   โ†’ administratively shut down

# Timers:
Hello Time    = 2 sec  (how often BPDUs are sent)
Max Age       = 20 sec (how long to wait before reconverging)
Forward Delay = 15 sec (time in Listening and Learning states each)

Step 5 โ€” Configure Root Bridge

# Method 1: Set priority manually (multiples of 4096)
spanning-tree vlan 1 priority 4096    # lower than default 32768 โ†’ becomes root
spanning-tree vlan 1 priority 0       # absolute lowest priority

# Method 2: Use the macro (sets to 24576 or adjusts automatically)
spanning-tree vlan 1 root primary     # make this the root
spanning-tree vlan 1 root secondary   # make this the backup root

# Verify
show spanning-tree vlan 1
Root ID    Priority    4097
           Address     aabb.cc00.0100
           This bridge is the root

# Change port cost (influence root port selection)
interface GigabitEthernet0/1
 spanning-tree vlan 1 cost 10   # lower cost = preferred path

# Change port priority (0-240, default 128, lower = preferred)
interface GigabitEthernet0/1
 spanning-tree vlan 1 port-priority 64

Step 6 โ€” RSTP (802.1w)

# RSTP = Rapid STP โ€” same algorithm but MUCH faster (1-2 seconds)

# Enable RSTP (modern Cisco switches run PVST+ by default)
spanning-tree mode rapid-pvst    # recommended for modern networks

# RSTP improvements over STP:
Only 3 port states (not 5): Discarding, Learning, Forwarding
New port roles: Alternate (backup to root port), Backup
Edge ports (formerly PortFast) transition immediately to Forwarding
Faster convergence via Proposal/Agreement handshake

# PortFast: skip Listening/Learning on access ports (hosts, printers)
interface GigabitEthernet0/1
 spanning-tree portfast          # immediate forwarding for access ports

# BPDU Guard: if a PortFast port receives a BPDU โ†’ shut it down
# Protects against someone plugging in an unauthorized switch
interface GigabitEthernet0/1
 spanning-tree bpduguard enable

Step 7 โ€” STP Security Features

# Enable PortFast + BPDU Guard globally on all access ports
spanning-tree portfast default           # PortFast on all access ports
spanning-tree portfast bpduguard default # BPDU Guard on all portfast ports

# Root Guard: prevent downstream switches from becoming root bridge
interface GigabitEthernet0/2
 spanning-tree guard root        # if superior BPDU received โ†’ port blocked

# BPDU Filter: suppress BPDUs on a port (use carefully)
interface GigabitEthernet0/1
 spanning-tree bpdufilter enable

# Verification commands:
show spanning-tree                    # all VLANs STP info
show spanning-tree vlan 1             # VLAN 1 only
show spanning-tree interface Gi0/1    # per-interface detail
show spanning-tree summary            # counts per VLAN

# Debug (use in lab only โ€” noisy!)
debug spanning-tree events
โœ…
Lab Complete! STP is a guaranteed CCNA exam topic. Focus on: BID election (lowest wins), root port selection (lowest path cost), and why PortFast + BPDU Guard together are the standard access port config.
Related: VLAN Lab โ†’ โ† All Labs
// guided terminal

Try It Live

Type the commands from the steps above. The terminal simulates the expected output for this lab.

KaliRange ~ Terminal type help for commands