On this page 33 sections
  1. What OSPF is
  2. Core OSPF concepts
  3. Start an OSPF process
  4. Configure the router ID
  5. How IOS selects a router ID
  6. Activate OSPF with network statements
  7. Activate OSPF directly on an interface
  8. Wildcard masks in OSPF
  9. Passive interfaces
  10. OSPF neighbor requirements
  11. OSPF neighbor states
  12. DR and BDR election
  13. Point-to-point network type
  14. OSPF hello and dead timers
  15. OSPF cost
  16. Reference bandwidth
  17. Advertise a default route
  18. Understand OSPF route codes
  19. Lab 1 topology — single-area OSPF
  20. Lab 1 — configure R1
  21. Lab 1 — configure R2
  22. Lab 1 — configure R3
  23. Lab 1 — verify neighbors and routes
  24. Lab 2 topology — multi-area OSPF
  25. Lab 2 — configure R1 and R2
  26. Lab 2 — configure R3 and R4
  27. Lab 3 — advertise an Internet default
  28. Change path selection in a lab
  29. Troubleshoot missing neighbors
  30. Troubleshoot missing routes
  31. Remove OSPF configuration
  32. OSPF verification quick reference
  33. Common OSPF mistakes
01

What OSPF is

Open Shortest Path First is a link-state interior gateway protocol. Routers exchange link-state information, build a common topology database and calculate best paths with the Shortest Path First algorithm.

OSPFv2 carries IPv4 routes. OSPF uses IP protocol number 89 rather than TCP or UDP. Its administrative distance on Cisco IOS is 110.

02

Core OSPF concepts

  • Router ID: 32-bit value that identifies an OSPF router.
  • Neighbor: another OSPF router discovered on a common link.
  • Adjacency: synchronized OSPF relationship used to exchange LSAs.
  • LSA: link-state advertisement describing routing information.
  • LSDB: link-state database containing the area topology.
  • Area: logical OSPF subdivision. Area 0 is the backbone.
  • Cost: metric used to select the best path.
03

Start an OSPF process

The command enters OSPF router configuration mode but does not yet activate OSPF on an interface.

Start OSPF process 1
router ospf 1
04

Configure the router ID

This temporarily removes OSPF adjacencies, so use it carefully in production.

Configure a router ID
router ospf 1
 router-id 1.1.1.1
Restart the OSPF process
clear ip ospf process
05

How IOS selects a router ID

If no manual router ID is configured, IOS generally chooses the highest IPv4 address on an active loopback interface. If no loopback is available, it uses the highest IPv4 address on an active physical interface when the process starts.

Manual configuration is preferred because interface changes can otherwise make identification and troubleshooting less predictable.

06

Activate OSPF with network statements

The second form is precise and avoids accidentally enabling OSPF on another interface in the same subnet range.

Match a /24 interface in area 0
router ospf 1
 network 192.168.10.0 0.0.0.255 area 0
Match one exact interface address
router ospf 1
 network 10.0.12.1 0.0.0.0 area 0
07

Activate OSPF directly on an interface

Use either method consistently. Verification commands show the resulting OSPF-enabled interfaces regardless of how they were activated.

Enable OSPF on an interface
interface GigabitEthernet0/0
 ip ospf 1 area 0
08

Wildcard masks in OSPF

The network statement uses a wildcard mask. A zero bit must match, while a one bit is ignored.

Common OSPF wildcard masks
/32  0.0.0.0
/30  0.0.0.3
/29  0.0.0.7
/28  0.0.0.15
/27  0.0.0.31
/26  0.0.0.63
/25  0.0.0.127
/24  0.0.0.255
/16  0.0.255.255
09

Passive interfaces

A scalable approach is to make every interface passive by default and explicitly enable neighbor formation only on router-to-router links.

Make one interface passive
router ospf 1
 passive-interface GigabitEthernet0/0
Passive by default
router ospf 1
 passive-interface default
 no passive-interface GigabitEthernet0/1
10

OSPF neighbor requirements

Routers normally require the following to form an adjacency:

  • Interfaces share an IP subnet and can exchange protocol 89 traffic.
  • OSPF is active on both interfaces.
  • Both interfaces belong to the same OSPF area.
  • Hello and dead intervals match.
  • Authentication parameters match when authentication is enabled.
  • Stub area flags match.
  • Router IDs are unique.
  • MTU mismatches do not prevent database synchronization.

The OSPF process IDs and interface IP addresses do not need to be identical.

11

OSPF neighbor states

Common states include DOWN, INIT, 2-WAY, EXSTART, EXCHANGE, LOADING and FULL.

