STP (Spanning-Tree Protocol) protocol prevents switches to loop traffic between switches. A loop happens when there are a multiple paths to a destination and broadcast traffic goes on both directions looping between the original switch and two or more other switches. Spanning Tree Protocol implements the 802.1D IEEE algorithm by exchanging BPDU messages with other switches to detect and prevent loops, and then removes the loop by shutting down the redundant path when there is multiple paths.
In this diagram below, see there are 3 paths possible to the destination on switch 13, and 5 paths possible on switch 16. Note that single path is active when all the other links are in block mode. This is the function of STP in a network.
STP – Spanning Tree Protocol Commands
To enable STP on your switch, use:
sw1# conf t
sw1(config)# spanning-tree vlan 1
To show the STP details, use:
sw1#show spanning-tree details
You can select an specific switch to be the root bridge of specific VLan. To do this,use this command:
sw3(config)#spanning-tree vlan 2 root primary – This simply sets switch 3 to be the root bridge of VLAN 2.
Another way to select a root bridge for a specific VLAN is to set the switch priority lower by using the command below:
sw3(config)#spanning-tree vlan 2 priority 4096 – This changes the switch 3 priority for VLAN 2.