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:
- 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.
- 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.
- 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
1. Hello · Multicast 224.0.0.5
R1 announces itself: router ID, area, timers. It hasn't heard anyone yet.
- State:
- FULL
- Hellos:
- every 10 s, dead after 40 s
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.
| Interface | Default cost | With reference 10000 Mbps |
|---|---|---|
| 10 Mbps Ethernet | 10 | 1000 |
| 100 Mbps FastEthernet | 1 | 100 |
| 1 Gbps GigabitEthernet | 1 | 10 |
| 10 Gbps | 1 | 1 |
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.
- 1. To 192.168.2.0/24: R1 Gi0/1 (1) + R2 Gi0/2 (1) = 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 originateOn 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.
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
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
Check yourself
R1 and R2 are cabled, but R1 is in area 0 and R2's interface is in area 1. What happens?
Two paths: three 1 Gbps links, or one 100 Mbps link, all at default reference bandwidth. Which does OSPF choose?