NextGen Sarkari

Study material for government exam preparation across Punjab and India.

Home/Study Material/Networking & Technical/OSPF Complete Guide
Routing study guide

OSPF Complete Guide

Understand how OSPF builds adjacencies, floods link-state information, calculates shortest paths and isolates failures. The examples are written for technical exams and hands-on network interviews.

RoutingIntermediate36 min readUpdated 2026-08-06

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.

Exam point: OSPF chooses paths using cost. The cost is normally derived from interface bandwidth and a reference bandwidth, but the exact default and configuration are vendor-specific.

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 roleMeaning
Internal routerAll participating interfaces are in the same area.
Backbone routerHas 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

PacketPurpose
HelloDiscovers 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
Init
2-Way
ExStart
Exchange
Loading
Full
  • 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.
Stuck in ExStart/Exchange? MTU mismatch is a common cause, along with duplicate router IDs, unstable links or packet filtering.

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.

R1
DR
R2
BDR
R3
DROTHER
R4
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

TypeNameGenerated by / scope
1Router LSAEvery router; remains inside its area.
2Network LSADR on a multi-access segment; remains inside its area.
3Summary LSAABR; advertises networks between areas.
4ASBR Summary LSAABR; describes reachability to an ASBR.
5AS External LSAASBR; floods external routes through normal areas.
7NSSA External LSAASBR 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.

Operational practice: Configure the same reference bandwidth on every OSPF router in the domain. Inconsistent reference bandwidth can produce asymmetric or unexpected path choices.
Route typeMeaning
OIntra-area route within the same area.
O IAInter-area route learned through an ABR.
O E1External route whose metric includes external cost plus internal cost to the ASBR.
O E2External route whose metric is primarily the external metric; internal cost is used later as a tie-breaker.
O N1 / N2NSSA external equivalents of E1 and E2.

Basic OSPF configuration example

Cisco IOS-style 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

  1. Confirm interfaces participate in the intended process and area.
  2. Check Hello/Dead timers, area ID, authentication, network type and stub flags.
  3. Check unique router IDs.
  4. Check MTU if the state reaches ExStart or Exchange but never Full.
  5. Inspect LSDB and SPF results, not only the neighbour table.
  6. Verify route preference and summarisation if LSAs exist but routes are missing.
Verification commands
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
Scenario: If both routers remain in Init, the local router receives Hellos but the neighbour does not list the local router ID. Check one-way connectivity, multicast handling, ACLs and subnet mismatch.

Interview questions and model points

  1. Why is Area 0 important? It is the OSPF backbone through which inter-area traffic and summaries are normally exchanged.
  2. 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.
  3. How is the DR elected? Highest eligible interface priority, then highest router ID; normal election is non-preemptive.
  4. E1 versus E2? E1 adds internal path cost to external cost; E2 primarily uses the external metric.
  5. 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?
Answer: 89.
2. Which area is the backbone?
Answer: Area 0.
3. At which state are databases synchronised?
Answer: Full.
4. Which packet requests missing LSAs?
Answer: Link-State Request.
5. Which LSA represents an OSPFv2 router inside an area?
Answer: Type 1 Router LSA.
6. What priority prevents DR/BDR eligibility?
Answer: Interface priority 0.
7. Why may two DROTHER routers stay in 2-Way?
Answer: They do not need a full adjacency with each other on a broadcast segment.
8. Which external metric type includes internal cost to the ASBR?
Answer: E1.

Frequently asked questions

1. Does OSPF use TCP or UDP?
Answer: Neither. OSPF runs directly over IP using protocol number 89.
2. Can an OSPF router belong to more than one area?
Answer: Yes. An ABR has interfaces in Area 0 and at least one other area.
3. Does the highest router ID always become DR?
Answer: Only after interface priority is considered, and the existing DR is not normally preempted by a later higher candidate.
4. What is the biggest difference between OSPFv2 and OSPFv3?
Answer: OSPFv2 is the base IPv4 protocol. OSPFv3 was designed for IPv6 and changes packet/LSA handling and neighbour formation details.

Standards and further reading

Editorial note: Vendor commands and best-path tie-breakers can differ by platform and software release. Always verify production configuration against the device vendor documentation.

Continue learning