What does R1 need to learn?
A user on LAN A wants to reach the server on LAN B, 192.168.4.0/24. R1 connects to LAN A, and R4 connects to LAN B. R2 and R3 provide two possible routes between them. R1 already knows its directly connected networks, but it needs information about the rest of the network before it can choose a path.
OSPF (Open Shortest Path First) exchanges that information between routers. A link-state advertisement (LSA) is a record describing links or reachable networks. The link-state database (LSDB) stores those records. Each router uses shortest path first (SPF), a lowest-cost path calculation, to turn its database into its own best paths.
Learning a route and forwarding a user's packet are separate jobs. OSPF prepares the information that forwarding uses; a user packet does not travel inside an OSPF update.
Follow the control traffic first, then the route it produces. The five stages below are a learning model: Hellos continue during database exchange, and SPF may run while the network is still converging.
From neighbours to installed routes
Step 1: start the process
Use OSPFv2 for this IPv4 lab. OSPFv3 and its IPv6 examples are covered separately. The commands use Cisco IOS/IOS XE syntax; check interface names and feature support on your image. The four routers already have the shown addresses, operational links and compatible area 0 settings. This page explains the process, rather than supplying a complete initial configuration for every device.
From privileged EXEC, R1#, enter configure terminal to reach global configuration, R1(config)#. The router ospf 1 command then enters R1(config-router)#, where the network statements belong. Use end to return to privileged EXEC for show commands. Set router IDs before forming adjacencies in a new lab; changing an existing process identity can require a disruptive restart.
Process ID and router ID
router ospf 1 starts process 1. The number is local to the router (1 to 65535), so neighbours don't need to match, although most networks use the same number everywhere to keep things tidy. The process then needs a unique router ID, chosen as described in What is OSPF?; set it explicitly with router-id.
The network command picks the interfaces
Starting the process doesn't enable OSPF on any interface. You choose them, with the network command:
network <ip-address> <wildcard-mask> area <area-id>Router configuration mode. Every interface whose IP address matches the address and wildcard joins OSPF in that area.
In a wildcard mask, a 0 bit must match and a 1 bit is ignored. The network command selects interfaces; it does not advertise the typed range as a summary. A selected, operational interface contributes its connected network; it sends Hellos unless passive. On R1:
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
network 10.0.13.0 0.0.0.3 area 0
passive-interface GigabitEthernet0/0R1, starting in global configuration mode. Gi0/0 (192.168.1.1), Gi0/1 (10.0.12.1) and Gi0/2 (10.0.13.1) each match one line and join area 0. Gi0/0 is passive: advertise the LAN without Hellos.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
The other way is to enable OSPF on the interface itself, which some engineers prefer because it leaves no doubt about which interfaces are in:
interface GigabitEthernet0/1
ip ospf 1 area 0Alternative on R1, starting in global configuration mode. The first line enters interface configuration; the second enables process 1 in area 0 on Gi0/1. You do not need both activation methods on the same interface.
Compare selected, passive and excluded interfaces
Passive does not mean unadvertised. A passive OSPF interface contributes its network but forms no neighbours. An interface outside OSPF needs another route source if its network is to be learned.
Step 2: find neighbours
A Hello is an OSPF packet used to discover another router and check whether it is still reachable. A neighbour is another OSPF router heard on a directly attached link. An adjacency is the closer relationship used to synchronise databases. We need both routers to hear each other before that exchange can succeed.
Enabled, non-passive broadcast and point-to-point interfaces normally send Hellos every 10 seconds to 224.0.0.5 on Cisco IOS. Two routers on the same link confirm two-way communication once each sees its own router ID listed in the other's Hello, with compatible area, addressing and timer settings. They then synchronise databases if an adjacency is required. On a point-to-point link it is; on broadcast Ethernet the designated-router roles determine which pairs synchronise. Here is a simplified exchange between R1 and R2:
Before opening the exchange, keep four packet names in mind. Database description (DBD) packets list LSA headers, identifying records and their versions without carrying the full records. A link-state request (LSR) asks for a record that is missing locally or available in a newer version. A link-state update (LSU) carries the full records. A link-state acknowledgement (LSAck) acknowledges LSAs, not DBD packets.
Follow the complete R1–R2 packet exchange
- DownNothing heard yet. Both start sending hellos to 224.0.0.5 every 10 seconds.
- I'm 1.1.1.1, area 0, timers 10/40. I haven't heard any neighbours yet.Hello from R1 to R2.Hello
- InitR2 received R1's Hello, but that Hello did not list R2's own RID. This is R2's local view.
- HelloI'm 2.2.2.2, same area and timers, and I can hear 1.1.1.1.Hello from R2 to R1.
- I can hear 2.2.2.2 too.Hello from R1 to R2.Hello
- 2-WayEach router sees its own ID in the other's hello: they are neighbours.
- Initial DBD: propose a sequence number and exchange role.DBD from R1 to R2.DBD
- DBDMy RID is higher: I become DBD master for this exchange.DBD from R2 to R1.
- ExStart → ExchangeR2 controls DBD sequence numbers, not network-wide routing. DBDs list LSA headers.
- DBDHere is the list of LSAs I have.DBD from R2 to R1.
- And here is mine.DBD from R1 to R2.DBD
- LoadingRequest lists still need LSAs that are missing locally or newer at the peer. With an empty list, Exchange can finish directly at Full.
- Please send the full LSAs from 3.3.3.3 and 4.4.4.4.LSR from R1 to R2.LSR
- LSUHere they are.LSU from R2 to R1.
- Got them, thanks.LSAck from R1 to R2.LSAck
- FullDatabase synchronisation complete. Hellos continue; LSUs carry changes, refreshes and retransmitted LSAs.
Device key: R1, R2 (router)
The top line is the shared network link; port labels name its interfaces. Read message rows from top to bottom and follow each arrow from sender to receiver. Rows show protocol order, not additional cables or timing to scale.
Reading the addresses
IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.
An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.
- R1: RID 1.1.1.1 · 10.0.12.1
- R2: RID 2.2.2.2 · 10.0.12.2
Full means database synchronisation is complete. On broadcast Ethernet, OSPF elects a designated router (DR) and backup designated router (BDR) to organise database exchanges. The other routers are called DROthers; two DROthers can correctly remain at 2-Way. An MTU mismatch is one possible cause of ExStart or Exchange problems. The neighbours lesson covers each state and the troubleshooting checks; the DR/BDR lesson explains which neighbours form Full adjacencies.
The five OSPF packet types
OSPF runs directly on IP (protocol number 89), not on TCP or UDP, and uses five packet types:
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Step 3: share the map (the LSDB)
Comparing headers avoids copying records the neighbour already has in the same version. One LSU can carry several LSAs; an LSA is a record inside the packet, not a sixth packet type. Acknowledgements make this exchange reliable. An LSAck can acknowledge several LSAs at once, and receiving the same LSA instance back from a neighbour can also provide an implicit acknowledgement of a previously sent record.
Database synchronisation happens before a neighbour reaches Full. Routers compare LSA headers, request missing or newer records and acknowledge received LSAs. After convergence, the area-scoped topology records agree. Later updates are reliably flooded through the appropriate adjacencies. Inspect the router LSA section with show ip ospf database:
R1#show ip ospf database OSPF Router with ID (1.1.1.1) (Process ID 1) Router Link States (Area 0) Link ID ADV Router Age Seq# Checksum Link count 1.1.1.1 1.1.1.1 412 0x80000004 0x00A1C3 3 2.2.2.2 2.2.2.2 409 0x80000003 0x0062F1 2 3.3.3.3 3.3.3.3 405 0x80000003 0x00B804 2 4.4.4.4 4.4.4.4 398 0x80000004 0x0024D9 3
Under normal OSPFv2 operation, each router refreshes its own LSAs at 30 minutes even without a topology change. MaxAge is one hour: records at that age are excluded from route calculation and flushed. These are LSA maintenance timers, not failure-detection timers.
Step 4: run SPF
Shortest path first (SPF) is the calculation that turns the stored topology into paths. Each router starts from its own position and adds the cost of outgoing interfaces along each possible path. A smaller total is preferred for these paths within the same area. Cost is a configured routing value, not a live measurement of delay or congestion.
See how stored link records become paths
Assume cost 10 in both directions on R1–R3, and cost 1 on every other outgoing interface, including the LAN interfaces. From R3 to LAN A, the path R3 → R4 → R2 → R1 costs 4; its direct high-cost path costs 11.
The result for R1 is its SPF tree, summarised here:
| Destination | Best path from R1 | Total cost | Next hop |
|---|---|---|---|
| 10.0.24.0/30 | R1 → R2 | 2 | 10.0.12.2 (R2) |
| 10.0.34.0/30 | R1 → R2 → R4 | 3 | 10.0.12.2 (R2) |
| 192.168.4.0/24 | R1 → R2 → R4 | 3 | 10.0.12.2 (R2) |
10.0.34.0/30 (the R3–R4 link) is reached through R4 at cost 3 rather than through R3 at cost 11, because the R1–R3 link is expensive.
Step 5: fill the routing table
OSPF offers its best paths to the routing table. If selected over competing route sources, these intra-area routes appear as O, with the default administrative distance 110 and the total cost as the metric. From now on the router forwards packets using these routes; OSPF itself isn't involved in forwarding each packet.
An LSA in the database does not guarantee an installed OSPF route. It must describe usable reachability in the OSPF calculation. For the same destination prefix, a competing source with a lower administrative distance can win the routing-table selection. For example, a normal static route with distance 1 can hide the OSPF route. Forwarding then chooses the longest matching prefix among installed routes; it does not compare every route's OSPF cost.
R1#show ip route ospf 10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks O 10.0.24.0/30 [110/2] via 10.0.12.2, 00:05:41, GigabitEthernet0/1 O 10.0.34.0/30 [110/3] via 10.0.12.2, 00:05:41, GigabitEthernet0/1 O 192.168.4.0/24 [110/3] via 10.0.12.2, 00:05:41, GigabitEthernet0/1
What happens when the R2–R4 link fails
The five steps aren't a one-off. When the R2–R4 link fails:
- When the interfaces report link-down, R2 and R4 detect the failure without waiting for the dead timer. With a silent failure, detection may wait for the configured dead interval (normally 40 seconds on these interfaces), unless another mechanism detects it sooner.
- Each sends a new version of its router LSA, without that link, in an LSU to its remaining neighbours (step 3).
- The changed topology records spread through the appropriate adjacencies in this single area; routers install and acknowledge the newer LSAs.
- The affected topology calculations use the updated map (step 4). This link failure changes the area's topology; not every kind of OSPF update requires a full SPF rebuild.
- R1 replaces its routes through R2 with routes through R3, at the higher cost (step 5).
- Destination subnet
- 192.168.4.0/24
- Next hop · router interface IP
- 10.0.13.2 · R3
- Forwarding path
- R1 → R3 → R4
- OSPF cost
- 12
- Failed connection · interface IPv4
- R2 Gi0/1: 10.0.24.1/30 ↔ R4 Gi0/1: 10.0.24.2/30. The X marks this failed link.
- R1’s possible next hops
- Gi0/1: 10.0.12.1/30 → R2 at 10.0.12.2; Gi0/2: 10.0.13.1/30 → R3 at 10.0.13.2. RIDs in the OSPF views: R1 1.1.1.1, R2 2.2.2.2, R3 3.3.3.3, R4 4.4.4.4.
- LAN gateways
- PC-A uses R1 Gi0/0 at 192.168.1.1; the server uses R4 Gi0/0 at 192.168.4.1. Both endpoint masks are /24 (255.255.255.0). Transit links are /30 (255.255.255.252).
- Routing example
- OSPF area 0; link costs are configured metrics, not measured speed. Dashed arrows carry link-state information; a solid coloured path carries the user’s request.
Timing matters: convergence includes detection, flooding, SPF scheduling and forwarding-table updates. There is no guaranteed recovery time from topology size alone.
Short lab: compare the route before and after failure
Use the four-router topology shown above, with cost 10 on R1–R3 and cost 1 on the other interfaces. The command outputs on this page are written examples, not tested router captures. Assume no competing preferred route for LAN B, operational host gateways and a return route. On R1, record the next hop and metric for LAN B before changing anything.
show ip ospf neighbor
show ip ospf database router
show ip route 192.168.4.0R1, privileged EXEC. Compare directly attached neighbours, stored router records and the selected route. The initial LAN B next hop is 10.0.12.2 at cost 3.
In your isolated lab, shut the R2 interface towards R4. Run the same checks on R1 after convergence. R2 can remain R1's Full neighbour because the failed link is farther away. The LAN B route should instead use R3, 10.0.13.2, at cost 12. Restore the interface with no shutdown and confirm the original route returns.
Next, configure and verify single-area OSPF. That complete configuration lesson uses a separate three-router chain, not this four-router backup-path topology. Check enabled interfaces, neighbours, the LSDB and installed routes in that order.
Test yourself on the five steps
R1 has interfaces 10.1.5.1, 10.1.200.1 and 10.2.0.1. Which of them does network 10.1.0.0 0.0.255.255 area 0 enable?
During the database exchange, R1 sees an LSA listed in R2's DBD that it doesn't have. What does R1 send next?
R4 has no network statement or interface-level OSPF command enabling its LAN interface. With no redistribution or alternate route, what happens?
All routers in the area have the same LSDB. Which step makes R1 and R3 install different next hops for LAN B?
The R2–R4 link fails. Put R1's experience in the right order.
Further reading: Cisco: interpreting OSPF interface output and RFC 2328: OSPFv2.