Skip to content
Visual explainer 3h to learn 4 steps

Dynamic routing & OSPF concepts

Explain how link-state routing with OSPF builds a shared map and picks shortest paths.

By Invicly Tech, , in Computer Networking. About 13 minutes to read.

Topic 17 of 51

In short

Dynamic routing protocols let routers discover routes and react to failures automatically. OSPF is a link-state protocol: every router floods descriptions of its links so all routers share the same map, then each runs Dijkstra's shortest-path algorithm on it. Areas keep large networks manageable.

Explained simply

In a big network, typing routes by hand on every router is slow and fragile. A dynamic routing protocol lets routers talk to each other, learn which networks exist, and fix the routes by themselves when a link breaks. OSPF (Open Shortest Path First) is the most widely used one inside companies.

OSPF is a link-state protocol. Each router tells every other router about its own links: "I am connected to these networks and these neighbours, at this cost". Soon every router holds the same complete map of the network.

With the map in hand, each router calculates the shortest path to every network using Dijkstra's algorithm, the same one you may know from graph lessons. Shortest here means lowest total cost, and cost is usually based on link speed, so faster links are preferred.

Large networks are split into areas, like neighbourhoods in a city. Routers know the detailed map of their own area and only a summary of the others. Area 0, the backbone, sits in the middle and every other area connects to it.

Press Play on a diagram to walk through it one step at a time.

CycleOSPF operation
  1. 1
    Form neighbours

    Hello packets on each link.

  2. 2
    Flood LSAs

    Share link-state advertisements.

  3. 3
    Build LSDB

    Identical map on every router in the area.

  4. 4
    Run SPF

    Dijkstra computes best paths.

  5. 5
    Install routes

    Re-run when a link changes.

  6. Back to step 1
SequenceTwo routers forming a full adjacency
R1
R2
  1. 1Hello (neighbours: none)
    R1 to R2: Hello (neighbours: none)
  2. 2Hello (neighbours: R1): 2-Way
    R2 to R1: Hello (neighbours: R1): 2-Way
  3. 3DBD: summary of my LSAs
    R1 to R2: DBD: summary of my LSAs
  4. 4DBD: summary of my LSAs
    R2 to R1: DBD: summary of my LSAs
  5. 5LSR: send me the LSAs I lack
    R1 to R2: LSR: send me the LSAs I lack
  6. 6LSU: the requested LSAs
    R2 to R1: LSU: the requested LSAs
  7. 7LSAck: received, state Full
    R1 to R2: LSAck: received, state Full

In depth

Distance-vector versus link-state

A distance-vector protocol such as RIP shares conclusions, not facts. Each router tells its neighbours "I can reach network X in 3 hops", and they add one. RIP sends its whole table every 30 seconds and uses hop count as its metric, with 15 as the maximum and 16 meaning unreachable. When a link fails, bad news spreads slowly and routers can keep raising each other's counts (count to infinity). Split horizon and poison reverse reduce this but convergence still takes a long time.

A link-state protocol shares facts. Each router describes its own links, these descriptions are flooded unchanged to every router in the area, and each router computes paths itself. Because everyone has the same map, they reach consistent answers quickly, typically within seconds. The cost is more memory and CPU for the database and the SPF calculation, which is why areas exist.

CompareRIP and OSPF side by side
RIP (distance-vector)
  • Shares its routing table with neighbours
  • Metric: hop count, max 15
  • Full updates every 30 seconds
  • Slow convergence, count to infinity
OSPF (link-state)
  • Floods link descriptions to all routers
  • Metric: cost from bandwidth
  • Updates on change, refresh every 30 minutes
  • Converges in seconds, uses Dijkstra

How two routers become neighbours

OSPF runs directly on IP as protocol number 89, not over TCP or UDP. Routers send Hello packets to the multicast address 224.0.0.5 (all OSPF routers), by default every 10 seconds on Ethernet and point-to-point links, and declare a neighbour dead after 40 seconds of silence.

To become neighbours, both sides must agree on the area ID, the hello and dead intervals, the subnet and mask on the link, the authentication settings and the area type (for example, both stub). They must have different router IDs. Once they see each other in Hellos they reach 2-Way, then exchange database summaries (ExStart, Exchange), request missing pieces (Loading) and finally reach Full.

If the interface MTUs differ, they usually get stuck in ExStart or Exchange. On a shared Ethernet segment, routers elect a designated router (DR) and a backup (BDR) by highest priority (default 1), then highest router ID. Other routers stay at 2-Way with each other, which is normal.

