IP Addresses & Routing

OSPF and Other Interior Routing Protocols

Learn how routers inside one organization share paths, how OSPF builds its map and how it compares with RIP, IS-IS and EIGRP.

Key takeaways

  • Interior protocols move routes within one organization; BGP handles routing between organizations.
  • OSPF routers flood descriptions of their links so that all of them hold an identical map of an area.
  • Cost, usually derived from link speed, decides which path wins in OSPF.
  • Areas limit how much detail each router must hold and how far a change ripples.
  • Most OSPF problems come from neighbors that disagree on basic settings.

An interior gateway protocol is how the routers inside one organization tell each other which networks exist and the best way to reach them. OSPF (Open Shortest Path First) is the one you are most likely to meet: every router builds the same map of the network, then calculates its own shortest paths across it.

If your network has two or three routers and one way out, static routes are probably enough. Once you have redundant links that need to take over automatically, a routing protocol earns its place.

Inside versus between

The internet is divided into autonomous systems, each run under one routing policy. Between them, networks use BGP, which is built for policy and enormous scale. Inside them, the goal is different: find the best path quickly and recover fast when something breaks.

Without any protocol you configure static routes by hand. They are predictable and cheap, but they don't notice a failure several hops away. A dynamic protocol watches neighbors and recalculates when the picture changes.

Two ways to learn a network

Distance vector protocols have each router tell its neighbors what it can reach and how far away it is. A router trusts the neighbor's summary without seeing the whole network. It is simple, but bad news can travel slowly, and loops are possible while routers catch up.

