Course contents

Module 1: Understanding OSPFLesson 1.2 (2 of 4 in this module)2 of 29 in the OSPF course

Why do networks need OSPF?

Why does a working backup cable not guarantee a working backup route? Let's compare static routes and OSPF in one small network.

Intermediate · 10 min read

Why does a router need a route before it can forward?

PC-A is a user's computer on LAN A. It needs to open an internal website on a server at 192.168.4.10 on LAN B. The server's address is an IP address, not a website URL. The computer sends packets towards that address through its local router, R1.

R1 checks its routing table: a list of networks and how to reach them. A matching route tells R1 the next router to send the packet to. This router is the next hop. R1 cannot use a path just because a cable exists; it needs a route that chooses that path.

See R1 look up the destination address
R1 looks up the destination IP, then chooses a next hop
R1 looks up the destination IP, then chooses a next hopArrows show the selected packet path; access switches are omitted. R1 uses the packet’s destination IP and the longest matching route. The panels below show two possible lookup outcomes, not extra network links. PC-A at 192.168.1.10 sends to server 192.168.4.10. The selected path is PC-A, R1, R2, R4, web server. R1 matches the destination to route 192.168.4.0/24 and uses next-hop 10.0.12.2 on R2. Without any matching route, including a default, R1 drops the packet.Packet: source 192.168.1.10 → destination 192.168.4.10PC-A · userR1R2R4Web serverR1’s next hop is R2 · interface IP 10.0.12.2Matching route found192.168.4.0/24 → forward to R2No matching route or defaultDrop the packet
Arrows show the selected packet path; access switches are omitted. R1 uses the packet’s destination IP and the longest matching route. The panels below show two possible lookup outcomes, not extra network links.

Where does that route come from?

OSPF (Open Shortest Path First) is a routing protocol: rules that let routers share network information and calculate routes. It is one way to supply the remote routes R1 needs.

  • Connected route: R1 knows about a network on one of its own working, addressed interfaces.
  • Static route: an administrator enters an instruction telling R1 how to reach another network.
  • Dynamic route: a routing protocol, such as OSPF, learns network information and calculates a path.

These sources can exist on the same router. This lesson compares static routes with OSPF so you can see when automatic updates help.

Compare the three route sources
Three ways a route reaches the routing table
Three ways a route reaches the routing tableTeal line: physical LAN connection. Coral arrow: an engineer’s configuration. Dashed purple arrow: OSPF control information. S and O are alternative examples on R1; the C example is on R4, directly attached to LAN B. These are separate examples for destination 192.168.4.0/24. Connected: R4 has an up interface on LAN B, giving a C route. Static: an engineer configures R1 to use R2, giving an S route. Dynamic: R1 calculates the route from OSPF information, giving an O route if selected.ConnectedLAN B switchR4 · attached routerC · Interface is upStaticEngineer’s PCR1 · remote routerS · Engineer configuresOSPFR2 · neighbourR1 · remote routerO · OSPF calculatesDestination in every example: LAN B · 192.168.4.0/24
Teal line: physical LAN connection. Coral arrow: an engineer’s configuration. Dashed purple arrow: OSPF control information. S and O are alternative examples on R1; the C example is on R4, directly attached to LAN B.

Two paths should mean a way around a failure

R4 is the router connected to the server's LAN. R1 can reach it through R2 or through R3. R2 and R3 are routers along the way, not servers or switches. The two paths provide an alternative if one router-to-router connection fails.

1Two paths, one destination
The task: an office user opens an internal websitehttp://192.168.4.10

PC-A sends a web request to the web server. The routers must find a working path between them.

