Labs / Routing / Routes by hand

Lab 2 of 4 ยท Routes by hand

Routing tables: how a router picks one line out of many

Read a routing table, and predict which line each packet follows.

Start this lab 6 steps

The idea

Every night the ski resort's backup swamps the old cable to the summit, and the lift operators' screens lag. Move the backup, and only the backup, onto the radio link by adding one line to a routing table.

A line names the next stop only
A line names the next stop only
The longest line that fits wins
The longest line that fits wins
Each probe stops one router further
Each probe stops one router further
The ping dies at the router with no line
The ping dies at the router with no line
Up by the cable, back by the radio
Up by the cable, back by the radio
An address takes the narrowest line that holds it
An address takes the narrowest line that holds it

Steps

  1. Read the base router's table

    A Router joins networks. Each time a packet comes in, the router must choose where to send it next, and the list it reads is its routing table, one line for each block of addresses it knows about.

    baseRouter stands at the bottom of the mountain with three network cards, each named after its network: lodge, where ticketDesk sits; cableLink, the old cable up to summitRouter; and radioLink, a faster radio link to radioRelay, which stands at the summit and reaches both the summit network and the outside world.

    Run ip route on baseRouter and read its routing table. The lines come in two kinds, and the word via tells them apart.

    baseRouter:~# ip route
  2. Ask which line wins

    The backup store at 10.0.3.50 fits two lines in that table: 10.0.3.0/24, and default, which fits every address there is. A router sends each packet one way only, so it needs a rule for choosing.

    ip route get shows the choice without sending anything. Ask baseRouter about the backup store, then about the weather feed at 10.0.9.40, which is on a network it has no line for.

    baseRouter:~# ip route get 10.0.3.50
    baseRouter:~# ip route get 10.0.9.40
  3. Move one machine to the radio

    Now fix the backup. Changing the 10.0.3.0/24 line would move all of summit, liftControl included, and the lift operators want to stay on the cable. You need a line narrower than /24.

    The narrowest line of all is /32, which pins down all 32 bits of an address, so it fits one machine. It's called a host route. 10.0.3.50/32 via 10.0.4.3 sends that one address to radioRelay.

    Trace the path from ticketDesk first. Traceroute lists each router on the way, and line 2 is the router after baseRouter. Add the line on baseRouter, then trace both summit machines.

    ticketDesk:~# traceroute -n -q 1 -w 2 10.0.3.50
    baseRouter:~# ip route add 10.0.3.50/32 via 10.0.4.3
    ticketDesk:~# traceroute -n -q 1 -w 2 10.0.3.50
    ticketDesk:~# traceroute -n -q 1 -w 2 10.0.3.20
  4. Send the weather by cable

    A storm is coming, and the radio link drops out in storms. The resort wants the weather feed at 10.0.9.40 on the cable from now on.

    That feed has no line of its own on baseRouter, so it goes by default. Add a line for its network, 10.0.9.0/24 via 10.0.2.3, which is narrower than default, so packets for the feed go to summitRouter. Then ping the feed from ticketDesk.

    Keep in mind who summitRouter is: it was set up to serve the summit and the way back to lodge, and nothing more.

    baseRouter:~# ip route add 10.0.9.0/24 via 10.0.2.3
    ticketDesk:~# ping -c 1 -W 2 10.0.9.40
    summitRouter:~# ip route
  5. Give the next router a line

    summitRouter needs its own line for 10.0.9.0/24. Work out the next stop from what you know: the feed is beyond radioRelay, and radioRelay has a card on the summit network with the address 10.0.3.3, which summitRouter can reach directly.

    Add the line on summitRouter. Then trace the path from ticketDesk and open the feed with curl, which fetches a web page and shows it as text. This trace sends three probes to each stop, because a router allows itself only a few of these notes each second, and a lost one prints as *.

    summitRouter:~# ip route add 10.0.9.0/24 via 10.0.3.3
    ticketDesk:~# traceroute -n -w 1 10.0.9.40
    ticketDesk:~# curl -s http://10.0.9.40/
  6. Read a table you haven't seen

    One short routine reads any routing table:

    1. Find every line whose block holds the address.
    2. Take the line with the biggest number after the slash.
    3. Read its via: that's the next stop. With no via, the machine is on that card's own network.

    The lab has added one more line to baseRouter, and these are the lines that matter:

    default via 10.0.4.3 dev radioLink
    10.0.3.0/24 via 10.0.2.3 dev cableLink
    10.0.3.0/25 via 10.0.4.3 dev radioLink
    10.0.3.50 via 10.0.4.3 dev radioLink
    

    /25 pins down one more bit than /24, so it covers half the block: 10.0.3.0/25 runs from .0 to .127, and 10.0.3.128/25 would be the other half. Work out the next stop for 10.0.3.200 before you ask baseRouter, then ask about 10.0.3.20 as well.

    baseRouter:~# ip route get 10.0.3.200
    baseRouter:~# ip route get 10.0.3.20

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab