STP

Configuring Spanning Tree Protocol to prevent loops and optimize network topology

Configure Spanning Tree Protocol to prevent loops and optimize path selection in switched networks.

Step 1: Set the bridge priority to become root bridge Configure this switch as the root bridge by setting a lower bridge priority value.

1
2
3
4
SW1>enable
SW1#configure terminal
SW1(config)#spanning-tree vlan 1 priority 4096
SW1(config)#spanning-tree vlan 10,20,30 priority 4096

Step 2: Configure STP mode and features Enable Rapid Spanning Tree Protocol (RSTP) for faster convergence and configure PortFast for access ports. Portfast will bypass the listening and learning states to reach the forwarding state immediately.  It should only be configured on interfaces connected to a single host or switch (this far less common).

1
2
3
SW1(config)#spanning-tree mode rapid-pvst
SW1(config)#spanning-tree portfast default
SW1(config)#spanning-tree portfast bpduguard default

Step 3: Configure per-interface STP settings Set specific STP parameters on trunk and access interfaces.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SW1(config)#interface gigabitEthernet 0/1
SW1(config-if)#description Trunk to SW2
SW1(config-if)#spanning-tree port-priority 128
SW1(config-if)#spanning-tree cost 4
SW1(config-if)#exit

SW1(config)#interface range fastEthernet 0/1-24
SW1(config-if-range)#description Access ports
SW1(config-if-range)#spanning-tree portfast
SW1(config-if-range)#spanning-tree bpduguard enable
SW1(config-if-range)#exit

Step 4: Configure STP timers (optional) Adjust STP timers for faster convergence in small networks.

1
2
3
4
SW1(config)#spanning-tree vlan 1 hello-time 1
SW1(config)#spanning-tree vlan 1 forward-time 4
SW1(config)#spanning-tree vlan 1 max-age 8
SW1(config)#end

Step 5: Verify STP configuration

1
2
3
4
SW1#show spanning-tree
SW1#show spanning-tree summary
SW1#show spanning-tree interface gigabitEthernet 0/1
SW1#show spanning-tree root

Key Points:

  • Lower priority values = higher priority (0 is highest, 65535 is lowest)
  • Use multiples of 4096 for priority values
  • PortFast should only be enabled on access ports connecting to end devices
  • BPDU Guard shuts down ports receiving BPDUs when PortFast is enabled
  • Root bridge should be centrally located with highest bandwidth links