Sub topic 3
Reading a routing table
This chapter assumes you know what an IP address and a subnet are, and that you can read basic Linux terminal output. Here you learn what each column of a routing table means, so that later chapters can explain how a router picks an entry.
What a routing table is
A routing table is a list of rules. Each rule says: "packets for this destination prefix go out this interface, toward this next hop." A router and an ordinary host both have one. The host's table is just shorter.
Every entry has the same core parts:
- Destination prefix: a network written in CIDR notation, such as
10.1.0.0/16. - Next hop: the IP address of the neighboring router to hand the packet to. Directly attached networks have no next hop.
- Outgoing interface: the port or network card the packet leaves through.
- Source of the route: how the entry got there (connected, static, or learned from a routing protocol).
- Metric: a number used to compare routes to the same prefix. Lower is usually better.
Reading real output
Run this on a Linux machine:
ip route showA typical result looks like this:
default via 192.0.2.1 dev eth0 proto dhcp metric 100
10.1.0.0/16 via 192.0.2.3 dev eth0 proto static
192.0.2.0/24 dev eth0 proto kernel scope link src 192.0.2.50Read each line from left to right:
| Line | Meaning |
|---|---|
| `default via 192.0.2.1 dev eth0` | Anything with no more specific match goes to router 192.0.2.1 through `eth0`. The `proto dhcp` tag shows DHCP installed it. |
| `10.1.0.0/16 via 192.0.2.3 dev eth0` | Traffic for 10.1.x.x goes to next hop 192.0.2.3. The `proto static` tag shows an administrator added it. |
| `192.0.2.0/24 dev eth0 scope link` | This network is directly attached. There is no `via`, so the host sends to the destination itself. |
The src 192.0.2.50 field on the last line is the source address the host picks for packets sent over that route.
Route sources
The proto field tells you where a route came from. Three kinds matter most:
- Connected: created automatically when an interface gets an address and prefix. Linux labels these
proto kernel. - Static: typed in by an administrator.
- Dynamic: learned from a routing protocol such as OSPF or BGP.
If two sources offer a route to the same prefix, the router needs a tie-breaker. A later chapter covers metrics and administrative distance.
Asking the table a question
You rarely need to scan the table by eye. Ask the kernel which entry a destination would use:
ip route get 10.1.2.3The output names the route, next hop, interface, and source address. This is the quickest check when traffic goes the wrong way.
Common mistakes
- Reading the table top to bottom and stopping at the first match. Order in the output does not decide the winner. Longest prefix match does, and the next chapter covers it.
- Forgetting that
defaultis just0.0.0.0/0. - Confusing the next hop with the final destination. The next hop is only the neighbor for the next step.
Exercise
In the line 10.1.0.0/16 via 192.0.2.3 dev eth0 proto static, which part is the next hop, and how did the route get into the table?
Show answer
The next hop is 192.0.2.3, the router the packet is handed to. The proto static tag shows an administrator configured the route manually.
Exercise
A table line reads 192.0.2.0/24 dev eth0 scope link with no via. What does this tell you about the destinations in that prefix?
Show answer
They are on a directly connected network. The host delivers packets straight to the destination on eth0 instead of using a next-hop router.