Read a sample: 1. The Router's Two Decisions
A packet arrives at a router with a destination IPv4 address. The router must decide what to do with it: deliver it locally, forward it toward another device, or discard it if no usable forwarding information exists.
That description sounds like one decision. In practice, it is easier to understand as the result of two related decisions made at different points in the routing process.
First, the router determines which routes belong in its routing table. It may learn about a destination in several ways: an interface may be directly connected to the network, an administrator may configure a static route, or a routing protocol may advertise a path. When eligible sources compete for the same destination prefix, the router needs a way to prefer one source over another.
Second, when a packet requires forwarding, the router looks for the installed route that best matches the packet’s destination address. If several installed prefixes match, the router uses the longest matching prefix—the most specific match.
These decisions are related, but they answer different questions:
- Route installation: Which available route or routes should the router place in the routing table for a destination prefix?
- Packet forwarding: Which installed prefix is the best match for this particular destination address?
Keeping those questions separate is one of the most useful habits you can develop for routing-table problems. It prevents a tempting mistake: seeing a route with a preferred administrative distance and assuming that it must win every forwarding decision.
A route describes a destination and how the router can reach it. For IPv4, the destination is normally expressed as a network prefix, such as 192.0.2.0/24. The prefix represents a range of addresses. The /24 indicates that the first 24 bits identify the network portion.
A route also has forwarding information. Depending on the route and how it was learned, that information may identify an outgoing interface, a next-hop address, or both. A next hop is the neighboring router or other reachable device to which traffic is directed on the next leg of its journey.
Imagine that a router has these routes installed:
The first prefix covers addresses from 192.0.2.0 through 192.0.2.255. The second covers 192.0.2.128 through 192.0.2.255. The ranges overlap: every address in the /25 also belongs to the /24.
For a packet destined for 192.0.2.50, only the /24 matches. For a packet destined for 192.0.2.200, both prefixes match, but the /25 is longer and therefore more specific. The router selects the /25.
The important point is that both routes can be installed at the same time. They describe different prefixes, even though some of the addresses covered by those prefixes overlap. The router does not have to discard the /24 simply because a /25 exists. The broader route can still serve destinations outside the more-specific range.
Before examining that forwarding lookup in detail, consider how routes become available to the lookup in the first place.
A router can have multiple sources of information about the same destination prefix. For example, an administrator might configure a static route for 192.0.2.0/24, while a dynamic routing protocol also provides a route to 192.0.2.0/24.
Assume both routes are eligible for installation:
The two candidates describe the same prefix. In this simplified example, the router prefers the candidate with the lower administrative distance, so it installs the static route through 10.0.0.2.
Administrative distance, often abbreviated AD, expresses a router’s preference for one route source over another. A lower value is preferred. The values in this example are representative of a standard static route and an OSPF-learned route on Cisco devices, respectively. A particular configuration can change administrative distance, so use the values supplied by the scenario rather than assuming every route has its default value.
The dynamically learned route does not become the forwarding choice merely because it exists as a candidate. Under the stated conditions, it is not the route installed for that prefix. If the preferred route later becomes unavailable and the other candidate remains eligible, the router may install the alternative. Route availability and backup behavior deserve their own careful treatment; for now, focus on the distinction between a candidate route and an installed route.
Eligibility matters. A configured route is not automatically usable just because a configuration line exists. For example, a static route that names a next hop needs a usable way to reach that next hop. Similarly, a route associated with an unavailable interface may not remain installed. When a problem asks you to compare administrative distances, check whether it has already told you the candidates are usable. Do not assume that the lowest number can rescue an otherwise ineligible route.
Administrative distance is also not the only consideration in route selection. Within a routing protocol, a metric helps distinguish paths according to that protocol’s rules. Some scenarios can result in multiple paths being installed. The immediate lesson is narrower: when eligible routes from different sources compete for the same prefix, administrative distance is a source-preference mechanism used in deciding what gets installed.
Once routes are installed, a forwarding lookup asks a different question. The router examines the destination address of the packet and finds the installed prefixes that contain that address.
Consider this simplified installed routing table. Assume both listed next hops are reachable:
Suppose the packet’s destination is 192.0.2.200.
1. 192.0.2.200 belongs to 192.0.2.0/24. 2. It also belongs to 192.0.2.128/25. 3. The /25 is longer than the /24.…