FlowOSPF neighbour states
  1. 1
    Down

    No Hellos heard.

  2. 2
    Init

    Hello heard, my ID not in it yet.

  3. 3
    2-Way

    Both see each other; DR election.

  4. 4
    ExStart / Exchange

    Agree roles, swap database summaries.

  5. 5
    Loading

    Request missing LSAs.

  6. 6
    Full

    Databases match.

LSAs, the database and the five packet types

OSPF uses five packet types: Hello (1), Database Description or DBD (2), Link State Request (3), Link State Update (4) and Link State Acknowledgement (5). Updates carry LSAs (link-state advertisements), and every update must be acknowledged, so flooding is reliable even though OSPF does not use TCP.

The common LSA types are: type 1 router LSA (each router's links, stays in its area), type 2 network LSA (made by the DR for a shared segment), type 3 summary LSA (made by an area border router to describe networks in other areas), type 4 ASBR summary, type 5 external LSA (routes redistributed from outside OSPF, flooded through all normal areas) and type 7 for NSSA areas.

Each LSA has a sequence number so newer copies replace older ones. The originating router refreshes it every 30 minutes, and an LSA that reaches MaxAge, one hour, is flushed. All LSAs together form the LSDB (link-state database).

  • Type 1 router, type 2 network: intra-area
  • Type 3 summary: from the ABR
  • Type 5 external: from the ASBR
  • Refresh every 30 minutes, MaxAge 1 hour

Cost, SPF and the reference bandwidth trap

Each interface has a cost, and the cost of a path is the sum of the outgoing interface costs along it. By default Cisco calculates cost = reference bandwidth / interface bandwidth, with a reference of 100 Mbps, and the result is at least 1. So 10 Mbps costs 10, 100 Mbps costs 1, and 1 Gbps, 10 Gbps and 100 Gbps also cost 1. OSPF then cannot tell them apart.

The fix is auto-cost reference-bandwidth, given in Mbps. With auto-cost reference-bandwidth 100000 (100 Gbps), 1 Gbps costs 100, 10 Gbps costs 10 and 100 Gbps costs 1. Set the same value on every router, or paths will be compared on different scales. You can also set a cost per interface with ip ospf cost.

After any change in the LSDB, each router runs SPF (Dijkstra) with itself as the root and installs the best paths. Equal-cost paths are installed together; Cisco IOS installs up to 4 by default, changeable with maximum-paths.

Areas, border routers and stub areas

Every OSPF network has area 0, the backbone. Other areas must attach to it directly (a virtual link can patch a broken design, but avoid that). A router with interfaces in area 0 and another area is an ABR (area border router). A router that brings in routes from outside OSPF, such as static routes or BGP, is an ASBR (AS boundary router).

Areas limit how far detail spreads. Type 1 and 2 LSAs stay inside their area, so a flapping link in area 1 makes only area 1's routers rerun the full SPF; others just see a type 3 summary change. ABRs can also summarise a range, such as many /24s into one /16.

Stub areas block type 5 external LSAs and get a default route from the ABR instead. Totally stubby areas, a Cisco feature, also block type 3 summaries. NSSAs allow a local ASBR inside a stub-like area by using type 7 LSAs. For IPv6, OSPFv3 (RFC 5340) uses the same ideas.

MapA multi-area OSPF domain
OSPF domain
  • Area 0 (backbone)
    • Core routers
    • Every ABR has a link here
  • Area 1
    • Connected via ABR1
    • Sees other areas as type 3 summaries
  • Area 2 (stub)
    • No type 5 externals
    • Default route from the ABR
  • Outside OSPF
    • ASBR redistributes static or BGP
    • Appears as type 5 external LSAs

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Compare distance-vector and link-state~45m
  2. 2
    Explain OSPF neighbours and LSAs~45m
  3. 3
    Explain areas and cost metrics~45m
  4. 4
    Configure single-area OSPF in a simulator~45m

Key points

  • Cost is based on bandwidth; lower total cost wins.
  • Area 0 is the backbone; other areas attach to it.
  • Converges in seconds after a failure.
  • Distance-vector protocols like RIP share routes, not the topology.

Key terms

Tap a card to flip it. 0/5 known

Examples

text
router ospf 1
 router-id 1.1.1.1
 network 10.1.0.0 0.0.0.255 area 0
 network 172.16.0.0 0.0.0.3 area 0
!
show ip ospf neighbor
show ip route ospf

Single-area OSPF on Cisco IOS; network uses wildcard masks.

Single-area OSPF on Cisco IOS with sensible defaults

Three routers, all in area 0. Step 1: give each router a fixed router ID, so it does not change when interfaces change. Step 2: raise the reference bandwidth on every router so gigabit and 10-gigabit links get different costs. Step 3: enable OSPF per interface with ip ospf 1 area 0. Step 4: make the LAN interface passive, so it advertises the LAN but sends no Hellos to hosts. Step 5: check that neighbours reach FULL and that O routes appear. In a simulator such as Packet Tracer, GNS3 or containerlab, repeat on R2 and R3.

text
router ospf 1
 router-id 1.1.1.1
 auto-cost reference-bandwidth 100000
 passive-interface GigabitEthernet0/2
interface GigabitEthernet0/0
 ip ospf 1 area 0
interface GigabitEthernet0/2
 ip ospf 1 area 0
!
R1# show ip ospf neighbor
Neighbor ID  Pri  State     Dead Time  Address     Interface
2.2.2.2        1  FULL/DR   00:00:36   172.16.0.2  GigabitEthernet0/0
R1# show ip route ospf

Why the reference bandwidth matters: a path cost walk

R1 can reach R4 two ways. Path A: two 1 Gbps links. Path B: one 10 Gbps link, then one 100 Mbps link. With the default reference of 100 Mbps, every link of 100 Mbps or faster costs 1, so path A = 1 + 1 = 2 and path B = 1 + 1 = 2. OSPF sees a tie and splits traffic, sending half of it over the slow 100 Mbps link. With a reference of 100,000 Mbps: 1 Gbps costs 100, 10 Gbps costs 10 and 100 Mbps costs 1000. Path A = 200, path B = 1010, so OSPF correctly picks path A.

Quick reference

  • OSPF is IP protocol 89; Hellos go to 224.0.0.5, and to the DR/BDR at 224.0.0.6
  • Default timers on Ethernet: hello 10 s, dead 40 s; they must match on both sides
  • Neighbour states: Down, Init, 2-Way, ExStart, Exchange, Loading, Full
  • Stuck in ExStart or Exchange? Check for an MTU mismatch
  • Cisco cost = 100 Mbps reference / bandwidth; set auto-cost reference-bandwidth on every router
  • Area 0 is the backbone; ABRs join areas, ASBRs bring in external routes
  • LSA types: 1 router, 2 network, 3 summary, 4 ASBR summary, 5 external, 7 NSSA
  • show ip ospf neighbor, show ip ospf interface brief, show ip route ospf

Common mistakes

  • Mismatched hello timers or area IDs, so neighbours never form.
  • Duplicate router IDs.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Two OSPF routers are stuck in the ExStart state. What is the most likely cause?

Question 2

2With Cisco's default reference bandwidth of 100 Mbps, what is the OSPF cost of a 10 Gbps interface?

Question 3

3Which LSA type does an area border router use to describe networks from one area to another?

Question 4

4What is the maximum usable hop count in RIP?

Question 5

5On a shared Ethernet segment, two non-DR routers show each other in the 2-Way state. What does it mean?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    With auto-cost reference-bandwidth 10000 (10 Gbps), calculate the OSPF cost of 100 Mbps, 1 Gbps, 10 Gbps and 40 Gbps interfaces.

  2. Exercise 2medium

    Configure single-area OSPF on two FRRouting routers joined by 172.16.0.0/30, each with a LAN (10.1.0.0/24 and 10.2.0.0/24). Then name the commands to check neighbours and routes.

  3. Exercise 3hard

    R1 and R2 are cabled together but show ip ospf neighbor is empty on both. Write a checklist of what to compare, and the command for each on Cisco.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Is OSPF still used, or has everything moved to BGP?
OSPF is still very common inside enterprise and campus networks. Large data centres often run BGP even internally, and service providers often use IS-IS, but OSPF concepts carry over to both.
Does the OSPF process ID have to match between routers?
No. The number in router ospf 1 is only local to that router. The area ID, timers, subnet and authentication are what must match.
What is the OSPF router ID and how is it chosen?
A 32-bit number written like an IPv4 address that names the router in OSPF. If you do not set it, Cisco uses the highest loopback address, or else the highest active interface address, so it is best to set it by hand.
What is the difference between OSPFv2 and OSPFv3?
OSPFv2 (RFC 2328) carries IPv4 routes. OSPFv3 (RFC 5340) was built for IPv6, runs over IPv6 link-local addresses, and with later extensions can carry IPv4 as well.

Go deeper

ShareXLinkedInWhatsApp