Labs / Routing / Routes by hand

Lab 1 of 4 · Routes by hand

Default gateways: why a machine reaches its neighbor and nothing else

Give a machine its way out of the network, and the reply its way back.

Start this lab 4 steps

The idea

The hotel's new front-desk machine reaches the key-card printer beside it, but the booking system in the back office never answers. Find what the machine is missing, and bring tonight's rooms up on its screen.

The far ping never leaves frontDesk
The far ping never leaves frontDesk
A gateway is the address on your side
A gateway is the address on your side
Each trip uses its sender's routes
Each trip uses its sender's routes
The hardware address names the next stop
The hardware address names the next stop

Steps

  1. Ping beyond the lobby

    This hotel has two networks. A network here means a group of machines that reach each other directly, through one Switch: lobby holds the addresses that start 10.0.1, and backOffice holds those that start 10.0.2.

    frontDesk (10.0.1.10) and keyPrinter (10.0.1.30) sit on lobby, and bookingSystem (10.0.2.40) sits on backOffice. Between them stands hotelRouter, a Router, the machine that carries traffic from one network to another, with a network card on each.

    Nadia set up frontDesk this morning. She gave it an address and a mask, the setting that says which addresses are on its own network, and she left the rest blank.

    Run both pings from frontDesk. ping sends a test packet and waits for a reply: -c 1 sends one packet, and -W 2 waits 2 seconds. The lab records everything frontDesk sends toward the booking system.

    frontDesk:~# ping -c 1 -W 2 10.0.1.30
    frontDesk:~# ping -c 1 -W 2 10.0.2.40
  2. Name the way out

    Run ip route on frontDesk to print its routes, the list of where it can send. You will see how little it knows.

    What's missing is a default gateway, the router a machine hands every packet that isn't for its own network. You might expect a machine to carry a map of the internet instead. It can't, because routers at the center of the internet hold about a million routes, and those change all day.

    So the internet's designers split the work. Routers hold the maps, and an ordinary machine holds two facts: which addresses are on my own network, and which router takes the rest. That's why a phone reaches any website in the world with a list of two lines.

    The word goes back to the start of the internet. A 1974 paper by Vint Cerf and Bob Kahn, the one that set out TCP, called the box between two networks a gateway. Standards later moved to the word router, but the settings screen on your laptop still says Default Gateway, and default keeps its everyday meaning: what to do when nothing else applies.

    hotelRouter has two addresses, one for each card: 10.0.1.2 on lobby and 10.0.2.2 on backOffice. Try the one beside the booking system first, and then the other. A refused command changes nothing, so this is safe.

    frontDesk:~# ip route
    frontDesk:~# ip route add default via 10.0.2.2
    frontDesk:~# ip route add default via 10.0.1.2
    frontDesk:~# ip route
  3. Ping the booking system again

    frontDesk has a way out now. For 10.0.2.40 it finds no line for that network, so it takes the default line, finds the hardware address of 10.0.1.2, and hands the packet to hotelRouter. hotelRouter has a card on backOffice, so it delivers the packet there.

    Before you run it, think about the whole trip: a ping needs a reply, and the settings on bookingSystem were typed in by hand too.

    Run the same ping. This time the lab records what reaches bookingSystem. Then look at the machine on the other end: run ip route on bookingSystem, and ask it how it would reach frontDesk with ip route get, which shows the way a machine would send to an address without sending anything.

    frontDesk:~# ping -c 1 -W 2 10.0.2.40
    bookingSystem:~# ip route
    bookingSystem:~# ip route get 10.0.1.10
  4. Give the reply a way back

    You know the fault now, so write the fix yourself. bookingSystem needs its own default gateway, and the rule from before still holds: it must be an address on bookingSystem's own network. You tried that address earlier, from the side where it was refused.

    Then run three commands on frontDesk. Traceroute lists each router on the way to an address: -n prints addresses without looking up names, -q 1 sends one probe per stop, and -w 2 waits up to 2 seconds for each.

    curl -s fetches the booking page and shows it as text, and ip neigh lists the hardware addresses a machine has found.

    bookingSystem:~# ip route add default via 10.0.2.2
    frontDesk:~# traceroute -n -q 1 -w 2 10.0.2.40
    frontDesk:~# curl -s http://10.0.2.40/
    frontDesk:~# ip neigh

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