Labs / IP Addressing & NAT / Addresses and subnets

Lab 1 of 5 · Addresses and subnets

Public and private IP addresses: how two homes use one address

Open one address in two homes, then find the address a website sees.

Start this lab 4 steps

The idea

Noah texts Mia the address of his holiday photos, but something else answers when Mia opens it at home. Follow that one address into both houses and find out why nothing is broken.

The request stays in the house
The request stays in the house
Two cards, two reaches
Two cards, two reaches
One address in two houses
One address in two houses
The provider drops private, carries public
The provider drops private, carries public

Steps

  1. Open Noah's address

    Every machine on a network has an IP address. The common kind, IPv4 (Internet Protocol version 4), is four numbers from 0 to 255, with dots between them. One machine reaches another by sending a request to that address.

    Noah's text says his photos are at 192.168.1.20. Type the command into the terminal on Mia's laptop, the window where you type commands to a machine. curl asks an address for its web page and shows the page as text.

    miaLaptop:~# curl -s http://192.168.1.20/
  2. Try the same address at Noah's house

    Noah's address comes from an old problem. Four numbers from 0 to 255 give about 4.3 billion addresses, and by the early 1990s engineers could see that the internet would run out. More and more companies wanted an address for every computer.

    One answer was to set aside a few blocks of addresses that anyone may reuse. That rule now stands as RFC 1918, one of the numbered documents that record how the internet works.

    A machine inside a home or an office usually takes one of those. Its Router, the machine that joins that network to the internet, deals with the outside world.

    In the lab, the machine with Noah's photos sits behind noahRouter and has no terminal of its own. So test Noah's side from that router, where a command stays inside his house. Run the same curl command there.

    Then try 127.0.0.1, an address with an even smaller reach, on miaPrinter. Most printers have no terminal, but the lab gives this one a terminal. Last, list the addresses on miaLaptop.

    noahRouter:~# curl -s http://192.168.1.20/
    miaPrinter:~# curl -s http://127.0.0.1/
    miaLaptop:~# ip -br addr
  3. See which address a website sees

    Mia's laptop calls itself 192.168.1.10, and millions of other homes use that address too. A website can't reply to an address that millions of machines hold, so something has to change on the way out of the house.

    198.51.100.80 is a website that shows each visitor the address it saw. Fetch it from Mia's laptop. Then list the addresses on miaRouter, and compare the two.

    Last, try Noah's router directly. 203.0.113.20 is the address of noahRouter on the internet, so send curl there from Mia's laptop.

    miaLaptop:~# curl -s http://198.51.100.80/
    miaRouter:~# ip -br addr
    miaLaptop:~# curl -sS -m 3 http://203.0.113.20/
  4. Ask the provider about Noah's address

    Noah could send 192.168.1.20 to more people, but that won't help. provider in this lab is a router that belongs to the company connecting Mia and Noah. Read its blackhole list, the blocks of addresses it has a special rule for.

    One private block is the one people get wrong: it starts at 172.16, but some addresses that start with 172 are public. Check where it ends with ipcalc, a calculator for addresses.

    Noah's fix is one more rule on his router: pass web requests from the street to the machine with the photos. That rule is port forwarding, which has a lab of its own, so the lab adds it for you here. Then try Noah's public address again.

    provider:~# ip route show type blackhole
    provider:~# ipcalc -n -b 172.16.0.0/12
    miaLaptop:~# curl -s http://203.0.113.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