On Ethernet broadcast networks, DROTHER routers may remain in 2-WAY with each other while becoming FULL with the DR and BDR. A persistent EXSTART or EXCHANGE state often points to an MTU or database-exchange problem.

Display neighbors
show ip ospf neighbor
12

DR and BDR election

An election is not automatically preemptive. Changing priority does not necessarily replace an existing DR until a new election occurs.

Set OSPF interface priority
interface GigabitEthernet0/1
 ip ospf priority 100
13

Point-to-point network type

Both ends should use compatible network types and timers.

Set point-to-point OSPF type
interface GigabitEthernet0/1
 ip ospf network point-to-point
14

OSPF hello and dead timers

Configure matching values at both ends. Default timers are normally preferable unless a design requirement justifies changing them.

Inspect interface timers
show ip ospf interface GigabitEthernet0/1
Configure custom timers
interface GigabitEthernet0/1
 ip ospf hello-interval 5
 ip ospf dead-interval 20
15

OSPF cost

OSPF selects the path with the lowest accumulated cost. On Cisco IOS, interface cost is derived from reference bandwidth divided by interface bandwidth, unless an explicit cost is configured.

Display calculated cost
show ip ospf interface brief
Configure explicit interface cost
interface GigabitEthernet0/1
 ip ospf cost 10
16

Reference bandwidth

The value is expressed in Mbps. Inconsistent reference bandwidth does not stop neighbors from forming but can produce asymmetric or unexpected path selection.

Use a 100 Gbps reference
router ospf 1
 auto-cost reference-bandwidth 100000
17

Advertise a default route

Use always deliberately because advertising an unusable default can create a black hole.

Create and advertise a static default route
ip route 0.0.0.0 0.0.0.0 203.0.113.1
router ospf 1
 default-information originate
Advertise a default even without one
router ospf 1
 default-information originate always
18

Understand OSPF route codes

Common Cisco routing-table codes include:

  • O: intra-area route learned inside the same area.
  • O IA: inter-area route learned through an Area Border Router.
  • O E1: external route including external and internal OSPF cost.
  • O E2: external route using the external metric; this is the common default external type.
Display only OSPF routes
show ip route ospf
19

Lab 1 topology — single-area OSPF

Configure the interface addresses and verify directly connected pings before enabling OSPF.

Lab 1 topology and addressing
LAN 10          R1             R2             R3          LAN 30
192.168.10.0/24 --- 10.0.12.0/30 --- 10.0.23.0/30 --- 192.168.30.0/24

R1 G0/0  192.168.10.1/24
R1 G0/1  10.0.12.1/30
R2 G0/0  10.0.12.2/30
R2 G0/1  10.0.23.1/30
R3 G0/0  10.0.23.2/30
R3 G0/1  192.168.30.1/24
20

Lab 1 — configure R1

R1 interfaces and OSPF
interface GigabitEthernet0/0
 ip address 192.168.10.1 255.255.255.0
 no shutdown
interface GigabitEthernet0/1
 ip address 10.0.12.1 255.255.255.252
 no shutdown

router ospf 1
 router-id 1.1.1.1
 passive-interface default
 no passive-interface GigabitEthernet0/1
 network 192.168.10.0 0.0.0.255 area 0
 network 10.0.12.0 0.0.0.3 area 0
21

Lab 1 — configure R2

R2 forms a neighbor relationship on both transit interfaces and has no end-user LAN in this topology.

R2 interfaces and OSPF
interface GigabitEthernet0/0
 ip address 10.0.12.2 255.255.255.252
 no shutdown
interface GigabitEthernet0/1
 ip address 10.0.23.1 255.255.255.252
 no shutdown

router ospf 1
 router-id 2.2.2.2
 passive-interface default
 no passive-interface GigabitEthernet0/0
 no passive-interface GigabitEthernet0/1
 network 10.0.12.0 0.0.0.3 area 0
 network 10.0.23.0 0.0.0.3 area 0
22

Lab 1 — configure R3

R3 interfaces and OSPF
interface GigabitEthernet0/0
 ip address 10.0.23.2 255.255.255.252
 no shutdown
interface GigabitEthernet0/1
 ip address 192.168.30.1 255.255.255.0
 no shutdown

router ospf 1
 router-id 3.3.3.3
 passive-interface default
 no passive-interface GigabitEthernet0/0
 network 10.0.23.0 0.0.0.3 area 0
 network 192.168.30.0 0.0.0.255 area 0
23

Lab 1 — verify neighbors and routes

R1 should have one full neighbor, R2 should have two and R3 should have one. R1 should learn LAN 30 as O, and R3 should learn LAN 10 as O.

