On this page 34 sections
- What OSPF is
- Core OSPF concepts
- Start an OSPF process
- Configure the router ID
- How IOS selects a router ID
- Activate OSPF with network statements
- Activate OSPF directly on an interface
- Wildcard masks in OSPF
- Passive interfaces
- OSPF neighbor requirements
- OSPF neighbor states
- DR and BDR election
- Point-to-point network type
- OSPF hello and dead timers
- OSPF cost
- Reference bandwidth
- Advertise a default route
- Understand OSPF route codes
- Lab 1 topology — single-area OSPF
- Lab 1 — configure R1
- Lab 1 — configure R2
- Lab 1 — configure R3
- Lab 1 — verify neighbors and routes
- Lab 1 — diagnose a passive transit interface
- Lab 2 topology — multi-area OSPF
- Lab 2 — configure R1 and R2
- Lab 2 — configure R3 and R4
- Lab 3 — advertise an Internet default
- Change path selection in a lab
- Troubleshoot missing neighbors
- Troubleshoot missing routes
- Remove OSPF configuration
- OSPF verification quick reference
- Common OSPF mistakes
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.
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.
Start an OSPF process
The process ID is locally significant. Neighboring routers do not need the same process ID.
The command enters OSPF router configuration mode but does not yet activate OSPF on an interface.
router ospf 1Configure the router ID
Set the router ID manually so it remains predictable. It uses dotted-decimal notation but does not need to be assigned to an interface.
If the OSPF process is already active, changing the configured router ID requires a process restart or device reload before it takes effect.
This temporarily removes OSPF adjacencies, so use it carefully in production.
router ospf 1
router-id 1.1.1.1clear ip ospf processHow 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.
Activate OSPF with network statements
The OSPF network command does not directly advertise an arbitrary network. It matches local interface IPv4 addresses. Matching interfaces run OSPF and their connected prefixes are included in OSPF.
The second form is precise and avoids accidentally enabling OSPF on another interface in the same subnet range.
router ospf 1
network 192.168.10.0 0.0.0.255 area 0router ospf 1
network 10.0.12.1 0.0.0.0 area 0Activate OSPF directly on an interface
IOS also supports interface-level activation. This avoids wildcard matching.
Use either method consistently. Verification commands show the resulting OSPF-enabled interfaces regardless of how they were activated.
interface GigabitEthernet0/0
ip ospf 1 area 0Wildcard masks in OSPF
The network statement uses a wildcard mask. A zero bit must match, while a one bit is ignored.
/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.255Passive interfaces
A passive interface advertises its connected network without sending OSPF hello packets or forming neighbors on that interface. LAN interfaces facing end devices should normally be passive.
A scalable approach is to make every interface passive by default and explicitly enable neighbor formation only on router-to-router links.
router ospf 1
passive-interface GigabitEthernet0/0router ospf 1
passive-interface default
no passive-interface GigabitEthernet0/1OSPF 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.
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.
show ip ospf neighborDR and BDR election
On broadcast multiaccess networks, OSPF elects a Designated Router and Backup Designated Router to reduce the number of adjacencies.
The highest interface priority wins. A priority of 0 makes an interface ineligible. Ties are resolved by the highest router ID.
An election is not automatically preemptive. Changing priority does not necessarily replace an existing DR until a new election occurs.
interface GigabitEthernet0/1
ip ospf priority 100Point-to-point network type
On a direct router-to-router Ethernet link, point-to-point network type removes the need for DR and BDR election.
Both ends should use compatible network types and timers.
interface GigabitEthernet0/1
ip ospf network point-to-pointOSPF hello and dead timers
Timers must match between neighbors. Defaults depend on the OSPF network type.
Configure matching values at both ends. Default timers are normally preferable unless a design requirement justifies changing them.
show ip ospf interface GigabitEthernet0/1interface GigabitEthernet0/1
ip ospf hello-interval 5
ip ospf dead-interval 20OSPF 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.
show ip ospf interface briefinterface GigabitEthernet0/1
ip ospf cost 10Reference bandwidth
The traditional reference bandwidth of 100 Mbps makes Fast Ethernet and faster links appear to have the same minimum cost. Increase it consistently on every OSPF router in the domain.
The value is expressed in Mbps. Inconsistent reference bandwidth does not stop neighbors from forming but can produce asymmetric or unexpected path selection.
router ospf 1
auto-cost reference-bandwidth 100000Advertise a default route
default-information originate advertises a default route only when one already exists in the local routing table.
Use always deliberately because advertising an unusable default can create a black hole.
ip route 0.0.0.0 0.0.0.0 203.0.113.1
router ospf 1
default-information originaterouter ospf 1
default-information originate alwaysUnderstand 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.
show ip route ospfLab 1 topology — single-area OSPF
All router-to-router links and LANs belong to area 0.
Configure the interface addresses and verify directly connected pings before enabling OSPF.
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/24Lab 1 — configure R1
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 0Lab 1 — configure R2
R2 forms a neighbor relationship on both transit interfaces and has no end-user LAN in this topology.
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 0Lab 1 — configure R3
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 0Lab 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.
show ip ospf neighbor
show ip ospf interface brief
show ip protocols
show ip route ospf
show ip ospf databaseping 192.168.30.1 source 192.168.10.1
traceroute 192.168.30.1 source 192.168.10.1Lab 1 — diagnose a passive transit interface
Start with the working three-router topology. On R1, record the neighbor state for R2 and confirm that 192.168.30.0/24 is learned through OSPF. In the lab, make the interface toward R2 passive under OSPF process 1, then check the same two outputs again.
The R1–R2 interface should stay up/up and R1 should still reach R2's directly connected address. After the adjacency drops, R2 should disappear from R1's neighbor table and the remote LAN should disappear from R1's OSPF routes. If the link is up and the transit interface appears in the passive-interface list, start with the OSPF interface configuration.
Restore no passive-interface GigabitEthernet0/1 under router ospf 1 on R1, adjusting the interface name to match the lab. Confirm that the adjacency returns to FULL, the remote prefix reappears and the ping to 192.168.30.1 sourced from 192.168.10.1 succeeds.
show ip interface brief
show ip protocols
show ip ospf neighbor
show ip route ospfLab 2 topology — multi-area OSPF
R2 is an Area Border Router between area 10 and the backbone. R3 is an Area Border Router between the backbone and area 20.
Every non-backbone area should connect to area 0 through an ABR in a normal hierarchical design.
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 20Lab 2 — configure R1 and R2
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 10router 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 0Lab 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.
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 20router 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 20show ip ospf
show ip ospf border-routers
show ip route ospf
show ip ospf database summaryLab 3 — advertise an Internet default
Assume R3 connects to an ISP through GigabitEthernet0/2 and uses next hop 203.0.113.1. R3 installs a static default and originates it into OSPF.
The default normally appears as an OSPF external route, commonly O*E2 with default settings.
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 originateshow ip route 0.0.0.0
show ip route ospfChange path selection in a lab
When two routes exist to the same prefix, modify interface cost to see OSPF choose the lower accumulated metric.
interface GigabitEthernet0/1
ip ospf cost 100show ip route 192.168.40.0
show ip ospf interface brief
traceroute 192.168.40.1Troubleshoot missing neighbors
Start at Layers 1 and 2, verify IP addressing, then inspect OSPF-specific parameters on both ends.
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.
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 ospfTroubleshoot missing routes
A full neighbor relationship does not guarantee that every expected prefix is being advertised.
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.
show ip route
show ip route ospf
show ip ospf interface brief
show ip ospf database
show ip protocolsRemove OSPF configuration
Removing the routing process deletes its OSPF configuration and learned OSPF routes.
To disable OSPF only on an interface configured with interface-level syntax, remove that interface command instead.
no router ospf 1interface GigabitEthernet0/0
no ip ospf 1 area 0OSPF verification quick reference
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 protocolsCommon OSPF mistakes
- Using the subnet mask instead of the wildcard mask in a
networkstatement. - 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.