Lesson

OSPF: Open Shortest Path First

Learning objective

Explain how OSPF routers form adjacencies, flood link-state advertisements, and compute shortest paths per RFC 2328.

Learning objective

Explain how OSPF routers form adjacencies, flood link-state advertisements, and compute shortest paths per RFC 2328.

What OSPF is

OSPF (Open Shortest Path First) is the most widely deployed interior gateway protocol, standardized for IPv4 in RFC 2328 (OSPFv2; OSPFv3 for IPv6 is RFC 5340). Unlike RIP's distance-vector design, OSPF is a link-state protocol: every router floods a description of its own directly connected links to every other router in the same area, so all routers end up holding an identical link-state database (LSDB). Each router then independently runs Dijkstra's shortest-path algorithm against that shared database to compute its own best routes. Every OSPF router is identified by a 32-bit Router ID, conventionally written in dotted-decimal form even though it is not necessarily a real IP address.

OSPF's metric is cost, calculated per interface as reference bandwidth ÷ interface bandwidth, and summed along the whole path. With the common default reference bandwidth of 100 Mbps, a 100 Mbps link costs 1 and a 10 Mbps link costs 10 — faster links are cheaper. Because every router in an area holds the same link-state database, cost comparisons and the resulting shortest-path tree are consistent across the whole area; there is no risk of the reachability disagreements that plague distance-vector protocols.

OSPF packet types

OSPF runs directly over IP (IP protocol 89, no UDP or TCP header) and defines five packet types, each playing a role in the adjacency-formation sequence covered next:

  • Hello (type 1): discovers and maintains neighbors.
  • Database Description / DBD (type 2): summarizes LSA headers during adjacency formation.
  • Link State Request / LSR (type 3): asks a neighbor for a specific LSA in full.
  • Link State Update / LSU (type 4): carries one or more complete LSAs.
  • Link State Acknowledgment / LSAck (type 5): confirms receipt of an LSU.

Forming an OSPF adjacency

Two OSPF routers move through a well-defined sequence of neighbor states on their way to a full adjacency:

  1. Down: no Hello has been heard from this neighbor yet.
  2. Init: a Hello has been heard, but the local router isn't listed in it yet.
  3. 2-Way: both routers see each other's Router ID in a Hello.
  4. ExStart: negotiating which router will be master for the exchange.
  5. Exchange: trading DBD summaries of the LSDB.
  6. Loading: requesting and receiving any LSAs not yet held in full.
  7. Full: the LSDBs are synchronized.

On a multi-access network (such as Ethernet) with more than two routers, OSPF also elects a Designated Router (DR) and Backup Designated Router (BDR) so that routers form full adjacencies with the DR/BDR rather than with every other router, cutting down on redundant flooding.

Interactive OSPF adjacency

Step through four routers on a shared multi-access segment: Hellos exchanged with everyone at once, a Designated Router and Backup Designated Router elected by priority, the DR and BDR each building a full adjacency with every other router, and the key fact that two non-DR/BDR routers stop at 2-Way and never exchange a full database directly with each other.

OSPF areas and LSA types

OSPF scales by dividing a network into areas; Area 0, the backbone, must exist, and every other area normally attaches directly to it, which limits how far a single topology change has to propagate. Different Link-State Advertisement (LSA) types carry different information:

  • Type 1 (Router LSA): describes a router's own links within an area.
  • Type 2 (Network LSA): describes a multi-access segment's attached routers, originated by the DR.
  • Type 3 (Summary LSA): lets an Area Border Router (ABR) advertise routes between areas.
  • Type 4 (ASBR Summary LSA): advertises the location of an Autonomous System Boundary Router (ASBR).
  • Type 5 (AS External LSA): carries routes redistributed from outside OSPF entirely, originated by an ASBR.

Inspect OSPF evidence

show ip ospf neighbor is the first command to check: it lists every neighbor and its current state, and any state other than Full (or 2-Way on a non-DR/BDR multi-access neighbor, which is expected) means the adjacency has not finished forming. show ip ospf database lists every LSA type the router holds, organized by area — a fast way to confirm whether two routers actually share an identical LSDB.

Basic Wireshark check

Display filter: ospf

Capture on an OSPF-enabled interface while an adjacency forms. Identify each packet type by its OSPF header (Hello, DBD, LSR, LSU, LSAck) and confirm the Router ID and Area ID match on both sides.

Guided OSPF cost practice

With the default reference bandwidth of 100 Mbps, compute the total cost of a path crossing a 100 Mbps link, then a 1 Gbps link, then a 10 Mbps link: 100,000,000/100,000,000 = 1, plus 100,000,000/1,000,000,000 rounds up to 1, plus 100,000,000/10,000,000 = 10. Total cost = 1 + 1 + 10 = 12.

Interview scenario

Show answer and reasoning
With the default 100 Mbps reference bandwidth, both a 100 Mbps and a 1 Gbps link round to a cost of 1, so OSPF cannot tell them apart. Explain what an administrator should change to make OSPF prefer the faster link, and why leaving the default in place on a modern high-speed network is a common misconfiguration.

Troubleshoot OSPF

  1. Confirm both routers have OSPF enabled on the correct interfaces and agree on the area number for that link.
  2. Check for a Hello or Dead interval mismatch — OSPF requires these to match exactly between neighbors on the same link.
  3. Look for a duplicate Router ID on the network, which can prevent an adjacency from forming correctly or cause it to flap.
  4. If a neighbor is stuck in ExStart or Exchange, suspect an MTU mismatch: routers that disagree on the largest DBD packet size can appear to negotiate but never finish exchanging LSA summaries.
  5. Verify authentication settings match on both sides if OSPF authentication is configured.
  6. On a multi-access network, confirm the DR/BDR election completed as expected — a router stuck below 2-Way with the DR usually means one of the checks above failed specifically toward the DR.

Interview scenario

Show answer and reasoning
Two routers show a neighbor relationship stuck in ExStart or Exchange indefinitely, never reaching Full. Walk through what you would check first, and explain why this specific symptom points toward an MTU mismatch rather than a Hello/Dead timer problem.

Knowledge check and summary

Knowledge check: What does OSPF's cost metric measure?
Knowledge check: What must be true for an OSPF neighbor relationship to reach the Full state?
Knowledge check: Which LSA type does an Area Border Router use to advertise routes between areas?

Pro deep dive