Two paths, one destinationLAN A reaches LAN B through R2. The lower path through R3 is available but has a higher OSPF cost. PC-A at 192.168.1.10 connects through access switch SW1 to router R1 on LAN A, 192.168.1.0/24. The web server at 192.168.4.10 connects through access switch SW2 to router R4 on LAN B, 192.168.4.0/24. R1 can route through R2 or R3 to R4. Solid grey lines are physical connections; switches forward within each LAN. All physical links are up.cost 1cost 1cost 10cost 1R1R2R3R4SW1 · switchSW2 · switchPC-A · userWeb server192.168.1.10192.168.4.10LAN ALAN B192.168.1.0/24192.168.4.0/24Purple arrow: PC-A → SW1 → R1 → R2 → R4 → SW2 → server

R1–R4: routers join different networks. SW1/SW2: switches connect devices within each LAN; they do not add routed hops or extra OSPF costs.

Grey lines: Ethernet connections. SW1 and SW2 are access switches. Purple arrow: the web request's path. The response travels back; it is not drawn here.

Device IP: 192.168.4.10 identifies this server. Subnet: 192.168.4.0/24 identifies its network, not a device or website. URL: http://192.168.4.10 tells the browser to request a web page at that IP.

Example OSPF route
Destination subnet
192.168.4.0/24
Next hop · router interface IP
10.0.12.2 · R2
Forwarding path
R1 → R2 → R4
OSPF cost
3
Diagram details · example interface map
R1 · RID 1.1.1.1
Gi0/0: 192.168.1.1/24 → LAN A; Gi0/1: 10.0.12.1/30 → R2; Gi0/2: 10.0.13.1/30 → R3.
R2 · RID 2.2.2.2
Gi0/0: 10.0.12.2/30 → R1; Gi0/1: 10.0.24.1/30 → R4.
R3 · RID 3.3.3.3
Gi0/0: 10.0.13.2/30 → R1; Gi0/1: 10.0.34.1/30 → R4.
R4 · RID 4.4.4.4
Gi0/0: 192.168.4.1/24 → LAN B; Gi0/1: 10.0.24.2/30 → R2; Gi0/2: 10.0.34.2/30 → R3.
LAN gateways and switch ports
PC-A gateway: 192.168.1.1. Server gateway: 192.168.4.1. Each access switch uses Gi0/1 to its endpoint and Gi0/2 to its router; endpoints use Ethernet ports.
OSPF assumptions and costs
Area 0; broadcast Ethernet; Hello 10 / Dead 40 seconds; no authentication; LAN interfaces passive. R1–R3 cost 10 in both directions; other outgoing interfaces, including the LANs, cost 1. Switches do not run OSPF here.
LAN A reaches LAN B through R2. The lower path through R3 is available but has a higher OSPF cost.

OSPF gives each connection a cost, a number used to compare paths. It adds the outgoing costs along each path to the destination network. In this example, the upper path costs 3 and the lower path costs 12, including the last connection to LAN B. For these routes to the same network, OSPF chooses the lower total.

OSPF builds a map, then calculates a route

R4 creates records describing its network connections. These are called link-state advertisements (LSAs). The routers pass these records to other routers in the OSPF area. An area is a part of the OSPF network that shares detailed link information.

Each router stores the records and calculates paths from its own position. R1 learns that LAN B is behind R4 and chooses the path through R2. R4 also needs a route back to LAN A so the server's replies can return.

Follow the network information back to R1
2Learn the network before choosing a path
Learn the network before choosing a pathR4 describes its LAN in link-state information. Routers flood LSAs through the area, build their databases and calculate paths locally. PC-A at 192.168.1.10 connects through access switch SW1 to router R1 on LAN A, 192.168.1.0/24. The web server at 192.168.4.10 connects through access switch SW2 to router R4 on LAN B, 192.168.4.0/24. R1 can route through R2 or R3 to R4. Solid grey lines are physical connections; switches forward within each LAN. All physical links are up.cost 1cost 1cost 10cost 1LSAs describeLAN BR1R2R3R4SW1 · switchSW2 · switchPC-A · userWeb server192.168.1.10192.168.4.10LAN ALAN B192.168.1.0/24192.168.4.0/24Dashed arrows: OSPF link-state information
After SPF on R1
Destination subnet
192.168.4.0/24
Next hop · router interface IP
10.0.12.2 · R2
Forwarding path
R1 → R2 → R4
OSPF cost
3
Diagram details · example interface map
R4’s link information · interface IPv4
R4 Gi0/1: 10.0.24.2/30 → R2; Gi0/2: 10.0.34.2/30 → R3; Gi0/0: 192.168.4.1/24 → LAN B.
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.
R4 describes its LAN in link-state information. Routers flood LSAs through the area, build their databases and calculate paths locally.

