All routing protocols need a method of deciding which routes are better than others in the event that more than one route to a network exists. OSPF uses the bandwidth of the links in the routing path to calculate its metric, known as cost. However, it is sometimes useful to manipulate the cost of a link, of which there are two methods.
The most granular method to change the cost of a particular route is to set the cost of a link manually. In this instance, OSPF forgoes the trouble of calculating the cost on a link itself and uses your set value. Where do we set this link cost value I hear you cry? In interface configuration mode, of course.
Router(config-if)#ip ospf cost <value>
The value is any integer in the range 1-65535. It should be mentioned at this point that lower is better. Note also that this wont 'reset' the cost of a route to reach a network, only add your custom value to it. This means that if one link along the route to the network has a ludicrously high cost, then even with this value set the cost will still be high.
The other method to manipulate the cost value of links is to change one of the variables in the OSPF cost calculation. Shown below is the equation used by OSPF to calculate cost. The reference bandwidth is an integer in the range 1-4294967, and represends bandwidth in megabits per second. The default value is 100, and this is the value we look to change.
The second variable in the calculation is the configured bandwidth of the interface. By default, this value is set based on the interface type e.g. fast ethernet interfaces will have a bandwidth of 100 megabits per second. The bandwidth value of an interface can be changed using the bandwidth command from interface configuration mode. More on that in a bit.
As changing the reference bandwidth is a global change, we do it from OSPF configuration mode.
Router(config-router)#auto-cost reference-bandwidth <value>
We set the value to an integer between 1-4294967 inclusive which represents a speed in megabits per second, and now all OSPF calculations will be based on this new value.
It is also possible to change the bandwidth value on individual interfaces using the bandwidth interface configuration mode command. This technique of manipulating the OSPF cost calculation should be avoided however as the bandwidth value of the interface is also used in other calculations, such as quality of service (QoS) and other routing protocols (EIGRP).
The value is an integer in the range 1 to 10,000,000, representing the bandiwdth of the interface in kilobits per second.