OSPF builds a map for the network and applies Dijkstra’s algorithm in order to calculate the OSPF metric to reach every IP prefix in the SPF tree. Calculating a route’s metric requires knowing the OSPF cost of each outgoing interface included in the route.
In this tutorial, you will learn how OSPF cost gets calculated by default, and how you can configure it manually.
How OSPF Cost is Calculated?
By default, the OSPF cost of an interface equals the integer part of (OSPF Reference Bandwidth ) / (Link Bandwidth). For example, if the bandwidth is 1.544Mbps and the reference bandwidth is 100Mbps, then
(OSPF Reference Bandwidth ) / (Link Bandwidth) = 100Mbps/1.544Mbps= 64.77, and thus the corresponding cost is 64, the integer value of 64.77.
Link Bandwidth is the interface’s bandwidth used to route metrics whether in OSPF or EIGRP. If the bandwidth is greater than the OSPF reference bandwidth, OSPF sets the link cost to 1. The link cost ranges from 1 to 65535; the lowest the cost the faster the interface.
What is The Default OSPF Cost of a Router Interface?
By default, the reference bandwidth is 100Mbps on Cisco IOS, IOS XE, and IOS XR. Here are the default OSPF costs for different interface types.
|Interface Type||Default Bandwidth||OSPF Cost|
How to Configure OSPF Cost?
Cisco IOS offers three ways to configure the OSPF cost of an interface:
IP OSPF Cost Command
The ip ospf cost int_cost command configures the cost of an interface, where int_cost is between 1 and 655535. In the following example, we set the OSPF cost of the FastEthernet 0/0 interface to 555.
R5(config)# interface fastEthernet 0/0 R5(config-if)# ip ospf cost 555
To verify your configuration, use the show ip ospf interface command in enable mode, as shown in the next example.
R5# show ip ospf interface fastEthernet 0/0 FastEthernet0/0 is up, line protocol is up Internet Address 10.0.15.5/24, Area 0 Process ID 1, Router ID 10.0.15.5, Network Type BROADCAST, Cost: 555 Enabled by interface config, including secondary ip addresses omitted output
If the ip ospf command is not applied to a particular interface, the cost gets calculated based on the OSPF reference bandwidth and the interface’s bandwidth. Therefore, you can change the cost of the interface by setting a new value for the bandwidth parameter using the bandwidth command.
The default OSPF cost of FastEthernet interfaces is 1. To change the cost to 10 using the bandwidth command, we have to set the interface’s bandwidth to 10Mbps. In this way, the resulting value of OSPF bandwidth/interface bandwidth equals 100Mbps/10Mbps=10.
In this example, we set the bandwidth of the F0/0 interface to 10 using the bandwidth 10000 statement. The command accepts one value in kbps.
R5(config)# interface fastEthernet 0/0 R5(config-if)# bandwidth 10000
To verify your configuration, use the show ip ospf interface command in enable mode, as shown in the following example.
R5# show ip ospf interface fastEthernet 0/0 FastEthernet0/0 is up, line protocol is up Internet Address 10.0.15.5/24, Area 0 Process ID 1, Router ID 10.0.15.5, Network Type BROADCAST, Cost: 10 Enabled by interface config, including secondary ip addresses omitted output
You can use the ip ospf cost and bandwidth commands to instruct OSPF to choose a particular path over another to reach a particular destination. Additionally, you can change OSPF cost to instruct OSPF to not load balance traffic across paths with the same metric.
While the ip ospf cost and bandwidth command may influence the current router to choose an interface over another to forward IP packets, the auto-cost command does not favor one router interface over another. However, it may only affect other routers’ OSPF routing decisions.
The auto-cost reference-bandwidth ref_dw command allows you to change the reference bandwidth value, which affects link cost calculations. ref_dw ranges from 1-4294967 Mbps. In this example, we set the reference-bandwidth to 100 Gigabits per second. In this way, the default OSPF cost of FastEthernet interfaces becomes 1000.
R5(config)# router ospf 1 R5(config-router)# auto-cost reference-bandwidth 100000
The show ip ospf interface command output below confirms our analysis.
R5# show ip ospf interface fastEthernet 0/0 FastEthernet0/0 is up, line protocol is up Internet Address 10.0.15.5/24, Area 0 Process ID 1, Router ID 10.0.15.5, Network Type BROADCAST, Cost: 1000 Enabled by interface config, including secondary ip addresses omitted output
Related Lessons to OSPF Cost
- OSPF Router ID
- OSPF Null Authentication
- OSPF Plain Text Authentication
- OSPF Default Route
- Basic OSPF Configuration Lab for CCNA
- OSPF Configuration
- OSPF Passive Interface
- OSPF Virtual Link
- OSPF Stub Area
- OSPF LSA Types
- OSPF Totally Stubby Area
- OSPF Reference Bandwidth
- OSPF Cost
- OSPF DR/BDR Election
- OSPF Hello and Dead Interval
- OSPF Metric
- OSPF MD5 Authentication
- OSPF HMAC-SHA Cryptographic Authentication
- OSPF Multi-Area
- OSPF TTL Security Check
- OSPF Graceful Shutdown
- Route Redistribution between OSPF and RIP
- OSPF Network Types
- OSPF Totally NSSA Area
- OSPF NSSA Area
- OSPF Summarization
- OSPF Route Filtering
- OSPF Type 5 LSA Filtering
- OSPF ABR Type 3 LSA Filtering
- OSPF Prefix Suppression
- OSPF Path Selection
- OSPF LSA Throttling
- OSPF SPF Throttling
- OSPF Incremental SPF
- OSPF Non-Broadcast Network Type
- OSPF Point-to-Point Network Type
- OSPF Broadcast Network Type
- OSPF Point-to-Multipoint Network Type
- OSPF vs RIP
- OSPF LSA Group Pacing
- OSPF LSA Flood Pacing
- OSPF LSA Retransmission Pacing