Routelearn.net
Course menu

Course 8: RoutingLesson 3.2 (9 of 12 in this course)58 of 91 in the CCNA series

OSPF overview

How OSPF routers meet neighbours, share link information and pick the lowest-cost path.

Intermediate · 9 min read

OSPF (Open Shortest Path First) is an open-standard, link-state interior gateway protocol. OSPF routers form neighbour relationships with hello packets, exchange LSAs to build an identical link-state database within an area, and run the SPF algorithm on it to choose the lowest-cost path to each network.

In simple terms: Routers running OSPF share a map of the network with each other. Each router then works out the cheapest way to every destination by itself.

A real-life situation

You remove all the static routes from R1, R2 and R3 and turn on OSPF instead. A few seconds later every router knows every LAN. When someone adds a fourth LAN behind R3, the other routers learn it on their own. Here is what happens behind the scenes.

What OSPF is

OSPF (Open Shortest Path First) is a link-state IGP and an open standard, so routers from any vendor can run it. It works in three stages:

  1. Meet neighbours. Routers send hello packets out of OSPF interfaces every 10 seconds (on Ethernet) to the multicast address 224.0.0.5. Two routers that hear each other and agree on key settings become neighbours.
  2. Share the map. Neighbours swap LSAs (link-state advertisements): small records that describe a router's links and networks. Every router stores them in its LSDB (link-state database). In one area, every router ends up with the same LSDB.
  3. Calculate. Each router runs the SPF (shortest path first) algorithm on the LSDB and puts the lowest-cost path to each network in its routing table.

How two routers become neighbours

Step 1 of 6 · Hello
R1
RID 1.1.1.1
R2
RID 2.2.2.2

1. Hello · Multicast 224.0.0.5

R1 announces itself: router ID, area, timers. It hasn't heard anyone yet.

Neighbour state
State:
FULL
Hellos:
every 10 s, dead after 40 s
R1 and R2 go from strangers to fully synchronised neighbours.

Cost: how OSPF picks a path

OSPF's metric is called cost. Each interface has a cost of reference bandwidth ÷ interface bandwidth. The default reference is 100 Mbps, and the cost can't go below 1. The cost of a path is the sum of the outgoing interface costs along it. Lowest total wins.

InterfaceDefault costWith reference 10000 Mbps
10 Mbps Ethernet101000
100 Mbps FastEthernet1100
1 Gbps GigabitEthernet110
10 Gbps11

With the default, OSPF can't tell 100 Mbps from 10 Gbps. That's why most networks raise the reference bandwidth with auto-cost reference-bandwidth 10000, set the same on every router.

192.168.1.0/24203.0.113.0/3010.0.12.0/3010.0.23.0/30192.168.2.0/24192.168.3.0/24PC1192.168.1.10ISP203.0.113.1R1R2R3PC2192.168.2.10Server192.168.3.10
  1. 1. To 192.168.2.0/24: R1 Gi0/1 (1) + R2 Gi0/2 (1) = 2.
  2. 2. To 192.168.3.0/24: R1 Gi0/1 (1) + R2 Gi0/1 (1) + R3 Gi0/1 (1) = 3.

Areas

In a big network, one shared map would get huge, and every change would make every router recalculate. OSPF splits the network into areas. Routers keep a detailed map only of their own area. Area 0, the backbone, sits in the middle and every other area must connect to it. Small networks like this one use just area 0.

Configure it

⚠️ Based on Cisco IOS / IOS XE documentation, not run on a lab device. R2 and R3 are set up the same way with their own router IDs and networks.

router ospf 1 router-id 1.1.1.1 network 192.168.1.0 0.0.0.255 area 0 network 10.0.12.0 0.0.0.3 area 0 passive-interface GigabitEthernet0/0 default-information originate

On R1. The network command uses a wildcard mask (the inverse of the subnet mask) to choose which interfaces run OSPF.

  • router ospf 1: the 1 is a local process number. It doesn't need to match between routers.
  • router-id: the router's OSPF name. It must be unique.
  • passive-interface: advertise the LAN, but don't send hellos to the PCs on it.
  • default-information originate: share R1's static default route, so R2 and R3 learn it through OSPF.

How to verify it

These outputs are based on Cisco documentation, not run on a lab device.

Example output · based on Cisco documentation; exact format varies by platform and software version
R2#show ip ospf neighbor
Neighbor ID     Pri   State           Dead Time   Address         Interface
1.1.1.1           1   FULL/BDR        00:00:33    10.0.12.1       GigabitEthernet0/0
3.3.3.3           1   FULL/DR         00:00:38    10.0.23.2       GigabitEthernet0/1
Both neighbours are FULL. On Ethernet, OSPF also elects a designated router (DR) and a backup (BDR) on each link; here the higher router ID won. The full OSPF course covers this.
Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show ip route ospf
Gateway of last resort is 203.0.113.1 to network 0.0.0.0

      10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
O        10.0.23.0/30 [110/2] via 10.0.12.2, 00:03:10, GigabitEthernet0/1
O     192.168.2.0/24 [110/2] via 10.0.12.2, 00:03:10, GigabitEthernet0/1
O     192.168.3.0/24 [110/3] via 10.0.12.2, 00:03:10, GigabitEthernet0/1
Code O, AD 110, and the costs worked out above.

Check yourself

Predict · scenario 1

R1 and R2 are cabled, but R1 is in area 0 and R2's interface is in area 1. What happens?

Predict · scenario 2

Two paths: three 1 Gbps links, or one 100 Mbps link, all at default reference bandwidth. Which does OSPF choose?