What is OSPF?
Open Shortest Path First is a link-state interior gateway protocol used within an autonomous system. Routers build a shared link-state database for an area, run the Shortest Path First algorithm and install the best routes into the routing table.
OSPFv2 is used for IPv4 and OSPFv3 is used for IPv6. OSPF packets run directly over IP using protocol number 89 rather than TCP or UDP.
OSPF hierarchy and areas
OSPF divides a large topology into areas to limit link-state flooding and SPF recalculation. Area 0 is the backbone. Other regular areas should connect to the backbone directly or through a carefully designed virtual link.
| Router role | Meaning |
|---|---|
| Internal router | All participating interfaces are in the same area. |
| Backbone router | Has at least one interface in Area 0. |
| Area Border Router (ABR) | Connects Area 0 to one or more non-backbone areas and maintains separate area databases. |
| Autonomous System Boundary Router (ASBR) | Redistributes routes from another routing domain or source into OSPF. |
Common area types
- Normal area: supports intra-area, inter-area and external routes.
- Stub area: blocks Type 5 external LSAs and normally receives a default route from the ABR.
- Totally stubby area: a vendor extension that additionally suppresses most inter-area summaries.
- NSSA: permits an internal ASBR to inject external routes as Type 7 LSAs, which are translated at the ABR.
- Totally NSSA: combines NSSA behaviour with additional summary suppression; vendor-specific terminology and behaviour should be verified.
OSPF packet types
| Packet | Purpose |
|---|---|
| Hello | Discovers neighbours, verifies parameters and supports DR/BDR election. |
| Database Description (DBD) | Summarises the sender’s link-state database during adjacency formation. |
| Link-State Request (LSR) | Requests specific missing or newer LSAs. |
| Link-State Update (LSU) | Carries one or more LSAs. |
| Link-State Acknowledgment (LSAck) | Acknowledges reliably flooded LSAs. |
OSPF neighbour states
- Down: no valid Hello has been received.
- Init: a Hello was received, but the local router ID is not yet seen in the neighbour’s Hello.
- 2-Way: bidirectional communication is confirmed. On broadcast networks, DROTHER routers may remain 2-Way with each other.
- ExStart: adjacent routers decide the database-exchange relationship and sequence.
- Exchange: DBD packets describe database contents.
- Loading: LSR and LSU packets obtain missing information.
- Full: the adjacent routers’ databases are synchronised.
DR and BDR election
On broadcast and non-broadcast multi-access segments, a Designated Router and Backup Designated Router reduce adjacency and flooding overhead. Election considers OSPF interface priority first and router ID as the tie-breaker. Priority 0 makes an interface ineligible.
DR
BDR
DROTHER
DROTHER
The election is non-preemptive under normal operation. A newly connected router with a higher priority does not automatically replace the existing DR.
Important OSPFv2 LSA types
| Type | Name | Generated by / scope |
|---|---|---|
| 1 | Router LSA | Every router; remains inside its area. |
| 2 | Network LSA | DR on a multi-access segment; remains inside its area. |
| 3 | Summary LSA | ABR; advertises networks between areas. |
| 4 | ASBR Summary LSA | ABR; describes reachability to an ASBR. |
| 5 | AS External LSA | ASBR; floods external routes through normal areas. |
| 7 | NSSA External LSA | ASBR inside an NSSA; translated to Type 5 by an ABR when leaving the NSSA. |
OSPFv3 changes LSA formats and separates address-family information from the core topology more clearly, so do not apply an OSPFv2 LSA list blindly to OSPFv3.
OSPF cost and route preference
A common cost formula is reference bandwidth ÷ interface bandwidth. If the reference value is too low, many high-speed links can receive the same minimum cost, hiding meaningful differences.
| Route type | Meaning |
|---|---|
| O | Intra-area route within the same area. |
| O IA | Inter-area route learned through an ABR. |
| O E1 | External route whose metric includes external cost plus internal cost to the ASBR. |
| O E2 | External route whose metric is primarily the external metric; internal cost is used later as a tie-breaker. |
| O N1 / N2 | NSSA external equivalents of E1 and E2. |
Basic OSPF configuration example
router ospf 10 router-id 10.255.255.1 auto-cost reference-bandwidth 100000 passive-interface default no passive-interface GigabitEthernet0/0 network 10.10.0.0 0.0.255.255 area 0 ! interface GigabitEthernet0/0 ip ospf network point-to-point ip ospf cost 10
Using passive-interface by default reduces accidental neighbour formation while still advertising connected networks. The exact syntax varies by platform.
OSPF troubleshooting workflow
- Confirm interfaces participate in the intended process and area.
- Check Hello/Dead timers, area ID, authentication, network type and stub flags.
- Check unique router IDs.
- Check MTU if the state reaches ExStart or Exchange but never Full.
- Inspect LSDB and SPF results, not only the neighbour table.
- Verify route preference and summarisation if LSAs exist but routes are missing.
show ip ospf neighbor show ip ospf interface brief show ip ospf interface GigabitEthernet0/0 show ip ospf database show ip route ospf show ip protocols show logging | include OSPF
Interview questions and model points
- Why is Area 0 important? It is the OSPF backbone through which inter-area traffic and summaries are normally exchanged.
- Why can two neighbours remain 2-Way? On a broadcast network, DROTHER routers form full adjacency with DR/BDR, not necessarily with every other DROTHER.
- How is the DR elected? Highest eligible interface priority, then highest router ID; normal election is non-preemptive.
- E1 versus E2? E1 adds internal path cost to external cost; E2 primarily uses the external metric.
- What causes ExStart problems? MTU mismatch is a classic cause, along with duplicate router IDs and unstable or filtered communication.
Quick self-check
1. Which IP protocol number is used by OSPF?
2. Which area is the backbone?
3. At which state are databases synchronised?
4. Which packet requests missing LSAs?
5. Which LSA represents an OSPFv2 router inside an area?
6. What priority prevents DR/BDR eligibility?
7. Why may two DROTHER routers stay in 2-Way?
8. Which external metric type includes internal cost to the ASBR?
Frequently asked questions
1. Does OSPF use TCP or UDP?
2. Can an OSPF router belong to more than one area?
3. Does the highest router ID always become DR?
4. What is the biggest difference between OSPFv2 and OSPFv3?
Standards and further reading
- RFC 2328 — OSPF Version 2
- RFC 5340 — OSPF for IPv6
- RFC 3101 — The OSPF Not-So-Stubby Area Option
- RFC 9454 — Update to OSPF Terminology
