This is the feature that prevents infinite layer 2 loops among redundant links leading to broadcast storms.
This command will show who the root bridge is, this switch/bridge's priority, root status, role (designated, non-designated), and port cost for each interface:
SW3#show spanning-tree
VLAN0001
Filter the output to only show vlan 1:
SW3#show spanning-tree vlan 1
Show more details:
SW3#show spanning-tree detail
Fewer overall view but displays number of ports in various states:
SW3#show spanning-tree summary
NAME Blocking Listening Learning Forwarding STP Active
VLAN0001 0 0 0 4 4
Portfast is a feature that lets a a switch interface skip the listening/learning stages and go straight to forwarding state. The idea here is that the interface is connected to a PC, not a switch. If it isn't connected to a switch, there is no danger of a layer 2 infinite loop.
[Seems risky]
To enable portfast:
SW1(config-if)#spanning-tree portfast
To enable portfast on all access ports by default:
SW1(config)#spanning-tree portfast default
BPDU Guard makes this less risky. If an interface enabled with BPDU guard receives a BPDU from another switch, the interface will be shut down to prevent a loop from forming:
SW1(config)#int g0/2
SW1(config-if)#spanning-tree bpduguard enable
To enable BPDU guard by default:
SW1(config)#spanning-tree portfast bpduguard default
Configure which spanning-tree mode the switch uses:
SW1(config)#spanning-tree mode ?
mst Multiple spanning tree mode
pvst Per-Vlan spanning tree mode (Classic with Cisco's per Vlan addition)
rapid-pvst Per-vlan rapid spanning tree mode (Modern and improved per-Vlan spanning tree mode)
Rig a specific switch to act as the root bridge for vlan 1:
SW3(config)#spanning-tree vlan 1 root primary
^This command figures out the next lower priority (4096 less) for you so you don't have to calculate it.
Rig up a specific switch to act as a secondary:
SW2(config)#spanning-tree vlan 1 root secondary
Spanning Tree Costs:
STP - Cost
10 Mbps - 100
100 Mbps - 19
1 Gbps - 4
10 Gbps - 2
[These are my notes from Jeremy's excellent CCNA course which can be viewed here.]