Now try the same network with static routes

Instead of running OSPF, configure R1 to send LAN B traffic to R2. The other routers also need forwarding and return routes. This command is entered in R1's global configuration mode:

ip route 192.168.4.0 255.255.255.0 10.0.12.2

An untracked static route: R2 is the next hop for LAN B.

3A remote failure leaves the static route unchanged
A remote failure leaves the static route unchangedR1 can still reach R2, so its untracked static route stays installed. In this example R2 has no remaining route to LAN B and drops the packet. PC-A at 192.168.1.10 connects through access switch SW1 to router R1 on LAN A, 192.168.1.0/24. The web server at 192.168.4.10 connects through access switch SW2 to router R4 on LAN B, 192.168.4.0/24. R1 can route through R2 or R3 to R4. Solid grey lines are physical connections; switches forward within each LAN. The R2 to R4 link has failed.cost 1cost 10cost 1Link downR1R2R3R4SW1 · switchSW2 · switchPC-A · userWeb server192.168.1.10192.168.4.10LAN ALAN B192.168.1.0/24192.168.4.0/24The untracked static route still sends packets to R2
Static route on R1
Destination subnet
192.168.4.0/24
Next hop · router interface IP
10.0.12.2 · R2
Forwarding path
Stops at R2
OSPF cost
Not used
Diagram details · example interface map
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
Untracked static route on R1. R2 has no alternate/default route to LAN B. OSPF is not providing recovery in this example.
R1 can still reach R2, so its untracked static route stays installed. In this example R2 has no remaining route to LAN B and drops the packet.

The failure is beyond R1's next hop. R1 can still resolve 10.0.12.2 over its connected link, so the static route remains. Assume R2 has no alternate or default route to LAN B: it drops the traffic. A floating static route on R1 cannot take over while that primary route stays installed. Tracking reachability can change this behaviour; the example has no tracking.

With OSPF, the failure changes the map

  1. R2 and R4 detect that their connection has failed.
  2. They report the change using updated OSPF records.
  3. R1 receives the information and calculates its paths again.
  4. R1 replaces the path through R2 with the working path through R3.

This process is called convergence: the routers process a change and settle on updated routes. It takes time, so packets may be lost while the change is being processed.

See the failure and recovery steps
A failed link changes the route in four stages
A failed link changes the route in four stagesArrows show processing order. Recovery time depends on failure detection, flooding, SPF scheduling and forwarding updates. The R2–R4 link fails. R2 and R4 detect loss, originate changed LSAs, and flood them through the area. R1 updates its LSDB and runs SPF. R1 then selects R3 at next-hop 10.0.13.2 instead of R2 at 10.0.12.2. Forwarding uses the new route after its forwarding state is updated.1R2Detect the R2–R4 failureLink-down indication or neighbour timeout2LSAShare changed link informationOriginate updated LSAs and flood them in the area3R1Update the map and run SPFR1 calculates the surviving path through R34R1Install the route and update forwardingNext hop changes: 10.0.12.2 → 10.0.13.2
Arrows show processing order. Recovery time depends on failure detection, flooding, SPF scheduling and forwarding updates.
4OSPF recalculates and uses the surviving path
OSPF recalculates and uses the surviving pathAfter failure detection, LSA flooding and SPF calculation, R1 installs a path through R3. Both directions still need valid routes and policies. PC-A at 192.168.1.10 connects through access switch SW1 to router R1 on LAN A, 192.168.1.0/24. The web server at 192.168.4.10 connects through access switch SW2 to router R4 on LAN B, 192.168.4.0/24. R1 can route through R2 or R3 to R4. Solid grey lines are physical connections; switches forward within each LAN. The R2 to R4 link has failed.cost 1cost 10cost 1Link downR1R2R3R4SW1 · switchSW2 · switchPC-A · userWeb server192.168.1.10192.168.4.10LAN ALAN B192.168.1.0/24192.168.4.0/24The surviving data path goes through R3
New OSPF route on R1
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
Diagram details · example interface map
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.
After failure detection, LSA flooding and SPF calculation, R1 installs a path through R3. Both directions still need valid routes and policies.

