OSPF

On this page 7

OSPF (Open Shortest Path First) is a link-state interior gateway protocol in which every router builds an identical map of the network and computes the shortest path to each destination with Dijkstra’s algorithm. In routing, OSPF is the most widely used open standard for dynamic routing inside one organization’s network, from campus cores to data centers and service provider backbones.

OSPF version 2 for IPv4 is defined in RFC 2328, and OSPFv3 in RFC 5340 extends the protocol to IPv6. Unlike BGP, which exchanges routes between autonomous systems, OSPF is designed for fast, automatic convergence within a single administrative domain.

OSPF routers first discover neighbors by sending Hello packets to the multicast address 224.0.0.5, directly over IP protocol number 89. Neighbors that agree on key parameters form an adjacency and synchronize their link-state databases (LSDB), which describe every router, link and cost in the area.

Each router then runs the shortest path first (SPF) calculation, placing itself at the root of a tree and finding the lowest total cost to every prefix. The best results are installed in the routing table. When a link changes, the affected router floods a link-state advertisement (LSA), and all routers recalculate.

Because every router in an area holds the same database, OSPF avoids the routing loops and slow counting behavior of older distance-vector protocols such as RIP. The price is memory and processor time for the database and the SPF runs, which is why implementations apply SPF throttling timers that delay recalculation briefly when many changes arrive at once.

Adjacency formation passes through defined neighbor states, which are the first place to look when two routers fail to exchange routes.

StateWhat has happenedStuck here usually means
Down / InitHello sent or received one wayFiltering, mismatched area or subnet
2-WayBidirectional Hellos seenNormal between non-DR routers
ExStart / ExchangeMaster chosen, database summaries swappedMTU mismatch
LoadingMissing LSAs requestedCorrupt or very large LSDB
FullDatabases synchronizedHealthy adjacency
OSPF neighbor states

Areas, router roles and LSA types

OSPF scales through hierarchical areas. All areas must connect to the backbone, area 0, and routers that join areas are area border routers (ABRs), which summarize routes between areas so that a change in one area does not trigger SPF everywhere.

On broadcast segments such as Ethernet, routers elect a designated router (DR) and a backup, which reduces the number of full adjacencies. Routers that inject external routes, for example from BGP or static routes, are autonomous system boundary routers (ASBRs).

LSA typeOriginated byDescribesFlooding scope
1 RouterEvery routerIts links and costsOne area
2 NetworkDesignated routerRouters on a shared segmentOne area
3 SummaryABRPrefixes from other areasOne area
4 ASBR summaryABRHow to reach an ASBROne area
5 ExternalASBRRoutes from outside OSPFWhole domain
7 NSSA externalASBR in an NSSAExternal routes in an NSSAOne NSSA area
Main OSPFv2 LSA types

Special area types limit what is flooded into small sites. Stub areas block type 5 LSAs, a stricter stub variant also blocks most type 3 LSAs and leaves only a default route, and not-so-stubby areas (NSSA) allow local external routes while blocking those from elsewhere.

Key OSPF parameters

OSPF behavior is governed by a small set of timers and metrics that must match or be planned consistently across the network.

ParameterTypical defaultEffect
Hello interval10 s on broadcast linksNeighbor discovery and keepalive
Dead interval40 s, four HellosTime before a neighbor is declared down
Reference bandwidth100 Mbit/s on many platformsBasis for automatic cost
Interface costReference divided by link speedPath preference
Router priority1, range 0 to 255DR election, 0 never becomes DR
MTUMust match on both endsAdjacency reaches Full
Important OSPF parameters with typical defaults

The default reference bandwidth is a classic trap: with 100 Mbit/s, every link of 100 Mbit/s or faster receives cost 1, so a 1 Gbit/s and a 100 Gbit/s link look equal. Operators should raise the reference bandwidth consistently on all routers. Fast failure detection usually comes from BFD rather than from aggressive Hello timers.

OSPF compared with other routing approaches

OSPF is one of several ways to fill a routing table, and the right choice depends on network size, administrative boundaries and required convergence speed.

MethodTypeTypical useMain trade-off
Static routeManual entrySmall networks, default routesNo automatic failover
OSPFLink-state IGPEnterprise and campus networksArea design required
IS-ISLink-state IGPLarge provider backbonesLess familiar to many teams
EIGRPAdvanced distance-vectorNetworks built on one vendorLimited multi-vendor support
BGPPath-vector EGPBetween autonomous systemsPolicy-rich but slower
OSPF and neighboring routing methods

A common enterprise pattern combines them: OSPF carries internal prefixes and loopback addresses, while BGP exchanges routes with internet providers and a static or OSPF-originated default route points toward the edge. Keeping the two protocols separated by careful redistribution rules prevents external tables from overwhelming the internal network.

Common OSPF mistakes

Most OSPF incidents come from parameter mismatches and poor area design rather than protocol defects.

  • Mismatched timers, area IDs or authentication prevent adjacencies from forming.
  • Non-contiguous area 0 splits the backbone and breaks inter-area routing.
  • Redistribution without filtering can leak thousands of external routes or create loops.
  • Duplicate router IDs cause flapping and inconsistent databases.
  • Running OSPF on user-facing interfaces without passive mode exposes the protocol to rogue routers.

Stripped to the essentials

OSPF lets routers share one complete map of the network instead of passing along rumors. Every router knows every road and its length, so each one can work out the quickest route on its own.

When a road closes, the router next to it tells everyone, they all redraw the map and traffic shifts to the next best route within seconds.

Where it is applied

A hospital network connects a main building, two clinics and a data center with redundant fiber links of 10 Gbit/s and older 1 Gbit/s backup links. With static routes, a fiber cut once required manual changes that took most of an hour.

The network team deploys OSPF with the core and data center in area 0 and each clinic in its own area, sets the reference bandwidth to 100 Gbit/s on every router so that 10 Gbit/s links are preferred, and adds BFD for sub-second failure detection.

During a later construction accident that cuts a fiber, OSPF reroutes traffic over the backup link automatically, and clinicians notice no interruption to patient record access.