Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Following a packet across routers

After this lesson: I can follow a packet across routers.

50 min lesson5 commandsStatic routing lab: build routes on a small network in your browser

A parcel with only an address

A parcel leaves a warehouse with an address on it and nothing else. No driver knows the whole way.

Each depot only knows which van to put it on next. Step by step, it arrives.

Packets cross the internet in the same way. Each router only decides the next hop.

By the end of this lesson

Note

I can follow a packet across routers.

Key words

WordWhat it meansExample
Routera device that passes packets between networks
Routing tablea router's list of networks and where to send each
Next hopthe next router a packet is handed to
Default routethe line used when no other line matchesdefault via 10.0.1.1
Directly connecteda network the router has a cable on
Hopone step from one device to the next

The cells students fill in are left blank in this preview.

A routing table lists networks

Every device with an address has a routing table. Each line names a network and says where to send packets for it.

A host's table is short. It knows its own network, and it has a default route: send everything else to the router.

A router's table is longer. It knows every network it has a cable on.

Read h1's routing table

Command
sudo ip netns exec h1 ip route

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Read r1's routing table

Command
sudo ip netns exec r1 ip route

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the two tables say

h1 has two lines. default via 10.0.1.1 sends everything to r1. 10.0.1.0/24 dev to-r1 is h1's own network.

r1 also has two lines, 10.0.1.0/24 and 10.0.12.0/24. Both are directly connected. r1 has no line for h2's network, 10.0.3.0/24, and no default route.

The most exact line wins

A packet can match more than one line. The default route matches everything, for example.

The router picks the line with the longest prefix, the biggest number after the slash. That line is the most exact.

If nothing matches and there is no default route, the router drops the packet. It sends back a message: the network is unreachable.

Worked example: a school router's choice

Packet forLines that matchWinnerNext hop
172.16.4.9172.16.0.0/16, 172.16.4.0/24, default172.16.4.0/24172.16.0.2
172.16.9.9172.16.0.0/16, default172.16.0.0/16172.16.0.1
8.8.8.8defaultdefault192.0.2.1

The cells students fill in are left blank in this preview.

Ping h2 from h1

Command
sudo ip netns exec h1 ping -c 2 -W 1 10.0.3.2

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Trace the packet's hops

Command
sudo ip netns exec h1 traceroute -n -m 4 -w 1 10.0.3.2

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Ask r1 where it would send it

Command
sudo ip netns exec r1 ip route get 10.0.3.2

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Where the packet stops

The ping prints From 10.0.1.1 ... Destination Net Unreachable twice. The message comes from r1, not from h2.

The trace shows one hop, 10.0.1.1, marked !N: network unreachable.

r1 answers RTNETLINK answers: Network is unreachable. Its table has no line for 10.0.3.0/24. Fixing that is the lab.

A common mistake

Warning

Many people think a router knows the whole path to the far end. It only knows the next hop. Every router on the way must have its own line for the far network, and the far side needs a line back for the reply.

Going further: why the reply matters

Once your lab works, run sudo ip netns exec r2 ip route again.

Which line lets r2 send the reply back to h1? Write that line in your assignment's format, add it to a table and test it with your next_hop.

About this lab and its source: Static routing lab: build routes on a small network in your browser

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.