Build the idea first, then use the next activity to check it.
How OSPF builds a routing table
Neighbours, link-state advertisements and the shortest-path calculation - what each router learns, and why it has to learn all of it.
What you will be able to do
- Describe the three stages between two routers meeting and a route appearing
- Explain what every router in an area holds, and why it is identical
- Read an adjacency state and say whether it is healthy
- Predict which path OSPF picks from interface costs
Before this: You should be able to write a static route and explain why static routing stops scaling - see "Writing a static route" and "Why static routing stops scaling".
Why it matters: OSPF is the routing protocol you are most likely to meet inside a single organisation, and it is the one the exam tests in most depth. Nearly every OSPF fault is one of three things going wrong in the sequence below, so knowing the sequence is most of the diagnosis.
A static route is you telling one router one fact. OSPF is every router telling every other router everything it knows, and then each of them working out the answer independently. That sounds like more work, and it is - but it is work the routers do, and it happens again automatically every time the network changes.
Getting from "two routers are cabled together" to "a route appears in the table" takes three stages. Almost every OSPF problem is one of these three failing, so it is worth being able to name them.
Stage one - find a neighbour
Each OSPF-enabled interface sends a small hello packet at a regular interval. When two routers hear each other, they compare notes. If several settings match, they become neighbours; if any of them disagree, they stay strangers and no routes are exchanged at all.
| Setting | What happens if it differs |
|---|---|
| Area number | The routers see each other's hellos and reject them |
| Hello and dead intervals | Neighbours form and then drop repeatedly |
| Subnet and mask on the link | Hellos are not even received |
| MTU | The adjacency reaches ExStart and stops there |
| Authentication, if configured | Hellos are discarded silently |
Stage two - exchange the map
Once adjacent, the two routers swap link-state advertisements. An LSA is a small statement of fact - "I am this router, I am attached to this network, at this cost". Each router floods what it hears onward, so within a few seconds every router in the area holds the same collection of statements.
That collection is the link-state database, and this is the property that makes OSPF what it is - every router in an area holds an identical database. Not a list of routes; a description of the topology. Two routers that disagree about the database is a fault, and one of the first things to check.
Stage three - run the calculation
Each router then runs the shortest-path algorithm over that database, placing itself at the root and working out the cheapest way to every destination. The results become routing table entries. Because every router starts from the same database but a different root, they all reach consistent answers without ever comparing routing tables.
What "shortest" means
OSPF's metric is cost, and cost is derived from interface bandwidth - faster links cost less. The cost of a path is the sum of the costs of the outgoing interfaces along it. Hop count does not enter into it, which is the point: a two-hop path over fast links beats a one-hop path over a slow one.
Two paths, and why the longer one wins
Traffic from head office to the warehouse floor can go directly over the leased line at a cost of 64, or via the showroom over two links costing 10 each. OSPF picks the showroom path, total cost 20, even though it is two hops instead of one. It is not counting hops - it is adding costs, and 20 beats 64.
Turning it on
router ospf 1
router-id 10.30.0.1
network 10.30.0.0 0.0.0.3 area 0
network 10.30.10.0 0.0.0.255 area 0
Each network statement does two things at once, and conflating them causes confusion later. It enables OSPF on any interface whose address falls inside that range, and it advertises that range to the rest of the area. An interface not matched by any network statement is invisible to OSPF in both directions.
Area 0
A single-area design puts everything in area 0, the backbone. Areas exist to keep the database from growing without limit on a large network; below a few dozen routers there is nothing to gain from splitting one up. Start in area 0, and add areas when the database becomes the problem.
Reading the state
show ip ospf neighbor
# Neighbor ID Pri State Dead Time Address Interface
# 10.30.0.2 1 Full/DR 00:00:34 10.30.0.2 GigabitEthernet0/0
show ip route
# O 10.30.40.0/24 [110/74] via 10.30.0.2, GigabitEthernet0/0
| State | Meaning |
|---|---|
| Full | Healthy. Databases are synchronised. |
| 2-Way | Normal on a shared segment between two non-designated routers. |
| ExStart | Stuck here almost always means an MTU mismatch. |
| Init | Hellos are going one way only. Check filtering and addressing. |
| Down | No hellos at all. Check the interface and the network statement. |
An adjacency that formed and a route that never came
reports that the new warehouse link has been up for an hour and the floor machines still cannot be reached from head office. The neighbour table shows Full, so the link and the adjacency are fine. The warehouse router simply has no network statement covering 10.30.40.0/24, so it never advertised the floor to anyone. Stage one succeeded and stage two had nothing to carry.
Terminology
- Adjacency
- A synchronised relationship between two OSPF routers, over which link-state advertisements are exchanged.
- LSA
- Link-state advertisement. One router's statement about what it is attached to and at what cost.
- Link-state database
- The collected LSAs for an area. Identical on every router in that area.
- Cost
- OSPF's metric, derived from interface bandwidth and summed along a path. Lower wins.
- Router ID
- The 32-bit identifier a router is known by in OSPF, written like an IPv4 address.
Key takeaways
- OSPF goes neighbour, then database, then calculation - faults live in one of the three.
- Several settings must match before an adjacency forms; area and MTU are the usual culprits.
- Every router in an area holds an identical link-state database describing the topology.
- Cost comes from bandwidth and is summed along the path, so fewer hops does not mean shorter.
- A network statement both enables OSPF on an interface and advertises that range.
- A Full adjacency proves the neighbours agree, not that anything is being advertised.
Ready to keep going?
Create a free account to save your progress and take the knowledge check.
