// Lesson 28 of 49 · IP routing
Reading the routing table
For every packet, a router looks up the destination IP in its routing table and sends the packet to the matching next hop or exit interface. If nothing matches and there is no default route, the packet is dropped.
Reading an entry
R1# show ip route
Codes: L - local, C - connected, S - static, O - OSPF, D - EIGRP, * - candidate default
Gateway of last resort is 203.0.113.1 to network 0.0.0.0
S* 0.0.0.0/0 [1/0] via 203.0.113.1
10.0.0.0/8 is variably subnetted, 4 subnets, 3 masks
C 10.1.12.0/30 is directly connected, GigabitEthernet0/1
L 10.1.12.1/32 is directly connected, GigabitEthernet0/1
O 10.1.30.0/24 [110/2] via 10.1.12.2, 00:14:51, GigabitEthernet0/1
S 10.1.40.0/24 [1/0] via 10.1.12.2
Take the OSPF line apart:
| Part | Meaning |
|---|---|
O |
Learned from OSPF |
10.1.30.0/24 |
Destination prefix |
[110/2] |
[administrative distance / metric] |
via 10.1.12.2 |
Next-hop address |
00:14:51 |
Age of the route |
GigabitEthernet0/1 |
Exit interface |
C routes appear for every up interface with an address; L (local) is the router's own address as a /32.
How the best route is chosen — in this order
1. Longest prefix match
The most specific matching route wins, regardless of the source. A packet to 10.1.30.25 matching both 10.0.0.0/8 and 10.1.30.0/24 uses the /24. The default route 0.0.0.0/0 matches everything but is the least specific, so it is used only when nothing else matches.
2. Administrative distance (AD)
When different sources offer the same prefix, the lowest AD (trustworthiness) wins and only that route is installed:
| Source | AD |
|---|---|
| Connected | 0 |
| Static | 1 |
| eBGP | 20 |
| EIGRP (internal) | 90 |
| OSPF | 110 |
| IS-IS | 115 |
| RIP | 120 |
| EIGRP (external) | 170 |
| iBGP | 200 |
| Unusable | 255 |
3. Metric
Within one routing protocol, the lowest metric wins — OSPF uses cost, RIP uses hop count, EIGRP uses a composite of bandwidth and delay. Equal metrics give equal-cost multipath (ECMP): traffic is shared across the paths.
Useful variations
R1# show ip route 10.1.30.25 ! which route is used for this address?
R1# show ip route ospf ! only OSPF routes
R1# show ip route connected
Key points
- Longest prefix match first, then AD, then metric.
[AD/metric]sits after the prefix.- C = connected subnet, L = the router's own address.
- The default route (gateway of last resort) is used only when nothing more specific matches.
Sign in to save your lesson progress across devices. You can read every published lesson without an account.