linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Protocols/ospf

kb/protocols ── Protocols ── advanced

OSPF: Open Shortest Path First

**OSPF** is a link-state IGP inside one autonomous system. Each router knows the full topology (LSDB) and independently computes shortest paths with Dijkstra. Convergence takes seconds.

view as markdownaka: ospfv2, open-shortest-path-first

What link-state means

Unlike distance-vector (RIP, EIGRP), where a neighbor just says "I reach prefix X with metric 5", link-state works differently:

  1. Each router describes only its own local links in an LSA (Link State Advertisement)
  2. Every LSA is flooded across the area without changes
  3. Each router builds an identical LSDB (Link State Database), the full map of the area
  4. Locally it runs SPF (Dijkstra) → the routing-table

The key point: everyone sees the same topology. No rumors passed through intermediate routers, no count-to-infinity loops.

Adjacency

OSPF hears neighbors over multicast 224.0.0.5 (ALL-OSPF-ROUTERS) on every enabled interface. Hello every 10s (Ethernet) or 30s (NBMA).

Neighbor states:

Down → Init → 2-Way → ExStart → Exchange → Loading → Full
  • Down/Init the Hello has not arrived yet, or it is one-way
  • 2-Way both see each other, but the LSDB exchange has not happened (on a broadcast network all non-DR neighbors stay in 2-Way)
  • ExStart/Exchange/Loading the LSDB is synchronizing
  • Full synchronization is complete and the adjacency is usable

In a working network all required neighbors must be Full (or 2-Way with a non-DR). Use show ip ospf neighbor through cmd-vtysh.

Area

OSPF splits a large network into areas, isolated flooding domains.

  • Area 0 is the backbone and is mandatory. Every other area attaches to area 0.
  • Area N is non-backbone. It can be stub or totally-stubby to shrink the LSDB
  • ABR (Area Border Router) sits between areas and summarizes routes
  • ASBR (AS Boundary Router) redistributes to the outside world (BGP, static)

With fewer than about 50 routers a single Area 0 is enough. The hierarchy earns its keep at hundreds of nodes.

LSA types (simplified)

TypeNameWhat it describes
1Router LSAown links inside the area
2Network LSAbroadcast segment (the DR generates it)
3Summary LSAprefix from a neighboring area (the ABR generates it)
4ASBR Summaryhow to reach the ASBR
5External LSAredistributed external prefixes
7NSSA Externalsame as type-5 but inside an NSSA area

show ip ospf database shows every LSA in the LSDB.

DR / BDR on broadcast networks

On an Ethernet segment with N routers you would have N×(N-1)/2 adjacencies. To avoid a flood storm OSPF elects a DR (Designated Router) and a BDR (Backup). Everyone else forms Full only with the DR and BDR.

  • DR election: highest priority (default 1), tie-breaker is the Router ID
  • On p2p links (such as a /30) no DR is needed, there is only one neighbor anyway

A loopback with a high IP and priority 0 brings up OSPF faster and more predictably.

Minimal configuration (FRR)

router ospf
 ospf router-id 1.1.1.1
 network 10.0.0.0/30 area 0
 network 192.168.10.0/24 area 0

What network does: on any interface whose IP falls into this prefix, OSPF turns on (Hello is sent, the prefix is announced in an LSA type 1).

Newer alternative, per-interface configuration:

interface eth0
 ip ospf area 0

This is more precise. It does not depend on the interface's current IP.

Common pitfalls

  • MTU mismatch between neighbors → stuck in ExStart. Fix: matching MTU or ip ospf mtu-ignore.
  • Hello/Dead intervals that differ → neighbors never see each other. OSPF requires an exact match of Hello and Dead.
  • Auth mismatch (when MD5 or a key-chain is enabled) → silent drop.
  • Subnet mask mismatch on a broadcast segment → no 2-Way.
  • passive-interface forgotten on the interface toward clients → they receive your Hello (harmless, but noisy and potentially risky).

OSPF vs BGP in one network

  • OSPF runs inside the AS, converges fast, and handles roughly 500 prefixes in one area without trouble
  • BGP (bgp) runs between ASes or carries transit for a large number of prefixes

The classic design: OSPF carries router loopbacks (the next-hops), BGP carries client prefixes. This takes load off OSPF and leaves policy to BGP.

§ команды

bash
vtysh -c 'show ip ospf neighbor'

List of neighbors and their state. They should be Full

bash
vtysh -c 'show ip ospf interface brief'

Which interfaces run OSPF, their area, and DR/BDR

bash
vtysh -c 'show ip ospf database'

The LSDB: every LSA this router knows

bash
vtysh -c 'show ip ospf route'

Routes computed by SPF, before they reach the RIB

bash
tcpdump -i any -n proto ospf

Watch Hello and LSU directly on the wire (multicast 224.0.0.5/6)

§ см. также

  • bgpBGP: Border Gateway Protocol**BGP** is the routing protocol between autonomous systems (AS). It is the language ISPs and large networks use to exchange reachability information: which AS owns which prefixes and how to reach them.
  • routing-tableRouting tableThe routing table lists where to send packets for each destination. The longest matching prefix wins.
  • ipv4-addressingIPv4: Addressing and CIDRAn IPv4 address is 32 bits written as `a.b.c.d`. The **/N** suffix is the prefix length: `/24` fixes the first 24 bits for the network and leaves 8 bits for hosts (256 addresses).
  • cmd-vtyshvtysh: CLI for FRR (BGP/OSPF)vtysh is the Cisco-style CLI for FRRouting. It lets you configure all routing daemons (zebra, bgpd, ospfd) in a single integrated session.

§ упоминается в уроках

  • ›advanced-09-ospf-area-0
  • ›intermediate-03-three-node-routing
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies