Sub topic 10
Administrative distance: choosing between route sources
This chapter assumes you know IPv4 addressing and CIDR prefixes, the difference between a router, a switch and a host, and basic command-line use on a router or Linux host. It also assumes you have seen longest-prefix match and the idea of static and dynamic routes from earlier chapters.
The problem: two sources, one prefix
A router can learn the same destination from several places at once. You might type a static route for 10.2.0.0/16, while OSPF also advertises 10.2.0.0/16. Both entries describe the identical prefix, so longest-prefix match cannot choose between them. Their metrics also cannot be compared. An OSPF cost counts link bandwidth, and a RIP metric counts hops. Comparing 20 to 3 across those two units means nothing.
Administrative distance (AD) solves this. It is a number from 0 to 255 that a router assigns to each route source to rank how trustworthy that source is. Lower is more trusted. When several sources offer the same prefix and prefix length, the router installs the route from the source with the lowest AD. Only that route enters the routing table.
AD is local to one router. It is never advertised to neighbors, so two routers in the same network can hold different AD values for the same protocol.
Where AD sits in the decision order
The router applies its tie-breakers in a fixed order. Each step only matters if the previous one did not settle the choice.
- Longest prefix. The most specific matching route wins, whatever its AD or metric.
- Administrative distance. Among routes with the same prefix length, the lowest AD wins.
- Metric. Among routes from the same source with the same AD, the lowest metric wins. If metrics tie, many routers install several equal-cost paths.
A common mistake is to think a low AD can beat a more specific route. It cannot. A /24 learned from a source with AD 200 still beats a /16 with AD 1 for any address inside the /24.
Default distance values
Cisco IOS ships with these defaults. Other vendors use similar but not identical numbers.
| Route source | Default AD |
|---|---|
| Connected interface | 0 |
| Static route (next hop or exit interface) | 1 |
| External BGP (eBGP) | 20 |
| Internal EIGRP | 90 |
| OSPF | 110 |
| IS-IS | 115 |
| RIP | 120 |
| External EIGRP | 170 |
| Internal BGP (iBGP) | 200 |
| Unknown or unusable | 255 |
Three points follow from this table.
- A directly connected network (AD 0) always beats everything else for that prefix.
- A static route (AD 1) beats every dynamic protocol by default. This is why a forgotten static route can override a perfectly healthy OSPF route without any warning.
- An AD of 255 means the router will not install the route at all.
Linux does not use the term administrative distance for kernel routes. The closest equivalent is the metric on a route, and routing daemons such as FRR assign their own distances using the same ideas. The examples below use Cisco IOS syntax.
Reading AD in the routing table
The routing table shows AD and metric together in square brackets as [AD/metric].
R1# show ip route 10.2.5.7
Routing entry for 10.2.0.0/16
Known via "ospf 1", distance 110, metric 20, type intra area
Last update from 192.168.1.2 on GigabitEthernet0/0, 00:04:12 ago
Routing Descriptor Blocks:
* 192.168.1.2, from 2.2.2.2, 00:04:12 ago, via GigabitEthernet0/0
Route metric is 20, traffic share count is 1The line Known via "ospf 1", distance 110, metric 20 tells you which source won and with what values. In show ip route output, the same route appears as O 10.2.0.0/16 [110/20] via 192.168.1.2. The letter O marks OSPF and S marks static.
Worked example: static versus OSPF
Suppose R1 learns 10.2.0.0/16 from OSPF and you also configure a static route to the same prefix.
router ospf 1
router-id 1.1.1.1
network 10.1.0.0 0.0.255.255 area 0
ip route 10.2.0.0 255.255.0.0 192.168.2.2With default values, the static route has AD 1 and OSPF has AD 110. The router installs the static route and keeps the OSPF route only as a candidate that is not in the table. Traffic now follows 192.168.2.2 even if OSPF has the better path. If the static next hop fails and the router removes the static route, the OSPF route is installed.
You can confirm which source won with:
show ip route 10.2.5.7
show ip route static
show ip route ospfIf the prefix shows up under show ip route static and not under show ip route ospf, the static route is winning.
Changing AD on purpose
You can raise or lower AD to control which source wins. There are two common places to do it.
On a static route, add the distance as the last argument:
ip route 10.2.0.0 255.255.0.0 192.168.2.2 200This static route now has AD 200. OSPF at 110 beats it, so the static route waits in the configuration without being installed. This is a floating static route, and the next chapters use it as a backup path.
On a dynamic protocol, set the distance for the whole protocol:
router ospf 1
distance 90This gives every OSPF route AD 90. Use it carefully. A protocol-wide change affects every prefix, and it can quietly reorder your preferences. Cisco IOS can also restrict a distance to routes from one neighbor with distance 95 2.2.2.2 0.0.0.0.
Pick values with the ordering in mind rather than the exact numbers. A backup must sit above the primary source's AD. Setting a backup static route to AD 100 beats nothing if the primary is OSPF at 110, because 100 is lower and the static route wins at once.
Edge cases and gotchas
- Same prefix length is required. AD only decides between routes for the same prefix and mask. A static /16 and an OSPF /24 are different entries, and both stay in the table. The /24 handles traffic inside it.
- Equal AD, different protocols. If two routes tie on AD, the router falls back to metric, but metrics from different protocols are not comparable. Avoid designs that depend on this. Give each source a distinct AD.
- Routing loops through mutual redistribution. When you redistribute routes between two protocols, external routes carry their own AD values. A badly chosen AD can make a router prefer a looped-back copy of a route it originally advertised. Redistribution is covered later in this tutorial.
- A static route to an exit interface is treated as directly connected on some platforms, which can give it AD 0 for ARP behavior. Prefer a next-hop address on Ethernet links.
- Static routes that depend on a dead next hop. A static route with a next hop stays installed as long as the router can resolve that next hop through some route. If the next hop is reachable by another path, the static route can remain installed even though the intended link is down. Track objects or IP SLA are the usual fix, and floating routes depend on this behavior working correctly.
- AD is not preference among paths of one protocol. Two OSPF paths to one prefix have the same AD. OSPF chooses between them by cost.
Linux comparison
On a plain Linux host, the kernel has a single routing table per policy and chooses among routes with the same prefix by metric, where lower wins. You can add a backup by giving it a higher metric.
sudo ip route add 10.2.0.0/16 via 192.168.1.2 dev eth0 metric 100
sudo ip route add 10.2.0.0/16 via 192.168.2.2 dev eth1 metric 200
ip route show 10.2.0.0/16
ip route get 10.2.5.7Both routes appear in ip route show, and ip route get reports the one with metric 100. This resembles a floating static route, though it is a metric, not an administrative distance. If the first interface goes down, the kernel removes that route and uses the second.
Summary of the model
- Longest prefix chooses first. AD chooses between sources for the same prefix. Metric chooses within a source.
- Lower AD is more trusted. Defaults: connected 0, static 1, eBGP 20, OSPF 110, RIP 120.
- AD is local, never advertised, and can be tuned per static route or per protocol.
- A higher AD on a backup route keeps it out of the table until the primary disappears.
Exercise
R1 has an OSPF route to 10.2.0.0/16 (default AD) and a static route to 10.2.0.0/16 configured as ip route 10.2.0.0 255.255.0.0 192.168.2.2 150. Which route does R1 install for 10.2.5.7? Now you add an OSPF-learned route to 10.2.5.0/24. Which route handles 10.2.5.7 after that, and why?
Show answer
First, OSPF is installed, because its AD of 110 is lower than the static route's AD of 150. The static route is held back as a floating backup. After the /24 appears, the /24 OSPF route handles 10.2.5.7. Longest-prefix match comes before administrative distance, so the more specific /24 wins regardless of AD, and the /16 is only used for addresses outside the /24.
Exercise
You want a static route to 10.3.0.0/16 to act as a backup for a route learned from RIP. What range of AD values is valid for the static route, and what happens if you pick 120?
Show answer
The AD must be above RIP's default of 120, so 121 to 254 works (255 means never installed). If you pick 120, the two sources tie on AD. The router then compares metrics, which are in different units, so the result is not a reliable backup design. Choose a value such as 130 or 200.