Cost
OSPF's metric is called cost.
It is automatically calculated based on the bandwidth (speed) of the interface.
It is calculated by dividing a reference bandwidth value by the interface's bandwidth.
The default reference bandwidth is 100 mbps.
Reference: 100 mbps / Interface: 10 mbps = cost of 10.
Reference: 100 mbps / Interface: 100 mbps = cost of 1.
Reference: 100 mbps / Interface: 1000 mbps = cost of 1??.
Reference: 100 mbps / Interface: 10000 mbps = cost of 1??.
All values less than 1 will be converted to 1.
Therefore FastEthernet, Gigabit Ethernet, 10Gig Ethernet, etc, are equal and all have a cost of 1 by default.
You can (and should!) change the reference bandwidth with this command.
The command is entered in megabits per seconds (defualt is 100).
100000 / 100 = cost of 1000 for FastEthernet.
100000 / 1000 = cost of 100 for GigEtherner.
You should configure a reference bandwidth greater thant the fastest links in your network (to allow for future upgrades).
You should configure the same references bandwidth on all OSPF routers in the network.
The OSPF cost to a destination is the total cost of the 'outgoing/exit interfaces'
For example, R1's cost to reach 192.168.4.0/24 is:
100 (R1 G0/0) + 100 (R2 G1/0) + 100 (R4 G1/0) = 300
Loopback interfaces have a cost of 1.
What is R1's const to reach 2.2.2.2 (R2's loopback0 interface)?
100 (R1 G1/0) + 1 (R2 L0) = 101
One more option to change the OSPF cost of an interface is to change the bandwidth of the interface with the bandwidth command.
The formula to calculate OSPF cost is reference bandwidth / interface bandwidth.
Although the bandwidth matches the interface speed by default, changing the interface bandwidth doesn't actually change the speed at which the interface operates.
The bandwidth is just a value that is used to calculate OSPF cost, EIGRP metric, etc.
To change the speed at which the interface operates, use the speed command.
Because the bandwidth value is used in other calculations, it is not recommended to change this value to alter the interface's OSPF cost.
It is recommended that you change the reference bandwidth, and then use the ip ospf cost command to change the cost of individual interfaces if you want.
Summary
Three ways to modify the OSPF cost:
Change the reference bandwidth:
Manual configuration
Change the interface bandwidth
Last updated