Sub topic 5
Dynamic routing: routers sharing what they know
What this chapter covers and what it assumes
This chapter explains how a dynamic routing protocol fills a routing table without an administrator typing each route. It assumes you already know three things:
- IPv4 addressing and CIDR prefix notation, such as 10.2.0.0/16.
- The difference between a router, a switch and a host.
- Basic command-line use on a router or a Linux host.
It also assumes you know that a router forwards a packet by finding the longest matching prefix in its routing table. Static routes are the baseline here: the chapter keeps asking what a protocol does that a hand-entered route cannot.
The idea in one paragraph
A dynamic routing protocol is a set of rules that lets routers exchange information about the networks they can reach. Each router starts knowing only its own connected networks. It tells its neighbors what it knows, learns what they know, and builds routes from that information. When a link fails or a new network appears, the routers update each other and the routing tables change without human action.
The routing table itself does not change. It still holds prefixes, next hops and exit interfaces, and the forwarding decision is still longest-prefix match. A protocol is only another source of entries.
Where a dynamic route comes from
A router on a dynamic network repeats the same cycle. It is worth learning as a pipeline, because most failures can be placed at one step of it.
- Discover neighbors. The router sends hello messages on its interfaces and finds other routers that run the same protocol.
- Advertise. The router tells its neighbors which prefixes it can reach and, depending on the protocol, how good each path is.
- Learn and compute. The router collects advertisements from its neighbors and selects the best path to each prefix.
- Install. The router offers its best path for each prefix to the routing table. The table accepts it if no route from a more trusted source already exists for that exact prefix.
- React. When a neighbor stops responding or sends a changed advertisement, the router repeats steps 3 and 4.
A small example
Three routers connect in a line. R1 has the LAN 10.1.0.0/16. R3 has the LAN 10.3.0.0/16. R2 sits in the middle.
With static routing, you would enter a route for 10.3.0.0/16 on R1 and R2, and a route for 10.1.0.0/16 on R2 and R3. That is four commands for two LANs.
With a dynamic protocol, you enable the protocol on each router and tell it which interfaces to use. R3 advertises 10.3.0.0/16 to R2. R2 installs it and advertises it to R1. R1 now has a route to 10.3.0.0/16 with R2 as the next hop. The same happens in the other direction. If you add a third LAN behind R3, R3 advertises it and no other router needs a command.
The configuration for OSPF, a common link-state protocol, shows how short this can be. This is the same style used in the OSPF example elsewhere in this tutorial:
! Cisco IOS: enable OSPF on interfaces that fall inside 10.1.0.0/16
router ospf 1
router-id 1.1.1.1
network 10.1.0.0 0.0.255.255 area 0The network statement does two jobs. It selects which interfaces run OSPF, and it makes the networks on those interfaces eligible for advertisement. Beginners often read it as "advertise this prefix", which is not quite right: it matches interface addresses against a wildcard mask.
What a dynamic protocol gives you
- Less manual work as the network grows. Adding a network means configuring it where it attaches, not on every router.
- Automatic reaction to failures. If a link goes down, routers can find another path and install it.
- Multiple paths. A protocol can compare paths using a metric and choose the best one, and some can use several equal paths at once.
- Fewer human errors in large tables. A mistyped next hop on one of many static routes is hard to find. A protocol computes next hops from real neighbors.
What it costs
Dynamic routing is not free, and the costs explain why static routes still exist.
| Cost | Detail |
|---|---|
| CPU and memory | Routers store neighbor state and a database or table of learned routes, and they run path calculations. |
| Bandwidth | Hellos and updates use link capacity, which matters on slow WAN links. |
| Complexity | You must understand protocol timers, areas, metrics and neighbor requirements to troubleshoot. |
| Convergence time | After a change, tables may be briefly inconsistent while routers catch up. |
| Trust | A router accepts what neighbors say. A misconfigured or hostile neighbor can advertise bad routes. |
The convergence cost has real consequences. During convergence, one router may still point at a failed path while another already uses the new one. Packets can be dropped, or in the worst case forwarded in a loop until the TTL field reaches zero. Later chapters treat convergence, metrics and the protocol families in detail. Here, remember that "automatic" means automatic after a delay, not instantly.
Two families, briefly
Protocols differ mainly in what routers tell each other.
- Distance-vector protocols, such as RIP, send neighbors a list of prefixes and a distance to each. A router knows only what its neighbors report, not the full network layout.
- Link-state protocols, such as OSPF, send descriptions of links. Every router builds the same map of the network and calculates paths from it.
Both are interior protocols used inside one organization. A third approach, path-vector, is used by BGP between organizations. The spine of this tutorial covers each later, so do not worry about the details yet.
Authentication and trust
Because a router believes its neighbors, a protocol should limit who can be a neighbor. Common protections include:
- Authentication on the protocol messages, so only routers with a shared key form a neighbor relationship.
- Passive interfaces, which stop hello messages on interfaces that face users or hosts. The network is still advertised, but nobody on that LAN can become a neighbor.
- Filters that restrict which prefixes you accept from a neighbor.
A static route has none of this risk, since nothing is learned from outside the device. That is a real advantage on a small edge router.
Dynamic routes and the routing table
A protocol competes with other sources for table entries. Suppose a router has an OSPF route and a static route to the same prefix. The router prefers the source with the lower administrative distance. OSPF defaults to 110 and a normal static route to 1, so the static route wins unless you change its distance. The separate chapter on administrative distance explains this. For now, note that a dynamic route does not automatically override a static one.
A dynamic route also has to match to be used. If the protocol learns 10.2.0.0/16 but a static route for 10.2.5.0/24 exists, then traffic to 10.2.5.7 follows the /24, because longest-prefix match runs before any comparison of sources. Mixed networks produce surprises like this often.
Checking what a protocol installed
You confirm the result with the same commands you use for static routes, now filtered by source:
! Cisco IOS: inspect the routing table
show ip route
show ip route static
show ip route ospf
show ip route 10.2.5.7Learned OSPF routes are marked with an O in the output. Each shows the prefix, the administrative distance and metric in brackets, such as [110/20], the next hop, and the exit interface. On a Linux host, ip route show lists the table, and ip route get 10.2.5.7 shows which entry the kernel would use for one destination.
A route that you expect but cannot find usually points to one of these causes:
- The neighbor relationship never formed, because of mismatched settings, an interface that is down or authentication that does not match.
- The
networkstatement or interface setting did not match the interface, so the protocol never ran on it. - The neighbor does not advertise the prefix, or a filter blocks it.
- A route from a more trusted source for the same prefix has taken the table entry.
Check the neighbor state first. A protocol that has no neighbors has nothing to learn.
Summary
- A dynamic protocol lets routers discover neighbors, advertise prefixes, compute best paths and install them in the table.
- It reduces manual work and reacts to failures, at the cost of resources, complexity, convergence delay and exposure to bad advertisements.
- The table still decides by longest-prefix match, and administrative distance decides between sources for the same prefix.
- When a learned route is missing, check neighbors first, then interface matching, then advertisements and filters, then competing sources.
Exercise
A router has a dynamic OSPF route to 10.2.0.0/16 and a normal static route to 10.2.0.0/16 with the default distance. Which is installed, and why? What changes if the static route is configured with distance 200?
Show answer
The static route is installed. A normal static route has administrative distance 1 and OSPF has 110, and the lower value is trusted more for the same prefix. With distance 200 the static route loses to OSPF and stays out of the table until the OSPF route disappears, which is a floating static route.
Exercise
You enabled OSPF on R2, but show ip route ospf shows no routes. List the first two things you check and why.
Show answer
First check that a neighbor relationship exists, because a router with no neighbors learns nothing. Then check that the network statement matches the interface addresses, because if no interface matches, OSPF does not run on it and never sends hellos.