Applies to: OSPFv2 (RFC 2328); lab tested with FRRouting 8.4.4 from the Ubuntu 24.04 repository (Ubuntu 26.04 ships FRR 10.5.1)

OSPF (Open Shortest Path First) is a routing protocol that routers inside one network use to find each other and share how they are connected. Every router builds the same map of the network and calculates the shortest path to each destination itself. When a link fails, the routers notice and switch to another path without anyone changing static routes.

RFC 2328 calls it an Interior Gateway Protocol (IGP) based on link-state or SPF technology. OSPFv2 carries IPv4; OSPFv3 (RFC 5340, “OSPF for IPv6”) carries IPv6. Between separate networks on the internet, BGP is used instead: RFC 4271 describes BGP as an inter-Autonomous System routing protocol.

How OSPF works

  1. Hello packets. Each router sends Hellos on its OSPF interfaces to the multicast address 224.0.0.5 (AllSPFRouters). RFC 2328 gives 10 seconds as the sample Hello interval on a LAN and suggests a dead interval of about four Hellos; FRRouting showed Hello 10s, Dead 40s.
  2. Neighbours and adjacencies. Routers that agree on area, timers and subnet become neighbours. On a shared LAN they elect a Designated Router (DR) and a Backup (BDR), reachable at 224.0.0.6, so not every router has to sync with every other.
  3. Link-state database. Routers flood link-state advertisements (LSAs) until each has the same database.
  4. Shortest path first. From that database each router “constructs a tree of shortest paths with itself as root” (Dijkstra’s algorithm). Every interface has a cost; the path with the lowest total cost wins.
  5. Areas. Large networks are split into areas. Area 0 (0.0.0.0) is the backbone, and other areas connect to it.

OSPF runs directly on IP as protocol number 89, not on TCP or UDP. A firewall between routers must allow it, for example iptables -A INPUT -p ospf -s 10.55.1.0/24 -j ACCEPT (/etc/protocols lists ospf 89 OSPFIGP).

Example: OSPF on Linux with FRRouting

We connected three Ubuntu 24.04 routers in a line (r1, r2, r3) on two subnets, gave r1 and r3 a test address on their loopback, and ran FRRouting on all three.

  1. Install FRR and switch on the OSPF daemon:
    sudo apt install frr
    sudo sed -i 's/^ospfd=no/ospfd=yes/' /etc/frr/daemons
    sudo systemctl restart frr
  2. Open the FRR shell with sudo vtysh, type configure terminal and enter the settings. This is the configuration r1 ended up with:
    interface eth0
     ip ospf area 0
    exit
    !
    interface lo
     ip ospf area 0
     ip ospf passive
    exit
    !
    router ospf
     ospf router-id 1.1.1.1
    exit
    ip ospf passive advertises the loopback address without sending Hellos on it. Save with write memory (FRR answered Integrated configuration saved to /etc/frr/frr.conf).
  3. Check the neighbours. After about 45 seconds (the DR election waits one dead interval), r2 showed:
    Neighbor ID     Pri State           Up Time         Dead Time Address         Interface                        RXmtL RqstL DBsmL
    1.1.1.1           1 Full/Backup     5.176s            34.749s 10.55.1.11      eth0:10.55.1.12                      1     0     0
    3.3.3.3           1 Full/DR         5.102s            34.897s 10.55.2.13      eth1:10.55.2.12                      1     0     0
    Full means the databases are in sync.
  4. Check the routes r1 learned. O>* is an OSPF route that is selected and installed:
    show ip route ospf
    O>* 10.55.2.0/24 [110/20] via 10.55.1.12, eth0, weight 1, 00:00:10
    O>* 192.168.103.1/32 [110/20] via 10.55.1.12, eth0, weight 1, 00:00:10
    In [110/20], 110 is FRR’s administrative distance for OSPF and 20 is the total cost (two links of cost 10).

Failover in practice

We then added a direct link between r1 and r3 with ip ospf cost 100 on both ends, so it was only a backup. After we disconnected r2’s link, r1 had switched to the backup within five seconds:

Known via "ospf", distance 110, metric 100, best
* 10.55.3.13, via eth1, weight 1

Here the failure was fast because r2 saw its own interface go down. If a router just goes silent, its neighbours wait for the dead interval (40 seconds) first; BFD (RFC 5880) is designed to detect such faults much faster.

Useful commands

show ip ospf neighbor
show ip ospf interface eth0     # cost, timers, DR and BDR
show ip ospf database
show ip route ospf

Common reasons two routers don’t become neighbours: different area, different Hello or dead timers, different subnet or MTU on the link, or a firewall dropping protocol 89.

Related: subnet mask cheat sheet, Linux networking commands and their replacements and network bonding modes.

Official documentation: RFC 2328: OSPF Version 2.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket