PacketLab
OSPF · Database and path selection

Cost and ECMP

Use consistent cost policy and verify equal next hops without promising equal traffic.

Understand

Automatic interface cost is based on reference bandwidth divided by interface bandwidth, with a minimum cost of 1 on common router implementations. A legacy 100-Mbps reference collapses 100-Mbps, 1-Gbps and 10-Gbps links to cost 1. Configure a consistent reference across the domain when using automatic costs; it does not negotiate through Hellos.

An explicit ip ospf cost overrides automatic calculation. Our baselines use explicit costs, so changing only auto-cost reference-bandwidth will not change them. Equal-cost multipath installs eligible equal routes up to maximum-paths and platform limits. Forwarding often hashes flows; two next hops do not imply a 50/50 byte split or per-packet alternation.

Lab setup

Use a fresh lab for this lesson; changes from other lessons are not cumulative. All outputs are illustrative excerpts, not recorded router tests. Transit cost is explicitly 10 and Loopback0 cost is 1. Interface names may vary by image.

Lab topologyIllustrative topology
192.0.2.0/30area 0192.0.2.4/30area 0192.0.2.8/30area 0R1Lo0 · 10.255.0.1/32R2Lo0 · 10.255.0.2/32R3Lo0 · 10.255.0.3/32
Solid lines are physical links, configured as point-to-point. Interfaces and areas are listed below. Router symbol: GNS3, GPL-2.0. Original layout.
RouterInterfaceIPv4 addressArea
R1Gi1192.0.2.1/300
R2Gi1192.0.2.2/300
R1Gi2192.0.2.5/300
R3Gi1192.0.2.6/300
R2Gi2192.0.2.9/300
R3Gi2192.0.2.10/300

Loopback0 is 10.255.0.<router number>/32; area assignments: R1: area 0, R2: area 0, R3: area 0.

Complete baseline configurations

R1

Configuration
configure terminal
hostname R1
router ospf 1
 router-id 10.255.0.1
 passive-interface Loopback0
 exit
interface Loopback0
 ip address 10.255.0.1 255.255.255.255
 ip ospf 1 area 0
 ip ospf cost 1
 exit
interface GigabitEthernet1
 ip address 192.0.2.1 255.255.255.252
 ip ospf network point-to-point
 ip ospf cost 10
 ip ospf 1 area 0
 no shutdown
 exit
interface GigabitEthernet2
 ip address 192.0.2.5 255.255.255.252
 ip ospf network point-to-point
 ip ospf cost 10
 ip ospf 1 area 0
 no shutdown
 exit
end

R2

Configuration
configure terminal
hostname R2
router ospf 1
 router-id 10.255.0.2
 passive-interface Loopback0
 exit
interface Loopback0
 ip address 10.255.0.2 255.255.255.255
 ip ospf 1 area 0
 ip ospf cost 1
 exit
interface GigabitEthernet1
 ip address 192.0.2.2 255.255.255.252
 ip ospf network point-to-point
 ip ospf cost 10
 ip ospf 1 area 0
 no shutdown
 exit
interface GigabitEthernet2
 ip address 192.0.2.9 255.255.255.252
 ip ospf network point-to-point
 ip ospf cost 10
 ip ospf 1 area 0
 no shutdown
 exit
end

R3

Configuration
configure terminal
hostname R3
router ospf 1
 router-id 10.255.0.3
 passive-interface Loopback0
 exit
interface Loopback0
 ip address 10.255.0.3 255.255.255.255
 ip ospf 1 area 0
 ip ospf cost 1
 exit
interface GigabitEthernet1
 ip address 192.0.2.6 255.255.255.252
 ip ospf network point-to-point
 ip ospf cost 10
 ip ospf 1 area 0
 no shutdown
 exit
interface GigabitEthernet2
 ip address 192.0.2.10 255.255.255.252
 ip ospf network point-to-point
 ip ospf cost 10
 ip ospf 1 area 0
 no shutdown
 exit
end

Apply

Make the direct R1→R3 transit cost 20, equal to the two-link path via R2. Allow two next hops.

R1

Configuration
configure terminal
router ospf 1
 maximum-paths 2
 exit
interface GigabitEthernet2
 ip ospf cost 20
end

Verify and interpret

Illustrative output · excerpt
R1# show ip route 10.255.0.3
Routing entry for 10.255.0.3/32
  Known via "ospf 1", distance 110, metric 21, type intra area
  * 192.0.2.2, via GigabitEthernet1
  * 192.0.2.6, via GigabitEthernet2

Both paths total 21 including R3’s loopback. A single ping flow may use just one next hop.

For a separate automatic-cost experiment, restore the fresh triangle, remove explicit transit costs on every router, and apply the following reference on every router. Verify each interface’s configured bandwidth and resulting OSPF cost; changing bandwidth metadata does not change physical line speed.

Every router · automatic-cost experiment

Configuration
configure terminal
router ospf 1
 auto-cost reference-bandwidth 10000
 exit
interface GigabitEthernet1
 no ip ospf cost
 exit
interface GigabitEthernet2
 no ip ospf cost
end

For a 1-Gbps interface with 10000-Mbps reference, expected cost is 10; for 10-Gbps it is 1. Restore the complete explicit-cost baseline before another lesson.

Technical references

OSPFv2 standard · Router configuration guide

Key Takeaways

  • Use one deliberate reference-bandwidth policy.
  • Explicit interface cost overrides automatic cost.
  • ECMP needs equal total path costs and an adequate path limit.
  • ECMP does not guarantee equal bytes across links.
  • Check actual interface bandwidth and installed next hops.

Cost and ECMP Quiz

Six questions · four options each · select one answer per question. Submit all answers to see your score and explanations.

1. What overrides automatic cost?
2. What cost gives direct/via-R2 equality here?
3. How many next hops does maximum-paths 2 allow here?
4. Does ECMP guarantee 50/50 bytes?
5. With 10000-Mbps reference and 1000-Mbps bandwidth, cost is?
6. Does changing reference bandwidth alter our explicit costs?