5.4 STP in the Campus Network
5.4.3 Configure the port cost
Path cost is the sum of costs between a switch and the root. STP calculates path cost based on the media speed of the links between switches and the port cost of each port forwarding frames.

If you want to change the path of frames between a particular switch and the root, carefully calculate the current path cost, and then change the port costs of the desired path. Make sure that you calculate the sum of potential alternate paths in addition to the desired path before making changes. This ensures a proper assessment of path costs prior to making port-cost changes and that frames are forwarded over the chosen path ports.

Assign lower numbers to ports attached to faster media (such as full duplex) and higher numbers to ports attached to slower media. The possible range is 1 to 65535. The default differs for different media. Path cost is typically 1000 divided by LAN speed in Mbps.

To change the port cost for a port on a set-command-based switch, enter the set spantree portcost mod-num/port-num cost command in privileged mode.

The following is an example of entering the set spantree portcost 2/1 command. (see Figure)

Switch> (enable) set spantree portcost 2/1 10
Spantree port 2/1 path cost set to 10.

Verify the port-cost setting by entering the show spantree [mod-num/port-num] command in privileged mode as shown in the Figure. The console returns a display similar to the previously entered command for verifying port priority.

To change the port cost for a port on a Cisco IOS command-based switch, enter the following command in interface configuration mode

Switch(config-if)#spantree cost cost-value

where cost-value is a numeric value within the range of 1 to 65535. To return the path cost for an interface to the default value, enter the no spantree cost command in interface configuration mode.