Verify OSPF operation
show ip ospf neighbor
show ip ospf interface brief
show ip protocols
show ip route ospf
show ip ospf database
Test end-to-end connectivity
ping 192.168.30.1 source 192.168.10.1
traceroute 192.168.30.1 source 192.168.10.1
24

Lab 2 topology — multi-area OSPF

Every non-backbone area should connect to area 0 through an ABR in a normal hierarchical design.

Lab 2 area topology
LAN 10        R1       area 10       R2       area 0       R3       area 20       R4        LAN 40
192.168.10.0/24 -- 10.0.12.0/30 -- 10.0.23.0/30 -- 10.0.34.0/30 -- 192.168.40.0/24

R1-R2: area 10
R2-R3: area 0
R3-R4: area 20
25

Lab 2 — configure R1 and R2

R1 area 10
router ospf 1
 router-id 1.1.1.1
 passive-interface default
 no passive-interface GigabitEthernet0/1
 network 192.168.10.0 0.0.0.255 area 10
 network 10.0.12.0 0.0.0.3 area 10
R2 areas 10 and 0
router ospf 1
 router-id 2.2.2.2
 passive-interface default
 no passive-interface GigabitEthernet0/0
 no passive-interface GigabitEthernet0/1
 network 10.0.12.0 0.0.0.3 area 10
 network 10.0.23.0 0.0.0.3 area 0
26

Lab 2 — configure R3 and R4

R1 should learn area 0 and area 20 prefixes as O IA. R4 should learn area 0 and area 10 prefixes as O IA.

R3 areas 0 and 20
router ospf 1
 router-id 3.3.3.3
 passive-interface default
 no passive-interface GigabitEthernet0/0
 no passive-interface GigabitEthernet0/1
 network 10.0.23.0 0.0.0.3 area 0
 network 10.0.34.0 0.0.0.3 area 20
R4 area 20
router ospf 1
 router-id 4.4.4.4
 passive-interface default
 no passive-interface GigabitEthernet0/0
 network 10.0.34.0 0.0.0.3 area 20
 network 192.168.40.0 0.0.0.255 area 20
Verify areas and inter-area routes
show ip ospf
show ip ospf border-routers
show ip route ospf
show ip ospf database summary
27

Lab 3 — advertise an Internet default

The default normally appears as an OSPF external route, commonly O*E2 with default settings.

Configure the OSPF default source on R3
interface GigabitEthernet0/2
 ip address 203.0.113.2 255.255.255.252
 no shutdown
ip route 0.0.0.0 0.0.0.0 203.0.113.1
router ospf 1
 default-information originate
Verify the learned default on another router
show ip route 0.0.0.0
show ip route ospf
28

Change path selection in a lab

When two routes exist to the same prefix, modify interface cost to see OSPF choose the lower accumulated metric.

Increase one link cost
interface GigabitEthernet0/1
 ip ospf cost 100
Compare the selected route
show ip route 192.168.40.0
show ip ospf interface brief
traceroute 192.168.40.1
29

Troubleshoot missing neighbors

Check for shutdown interfaces, different subnets, area mismatch, passive transit interfaces, timer mismatch, authentication mismatch, duplicate router IDs, incompatible network types, ACL filtering of protocol 89 and MTU problems.

Neighbor troubleshooting checklist
show ip interface brief
show interfaces GigabitEthernet0/1
show ip ospf neighbor
show ip ospf interface GigabitEthernet0/1
show ip protocols
show running-config | section router ospf
30

Troubleshoot missing routes

Confirm that the local interface is up, OSPF is active on it, the intended area is correct and the prefix appears in the LSDB. Also check whether a better route from another source already exists.

Route troubleshooting checklist
show ip route
show ip route ospf
show ip ospf interface brief
show ip ospf database
show ip protocols
31

Remove OSPF configuration

To disable OSPF only on an interface configured with interface-level syntax, remove that interface command instead.

Remove process 1
no router ospf 1
Disable interface-level OSPF
interface GigabitEthernet0/0
 no ip ospf 1 area 0
32

OSPF verification quick reference

Essential show commands
show ip ospf
show ip ospf neighbor
show ip ospf interface brief
show ip ospf interface
show ip ospf database
show ip route ospf
show ip protocols
33

Common OSPF mistakes

  • Using the subnet mask instead of the wildcard mask in a network statement.
  • Assuming the process ID must match between routers.
  • Reusing the same router ID on multiple routers.
  • Assigning opposite ends of a link to different areas.
  • Leaving a transit interface passive.
  • Forming neighbors on end-user LANs unnecessarily.
  • Forgetting that area 0 is the backbone in a multi-area design.
  • Changing timers, MTU or network type on only one side.
  • Advertising a default without verifying that the exit route works.
  • Changing reference bandwidth on only some routers.