Reading routes and default routes
On this page
Router has two interfaces. A packet arrives on home, but that does not tell router which interface should carry it next. You will read the entries that choose an outgoing interface and next hop, then apply the same rule on laptop.
Before you start
Section titled “Before you start”Finish Local delivery and gateway delivery. Use the starting lab with modes off. Leave machine shells and run netlab reset from the VM if needed. Run this lesson’s netlab shell … -- … commands from the VM prompt. They read settings without changing them.
Read laptop’s two choices
Section titled “Read laptop’s two choices”Run netlab shell laptop -- ip route. A route is an instruction for reaching destinations in a stated range. A routing table is a machine’s collection of those instructions. The printed list has two lines. Read the subnet line first, although Linux prints it second.
The entry beginning 10.77.10.0/24 says that destinations in that subnet are directly reachable through eth0. This is a connected route, an entry for a network attached to the machine. It needs no gateway after via because the destination can be the local next hop.
The line beginning default supplies the remaining choice. A default route is the route used when no more specific route matches. Laptop hands those packets to 10.77.10.1 through eth0.
Read laptop’s routes
default via 10.77.10.1 dev eth0
10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.10 via 10.77.10.110.77.10.0/24src 10.77.10.10Reading the output
Pick a step to match a marked part of the output to the picture.
Steps (7)
- Fallback. Fallback: default. Internet layer. Shown on laptop's eth0 as: laptop. The fallback matches when no longer prefix does.
- Next hop. Next hop: via 10.77.10.1. Internet layer. Shown on laptop's eth0 as: Next hop. This local router receives frames for remote packets.
- Interface. Interface: dev eth0. Internet layer. Shown on laptop's eth0 as: eth0. Send through this interface.
- Connected range. Connected range: 10.77.10.0/24. Internet layer. Shown on laptop's eth0 as: Connected range. Destinations in this subnet can be reached directly.
- Entry source. Entry source: proto kernel. Internet layer. Shown on laptop's eth0 as: laptop. The kernel installed this connected route.
- Local link. Local link: scope link. Internet layer. Shown on laptop's eth0 as: eth0. These destinations are reachable on the attached link.
- Preferred source. Preferred source: src 10.77.10.10. Internet layer. Shown on laptop's eth0 as: Preferred source. Laptop uses this source address for its own packets on this route.
| Part of a route line | What it is |
|---|---|
default |
Fallback destination range |
via 10.77.10.1 |
Next hop on home |
dev eth0 |
Outgoing interface |
10.77.10.0/24 |
Directly connected destination range |
proto kernel |
Entry installed by the kernel |
scope link |
Destinations reachable on this link |
src 10.77.10.10 |
Preferred source for laptop’s own packets |
The src setting does not tell router to replace a forwarded packet’s source. It supplies a source choice for traffic the machine itself originates. Keep that distinction when comparing a route read with a forwarded frame.
Read the router’s own networks
Section titled “Read the router’s own networks”The replay includes ip route on router and web. Router lists the home subnet through eth0 and the site subnet through eth1. It has no default route. Web lists its own site subnet and a default through the site side of router.
Predict: without a default, can router reach web? Can it reach an address outside the lab?
learner@rootvolt:~$ netlab shell laptop -- ip route[sudo] password for learner: default via 10.77.10.1 dev eth0
10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.10 learner@rootvolt:~$ netlab shell router -- ip route10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.1
10.77.20.0/24 dev eth1 proto kernel scope link src 10.77.20.1 learner@rootvolt:~$ netlab shell web -- ip routedefault via 10.77.20.1 dev eth0
10.77.20.0/24 dev eth0 proto kernel scope link src 10.77.20.80 learner@rootvolt:~$ netlab shell laptop -- ip route get 10.77.10.1110.77.10.11 dev eth0 src 10.77.10.10 uid 1001
cache learner@rootvolt:~$ netlab shell laptop -- ip route get 10.77.20.8010.77.20.80 via 10.77.10.1 dev eth0 src 10.77.10.10 uid 1001
cache learner@rootvolt:~$ netlab shell router -- ip route get 10.77.20.8010.77.20.80 dev eth1 src 10.77.20.1 uid 1001
cache learner@rootvolt:~$ netlab shell router -- ip route get 192.0.2.1RTNETLINK answers: Network is unreachablelearner@rootvolt:~$ Steps (24)
- Type
netlab shell laptop -- ip route - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Output:
default via 10.77.10.1 dev eth0 10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.10 - Type
netlab shell router -- ip route - Press Enter
- Output:
10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.1 10.77.20.0/24 dev eth1 proto kernel scope link src 10.77.20.1 - Type
netlab shell web -- ip route - Press Enter
- Output:
default via 10.77.20.1 dev eth0 10.77.20.0/24 dev eth0 proto kernel scope link src 10.77.20.80 - Type
netlab shell laptop -- ip route get 10.77.10.11 - Press Enter
- Output:
10.77.10.11 dev eth0 src 10.77.10.10 uid 1001 cache - Type
netlab shell laptop -- ip route get 10.77.20.80 - Press Enter
- Output:
10.77.20.80 via 10.77.10.1 dev eth0 src 10.77.10.10 uid 1001 cache - Type
netlab shell router -- ip route get 10.77.20.80 - Press Enter
- Output:
10.77.20.80 dev eth1 src 10.77.20.1 uid 1001 cache - Type
netlab shell router -- ip route get 192.0.2.1 - Press Enter
- Output:
RTNETLINK answers: Network is unreachable
Check your answer
Router chooses eth1 for 10.77.20.80. Its connected site route matches. For 192.0.2.1, it prints RTNETLINK answers: Network is unreachable. Neither connected route matches, and there is no fallback.
Ask for one destination
Section titled “Ask for one destination”In Same subnet or gateway, ip route get showed via for a remote destination. You can now explain that result from the table. The command asks Linux which route it would use; it does not send a test packet or prove a reply can return.
Laptop’s lookup for phone shows dev eth0 without via. Its lookup for web includes the gateway. Both use the same interface on laptop, but the next link destination differs.
When several entries match, the longest prefix wins: the entry that fixes the most leading destination bits. Phone matches both the default, equivalent to /0, and 10.77.10.0/24. The /24 wins. Printing default first does not make it the first choice.
Mistakes to recognize
Section titled “Mistakes to recognize”“Only routers have routing tables.” Laptop and web each printed their own table. Every sender must choose how to send.
“Default is the most important route.” A connected /24 takes precedence for a matching destination. Default supplies the broadest fallback.
Good to know
Section titled “Good to know”The uid in a lookup describes the user making it; your number may differ. The cache line does not mean you sent a packet. Route selection and testing delivery are separate actions.
Try it yourself
Section titled “Try it yourself”Use this supplied paper table; do not install it. Choose a line for six destinations before checking.
| Line | Destination range | Action |
|---|---|---|
| A | default |
Via gateway A |
| B | 192.0.2.0/24 |
Direct |
| C | 192.0.2.128/25 |
Via gateway C |
| D | 192.0.2.192/26 |
Via gateway D |
| E | 198.51.100.0/24 |
Direct |
Choose for 192.0.2.10, 192.0.2.130, 192.0.2.200, 192.0.2.254, 198.51.100.8, and 203.0.113.8. Then repeat laptop’s two ip route get commands from the replay. Compare each choice with the longest-prefix rule.
Solution
The paper answers are B, C, D, D, E, A. Laptop chooses its connected /24 for phone and default for web. Count matching prefix bits before considering the fallback.
Leave for later
Section titled “Leave for later”Dynamic Routing Foundations explains how routers can learn entries from other routers. Here the lab supplies the entries.
- Read the matching range before the next hop.
- Expect tables on end machines too.
- Choose the longest matching prefix before default.
Next, The reply must return checks the other sender’s decision.