Link state protocols have each router describe its own directly connected links. Those descriptions are passed to everyone unchanged. Each router then holds the same map and runs a shortest path algorithm (Dijkstra's) with itself at the center.

Distance vector and link state
Distance vector Neighbors share reachable networks and distances No router holds the full map Simple to run on small networks Can converge slowly after failures Link state Each router advertises its own links Everyone builds the same map of an area Each computes shortest paths itself Uses more memory and processing VS Distance vector Neighbors share reachable networks and distances No router holds the full map Simple to run on small networks Can converge slowly after failures Link state Each router advertises its own links Everyone builds the same map of an area Each computes shortest paths itself Uses more memory and processing

How OSPF finds neighbors

OSPFv2, for IPv4, is defined in RFC 2328. OSPFv3, defined in RFC 5340, adds IPv6. OSPF runs directly over IP using protocol number 89, not over TCP or UDP.

On each enabled interface, a router sends Hello packets, on many networks to the multicast address 224.0.0.5. Two routers become neighbors only if their hellos agree on key settings:

  • the area number,
  • the hello and dead intervals,
  • the subnet and mask on broadcast networks,
  • authentication,
  • certain area type flags.

Each router also needs a unique router ID, a 32-bit value written like an IPv4 address.

On an Ethernet segment with several routers, having every pair exchange everything would be wasteful. OSPF elects a designated router and a backup. The others synchronize with those two, and updates for the segment pass through them. On point-to-point links there is no election.

Flooding and the shortest path

Routers describe what they know in link-state advertisements (LSAs). When something changes, the router that notices originates a new LSA with a higher sequence number, and it floods through the area. Each router stores it in its link-state database, acknowledges it and passes it on.

Then each router recalculates.

The OSPF routine after a change
Install Best routes go into the forwarding table. Recalculate Each router runs the shortest path computation again. Detect A link drops or hellos from a neighbor stop arriving. Advertise The router issues a newer description of its links. Flood Every router in the area receives and stores it. 1 2 3 4 5 Detect A link drops or hellos from a neighbor stop arriving. 1 Advertise The router issues a newer description of its links. 2 Flood Every router in the area receives and stores it. 3 Recalculate Each router runs the shortest path computation again. 4 Install Best routes go into the forwarding table. 5

Convergence is the time from a failure until all routers agree on new paths. If a cable is pulled and the interface goes down, detection is immediate. If a link silently stops passing traffic, as through an intermediate switch, the router waits for the dead timer, commonly 40 seconds on Ethernet. Shorter timers help, and Bidirectional Forwarding Detection (BFD) detects silent failures much faster where equipment supports it.

Cost decides the path

Each interface has a cost, and a path's cost is the sum of the outgoing interface costs along it. Lowest total wins. If two paths tie, routers can share traffic across both, called equal-cost multipath.

Many implementations calculate cost as a reference bandwidth divided by interface bandwidth. A traditional reference of 100 Mbps gives every link of 100 Mbps and faster the same cost of 1, so a gigabit link and a ten-gigabit link look identical. Raise the reference bandwidth, and set it the same on every router.

You can also set costs by hand to steer traffic, for example to keep a backup wireless link idle while fiber works.

Areas

A single flat network works up to a point. Beyond it, every flap anywhere forces recalculation everywhere. OSPF splits a network into areas. Area 0 is the backbone, and other areas connect to it. A router on the boundary, an area border router, passes summarized reachability between them.

Detail stays local; neighbors in other areas learn which prefixes are reachable and at what cost. Good address planning lets you advertise a few large blocks instead of many small ones, which is the idea behind route summarization.

Special area types such as stub areas reduce detail further by replacing external routes with a default. Small and mid-sized networks often need only area 0. Don't add areas just because you can.

The other interior protocols

RIP is the classic distance vector protocol. RIPv2 (RFC 2453) measures distance in hops and treats 16 as unreachable, so no path can exceed 15. It ignores link speed. You'll see it in labs, old equipment and a few very simple setups.

IS-IS is a link state protocol that began in the OSI protocol family and was extended to carry IP. It runs directly over the link layer, handles IPv4 and IPv6 well, and is popular in large provider networks.

EIGRP was created by Cisco and later documented in the informational RFC 7868. It is an advanced distance vector protocol that keeps precomputed backup paths. Support outside Cisco equipment is limited.

Protocol Style Typical home
OSPF Link state Enterprises, campuses, many providers
IS-IS Link state Large service provider and data center cores
EIGRP Advanced distance vector Cisco-centric enterprises
RIP Distance vector Small or legacy networks

Some large data centers use BGP internally as well, because its policy tools and scaling behavior suit their layout.

Choosing and running one

For a network that mixes vendors, OSPF is the common choice. Whatever you pick:

  1. Plan router IDs and addressing before you configure anything.
  2. Mark user-facing interfaces as passive, so their networks are advertised but no neighbor can form there.
  3. Enable authentication on links where neighbors form. OSPF supports cryptographic authentication; plain-text passwords add little.
  4. Be careful with redistribution, which injects routes from one protocol into another. Without filters it can create loops.
  5. Document intended costs, so a later change doesn't silently move traffic.

A worked example

Picture a company with a head office, a warehouse and a data room, each with a router. The head office connects to both other sites by fiber, and the warehouse and data room share a slower wireless link.

With OSPF running on all three, each router advertises its local subnets and its links. The warehouse reaches the data room's servers by two routes: through the head office over two fiber links, or directly over the wireless link. Suppose each fiber interface has cost 10 and the wireless interface has cost 50, as illustrative values. The fiber path totals 20 plus the cost of the final server network, while the wireless path totals 50 plus the same final cost. Traffic takes the fiber.

If a digger cuts the fiber between the warehouse and head office, the warehouse router sees the interface fail, floods an update and recalculates. The wireless path is now the best remaining one. When the fiber is repaired, hellos resume, the adjacency rebuilds and traffic moves back. Nobody edits a route.

Test this on purpose during a quiet period. A backup path that has never carried traffic may turn out to have a filter, a firewall rule or an addressing gap that only appears under failure. Also confirm that the slower link can carry what matters, and use queue management or traffic priorities if bulk transfers would otherwise swamp voice calls while you're on backup.

Default routes and the way out

Internal routers also need to know where to send traffic for the rest of the internet. Usually the router at the edge, which holds a static default route or learns one from the provider, injects a default route into OSPF. Every other router then learns that unknown destinations go toward the edge.

Make that advertisement conditional where your software allows it, so a router that has lost its upstream stops attracting traffic. With two edge routers, decide whether both should share outbound load or one should be preferred, and check that return traffic won't be dropped by a stateful firewall that only saw half of the conversation. Asymmetric paths of that kind are a common surprise when redundancy is first added.

Is it worth it at small scale?

A routing protocol adds something to learn, monitor and secure. For a home or a single small office with one router, it adds nothing: your devices just use their default gateway. For two sites with a single link between them, a pair of static routes is easier to reason about.

The balance shifts when there are multiple paths, when subnets are added often, or when failures need to heal without someone logging in at night. A small lab is a safe way to learn: virtual routers running open source routing software let you form neighbors, break links and read the database without touching production. Building a home lab covers how to set one up.

When neighbors won't form

Check the neighbor table first. The command is typically show ip ospf neighbor on Cisco-style systems and show ip ospf neighbor in FRRouting's shell; other vendors use similar wording.

  • No neighbor at all: confirm basic connectivity, that OSPF is enabled on the interface, that it isn't passive and that no filter blocks protocol 89 or multicast.
  • Stuck in an early state: one side hears the other but not the reverse. Look for one-way connectivity.
  • Stuck exchanging database details: an MTU mismatch between the two interfaces is a frequent cause.
  • Neighbor flaps: look for an unstable link, an overloaded router or a duplicate router ID.
  • Routes missing: verify the network is actually advertised, and check area summaries and filters.

When a path looks wrong, compare costs along both candidates and then confirm with traceroute. Remember that a router's choice also depends on prefix length and on which routing source it trusts most, so an OSPF route can lose to a static one even when OSPF is working perfectly.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in IP Addresses & Routing →

Latest news on this topic