The new route costs 12. Valid return routes and permitting security policies are still required; learning a forward route alone does not prove that an application will work.

More subnets mean more routes to maintain

With static routing, you must update the relevant routers when you add a remote subnet or change a path. A subnet is an IP network such as LAN B's 192.168.4.0/24. More routers and subnets can mean more entries to check.

In this example, there are six subnets. R2 connects directly to two of them. If you use one static route for each remote subnet, with no default or summary routes, R2 needs four static routes. The other routers also need the correct routes, including paths for replies.

Count the static routes in the example
Six subnets create fourteen manual route entries
Six subnets create fourteen manual route entriesEach group of six squares counts the six subnets: two LANs and four /30 transit networks. Teal means connected; coral means a manual remote-subnet route. Assume one explicit static route per remote subnet, with no defaults, summaries or backups. R1 has 3 connected networks and needs 3 remote routes. R2 has 2 connected networks and needs 4 remote routes. R3 has 2 connected networks and needs 4 remote routes. R4 has 3 connected networks and needs 3 remote routes. The total is 14 configured routes.R13 connected3 remote routesR22 connected4 remote routesR32 connected4 remote routesR43 connected3 remote routes3 + 4 + 4 + 3 = 14 static routes to maintain
Each group of six squares counts the six subnets: two LANs and four /30 transit networks. Teal means connected; coral means a manual remote-subnet route. Assume one explicit static route per remote subnet, with no defaults, summaries or backups.

A static default route can be a sensible choice for a branch with one exit. OSPF helps when routers must learn changing networks and choose among paths, at the cost of protocol processing, memory and control traffic. The two approaches can coexist.

Try it: watch a route change

Use an isolated lab with the diagram's four routers already configured for OSPF. On R1 at the privileged EXEC # prompt, run show ip route 192.168.4.10. The route should use R2 at 10.0.12.2 and show cost 3 for this example.

show ip route 192.168.4.10

Privileged EXEC on R1. Inspect the route covering the server IP, its next hop and total OSPF cost.

Disconnect only the R2–R4 lab link. After OSPF processes the change, repeat the command: the next hop should be R3 at 10.0.13.2, with cost 12. Reconnect the link and confirm the lower-cost route returns. This test assumes the illustrated costs and no preferred competing route.

Next, see how OSPF works. The protocol specification is RFC 2328.

Test yourself on static and dynamic routing

Predict · scenario 1

R1 reaches LAN B with ip route 192.168.4.0 255.255.255.0 10.0.12.2 (R2). The link between R2 and R4 fails; R1's link to R2 stays up. Assume there is no tracking and R2 has no alternate route. What does R1 do with traffic for LAN B?

Predict · scenario 2

Using one explicit static route per remote subnet, with no default or summary routes, how many does R2 need in this six-subnet topology?

Predict · scenario 3

What does 'convergence' mean in routing?

Predict · scenario 4

A branch office has one router and a single link to head office. Which is the most sensible choice?

Predict · scenario 5

A router running a link-state protocol learns about a new subnet. What did it receive?

Predict · scenario 6

Which statement about OSPF is true?