Technischer Leitfaden

How Routers Choose a Route: Longest Prefix Match, Administrative Distance, and Metrics

Von Subnetica · Veröffentlicht am 24. August 2026 · Aktualisiert am 24. August 2026

When several routes could reach a destination, the answer depends on whether you are comparing different prefixes, different sources for the same prefix, or different paths inside one routing protocol. Keeping those decisions separate prevents many route-selection mistakes.

1. Longest prefix match chooses the matching destination range

Suppose the forwarding table contains:

0.0.0.0/0
10.0.0.0/8
10.20.0.0/16
10.20.30.0/24

A packet for 10.20.30.42 matches all four entries, but the /24 is the most specific match and wins. A packet for 10.20.31.42 matches the default, /8, and /16, so the /16 wins. This forwarding lookup happens after the system decides which candidate for each prefix is installed.

A more-specific prefix can beat a less-specific route regardless of the less-specific route’s source preference. A static 10.0.0.0/8 does not override an installed 10.20.30.0/24 merely because static routes are preferred in a particular vendor’s table.

2. Source preference compares routes to the same prefix

If static, OSPF, and BGP all offer 10.20.30.0/24, the implementation needs a rule for preferring one source. Cisco IOS calls this administrative distance and assigns familiar defaults such as connected 0, static 1, OSPF 110, and RIP 120. Those numbers are Cisco defaults, not a universal law.

FRRouting has its own administrative-distance configuration, while Linux route lookup exposes metrics, tables, and policy routing rather than Cisco’s model. Do not copy a Cisco number into a Linux explanation without identifying the layer and implementation. In FRR, show ip route shows the selected RIB view; on Linux, ip route shows kernel routes and ip rule reveals policy-table selection.

3. Protocol metrics choose among paths from one protocol

OSPF commonly sums interface costs; RIP compares hop count and treats a path beyond its finite maximum as unreachable. The exact metric calculation and tie-breaking rules belong to the protocol, not to longest-prefix match.

Which route wins?

Specificity

Routes are 172.16.0.0/12 via R1 and 172.16.20.0/24 via R2. Destination 172.16.20.9 uses R2. Destination 172.17.20.9 uses R1.

Same prefix, different sources

Static and OSPF both offer 192.0.2.0/24 in Cisco IOS. With default distances, static wins. If OSPF instead offers 192.0.2.0/25, that more-specific route wins for addresses in the /25 even though OSPF is less preferred as a source.

Equal-cost paths

Two OSPF paths have equal cost and pass the platform’s ECMP rules. The device can install multiple next hops and distribute flows across them. Per-packet versus per-flow behavior depends on platform and configuration.

Next-hop resolution, RIB, and FIB

A selected route still needs a usable next hop. Recursive resolution may use another route to reach that address; if resolution fails, the route may not enter the forwarding table. A RIB is the selected control-plane view; a FIB is the installed forwarding representation. The FRRouting and Linux routing-table guide explains the protocol-daemon, Zebra, and kernel boundaries.

# Cisco-style
show ip route
show ip route 10.20.30.42
show ip cef 10.20.30.42

# Linux
ip route
ip route get 10.20.30.42
ip rule
ip route show table all

Static routes are manually supplied candidates; dynamic protocols learn candidates and withdraw or replace them. A default route is simply the least-specific /0 fallback.

When the route exists but traffic takes another path

  1. Ask for the exact destination with show ip route <destination> or ip route get <destination>.
  2. Look for a more-specific connected, VPN, or policy route.
  3. Check ip rule and all Linux tables; ordinary ip route may not be the selected table.
  4. Inspect ECMP next hops and hashing behavior.
  5. Verify recursive resolution, neighbor state, and interface status.
  6. Compare FRR’s RIB view with the kernel FIB and account for recent reconvergence.
  7. Check the return path; asymmetric routing can make a correct forward lookup look broken.

Use the Routing curriculum, then return to the subnetting guide for examples where an incorrect prefix creates an unexpectedly specific route.

Weiterführende Lektüre

Den diagnostischen Kreislauf weiter üben

Eine Routing-Tabelle zu lesen oder ein Präfix zu berechnen ist nützlich; es in einem Live-Netzwerk zu beheben ist besser. Subnetica kombiniert Lektionen, bewertete Prüfungen und praktische virtuelle Labs mit FRRouting und Linux hinter einer Cisco-artigen Kompatibilitätsschicht für unterstützte Befehle und Ausgaben. Es handelt sich nicht um Cisco IOS.

subnetica© 2026 · Lernen, üben, behalten.
Über unsFAQDatenschutzerklärungNutzungsbedingungenBarrierefreiheitcontact@subneti.ca
CCNA ist eine eingetragene Marke von Cisco Systems, Inc. CompTIA Network+ und CompTIA Security+ sind eingetragene Marken der CompTIA, Inc. Subnetica ist eine unabhängige Lernplattform und steht in keiner Verbindung zu Cisco Systems, Inc. oder CompTIA, Inc. und wird von diesen weder unterstützt noch gesponsert.