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
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
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.
http://192.168.4.10PC-A sends a web request to the web server. The routers must find a working path between them.
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.
- 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
- 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.
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
- 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
- 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.
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.2An untracked static route: R2 is the next hop for LAN B.
- 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
- 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.
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
- R2 and R4 detect that their connection has failed.
- They report the change using updated OSPF records.
- R1 receives the information and calculates its paths again.
- 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
- 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.
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
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.10Privileged 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
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?
Using one explicit static route per remote subnet, with no default or summary routes, how many does R2 need in this six-subnet topology?
What does 'convergence' mean in routing?
A branch office has one router and a single link to head office. Which is the most sensible choice?
A router running a link-state protocol learns about a new subnet. What did it receive?
Which statement about OSPF is true?