Sub topic 10
Administrative distance: choosing between route sources
This chapter assumes you know CIDR prefixes, the difference between a router and a host, and how longest-prefix match picks the most specific route. It covers what happens when two different sources offer a route to the same prefix.
The problem: two sources, one prefix
Longest-prefix match chooses between routes of different lengths. It does not help when a static route and an OSPF route both describe 10.2.0.0/16. Metrics cannot settle this either, because each protocol measures cost in its own units. An OSPF cost of 20 and a RIP hop count of 3 cannot be compared.
Administrative distance (AD) solves this. It is a number from 0 to 255 that a router assigns to each route source. The source with the lower AD is more trusted, and its route goes into the routing table. Metrics are only compared among routes from the same source.
Typical default values
These are Cisco IOS defaults. Other vendors use similar but not identical numbers.
| Route source | Default AD |
|---|---|
| Connected interface | 0 |
| Static route | 1 |
| eBGP | 20 |
| OSPF | 110 |
| RIP | 120 |
| iBGP | 200 |
A distance of 255 means the source is untrusted and its routes are never installed.
The order of decisions
A router applies the rules in a fixed order:
- Longest prefix wins, so the most specific route is chosen first.
- If several sources offer the same prefix, the lowest AD wins.
- If one source offers several routes to that prefix, the lowest metric wins.
Worked example
A router learns 10.2.0.0/16 from OSPF (AD 110). An administrator then adds this static route:
ip route 10.2.0.0 255.255.0.0 192.168.1.2The static route has AD 1, so it replaces the OSPF route in the routing table. OSPF still knows about its route. It just is not used while the static route exists.
You can change the distance by adding it at the end of the command. This static route has AD 200:
ip route 10.2.0.0 255.255.0.0 192.168.2.2 200Now OSPF (110) wins, and the static route waits in reserve. The next chapter builds on this idea as a floating static route.
Checking which source won
The routing table shows the AD and metric in brackets as [AD/metric].
show ip route 10.2.5.7A line such as O 10.2.0.0/16 [110/20] via 192.168.1.2 means the route came from OSPF (O), has AD 110 and has metric 20. A line starting with S and showing [1/0] is a static route.
Common errors
- Comparing metrics across protocols. Only AD decides between sources. Metrics are never compared between them.
- A static route that never appears. If a lower-AD source already holds the prefix, the static route stays out of the table. Check the AD you set.
- A static route that overrides a protocol by accident. The default AD of 1 beats every dynamic protocol, so a forgotten static route can hide a better dynamic path.
- Expecting AD to affect a more specific route. A /24 from RIP still beats a /16 static route for addresses inside the /24, because prefix length is checked before AD.
Exercise
A router has a static route to 10.5.0.0/16 with AD 1 and an OSPF route to 10.5.0.0/16 with AD 110. It also has an OSPF route to 10.5.8.0/24. Which route does it use for a packet to 10.5.8.20, and which for a packet to 10.5.9.20?
Show answer
For 10.5.8.20 it uses the OSPF /24 route, because longest-prefix match is applied before AD. For 10.5.9.20 only the /16 routes match, so AD decides and the static route (AD 1) wins over OSPF (AD 110).
Exercise
You want a static route to 10.2.0.0/16 to be used only when OSPF has no route to it. What AD should you give the static route?
Show answer
Any value above 110, for example 200. OSPF's route then has the lower AD and wins while it exists, and the static route is installed only when the OSPF route disappears.