Skip to content

Reading routes and default routes

Module
Reaching Another Device
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS, netlab 1.0, GNU Bash 5.2.21
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.

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.

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 
laptop · Internet
machine
eth0 · Internet
Next hop · Internetvia 10.77.10.1
Connected range · Internet10.77.10.0/24
Preferred source · Internetsrc 10.77.10.10

Reading the output

Pick a step to match a marked part of the output to the picture.

Step-by-step reading of a captured output · Output of netlab shell laptop -- ip route on laptop, on Ubuntu 24.04.5 LTS, netlab 1.0, tcpdump 4.99.4. The values are the capture's. Read laptop's two captured route lines, separating the matching range, next hop, interface and source setting.
Steps (7)
  1. Fallback. Fallback: default. Internet layer. Shown on laptop's eth0 as: laptop. The fallback matches when no longer prefix does.
  2. 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.
  3. Interface. Interface: dev eth0. Internet layer. Shown on laptop's eth0 as: eth0. Send through this interface.
  4. 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.
  5. Entry source. Entry source: proto kernel. Internet layer. Shown on laptop's eth0 as: laptop. The kernel installed this connected route.
  6. Local link. Local link: scope link. Internet layer. Shown on laptop's eth0 as: eth0. These destinations are reachable on the attached link.
  7. 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.

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?

Read three routing tables
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:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Read laptop, router and web tables, then ask laptop and router for specific destination choices.
Steps (24)
  1. Type netlab shell laptop -- ip route
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. 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
  7. Type netlab shell router -- ip route
  8. Press Enter
  9. 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
  10. Type netlab shell web -- ip route
  11. Press Enter
  12. 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
  13. Type netlab shell laptop -- ip route get 10.77.10.11
  14. Press Enter
  15. Output: 10.77.10.11 dev eth0 src 10.77.10.10 uid 1001 cache
  16. Type netlab shell laptop -- ip route get 10.77.20.80
  17. Press Enter
  18. Output: 10.77.20.80 via 10.77.10.1 dev eth0 src 10.77.10.10 uid 1001 cache
  19. Type netlab shell router -- ip route get 10.77.20.80
  20. Press Enter
  21. Output: 10.77.20.80 dev eth1 src 10.77.20.1 uid 1001 cache
  22. Type netlab shell router -- ip route get 192.0.2.1
  23. Press Enter
  24. 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.

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.

“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.

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.

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.

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.