Labs / IP Addressing & NAT / Addresses and subnets

Lab 5 of 5 · Addresses and subnets

Supernetting: turn a list of routes into one line

Join neighboring blocks into one route, and stop the loop a summary can cause.

Start this lab 7 steps

The idea

Noor's main Router lists every branch library on its own line, though they all go the same way. Swap them for one line, then find out what that one line gets wrong.

No line, so the router answers itself
No line, so the router answers itself
Neighbors can sit on two sides of a wall
Neighbors can sit on two sides of a wall
The summary knows the way, not the branch
The summary knows the way, not the branch
Each list points at the other router
Each list points at the other router
The blackhole sits above the default route
The blackhole sits above the default route
Only one list has the exception
Only one list has the exception
Park reaches Mill through the main library
Park reaches Mill through the main library

Steps

  1. Read the main library's list

    Noor looks after the network for a city's libraries. Every branch reads the same catalogue, a server at the main library that lists each book, so branch traffic goes through centralRouter, the Router there.

    A router decides where each packet goes from its list of routes. A packet is a small piece of data with an address on it. Each route names a block of IP addresses and the next stop for that block, and each branch has a block of its own, called a Subnet and prefix length.

    Type ip route in centralRouter's terminal, the window where you type commands to a machine. Then find out what the router does with an address that's on none of its lines. Nobody has 10.20.7.50, so send it a ping from catalogue.

    centralRouter:~# ip route
    catalogue:~# ping -c 1 -W 2 10.20.7.50
  2. Join blocks into one

    Three lines that point the same way could be one line, if one block held all three branches. Joining neighboring blocks into one bigger block is called supernetting, and the bigger block is a supernet. A route that covers a supernet is a summary route, because it stands for all the routes inside it.

    Noor's list is small, but this problem was once the internet's. By 1991 the lists in the internet's biggest routers were growing too fast, and engineers expected the problem to turn critical between 1993 and 1995.

    A 1992 proposal called "Supernetting" grew into Classless Inter-Domain Routing (CIDR) in 1993: routing across networks with no fixed block sizes. A provider with thousands of customers could now show the rest of the internet one block for all of them.

    Supernetting uses the same slash number as subnetting, moved the other way. A bigger number cuts a block into smaller ones. A smaller number joins blocks, and each step doubles the block: a /23 is two /24s, and a /22 is four.

    Supernet and subnet say how two blocks relate, not how big one is. 10.20.4.0/22 is a supernet of Park's /24, and a subnet of 10.20.0.0/16, a block of 65,536 addresses.

    Not every pair of neighbors can join. Test Harbor and Mill with ipcalc, a calculator for addresses: ask for the /23 around each one, then for the /22 around Park. It prints each block's first address as NETWORK and its last as BROADCAST.

    centralRouter:~# ipcalc -n -b 10.20.5.0/23
    centralRouter:~# ipcalc -n -b 10.20.6.0/23
    centralRouter:~# ipcalc -n -b 10.20.4.0/22
  3. Swap three routes for one

    Changing routes on a working router has a safe order: add the new line first, delete the old lines after. A list that's too long for a moment keeps traffic moving. A list that's too short for a moment drops traffic.

    While both are in the list, nothing changes. A packet for Mill matches 10.20.6.0/24 and 10.20.4.0/22, and the router always takes the line that matches the most bits of the address. That rule is called longest prefix match. A prefix is the first part of an address, the bits a block keeps the same.

    A /24 keeps 24 bits the same, and a /22 only 22, so the biggest slash number wins.

    So the old lines keep working until the moment they're gone.

    Add the summary to centralRouter. The lab then deletes the three branch lines. Read what's left, and ping millDesk, the machine at the Mill branch, from catalogue.

    centralRouter:~# ip -echo route add 10.20.4.0/22 via 10.20.2.3
    centralRouter:~# ip route
    catalogue:~# ping -c 1 -W 2 10.20.6.10
  4. Ping the empty block again

    Send the same ping as in the first step, to 10.20.7.50. Nobody has that address, and no branch uses .7. Back then centralRouter had no line for it and sent an error straight back.

    Now 10.20.4.0/22 covers it, so centralRouter hands the packet to northRouter. What happens from there depends on northRouter's own list, so read that too.

    This time the lab records the cable between the two routers while the ping runs. tcpdump, a program that prints the packets crossing a network card, shows you each crossing. -v adds detail about each packet, and -t leaves out the time of day.

    If the output looks strange, nothing has gone wrong on your side. The result walks through it.

    catalogue:~# ping -c 1 -W 2 10.20.7.50
    northRouter:~# ip route
  5. Drop what the summary can't deliver

    The loop has one cause: .7 matches the summary on one router and the default route on the other. What's missing is a line that catches .7 and stops it.

    A blackhole route is that line. It names a block and has no next router and no card, so a packet that matches it is dropped on the spot.

    That sounds like a bad thing to own, but longest prefix match keeps it in its place: a blackhole only gets packets that match no line with a bigger slash number. Give it the size of the summary, and every real branch still beats it, while the empty addresses reach it before they can reach the default route.

    Decide which router needs it, then add it. Run the ping with the cable recording again, and ping millDesk to check that a real branch still answers.

    northRouter:~# ip -echo route add blackhole 10.20.4.0/22
    catalogue:~# ping -c 1 -W 2 10.20.7.50
    catalogue:~# ping -c 1 -W 2 10.20.6.10
  6. Move Mill to the other router

    Mill's building is being rewired, and its cable moves from northRouter to southRouter, the new router with its own cable to the main library. The lab moves it first. Mill's block still sits inside .4 to .7, but it's no longer behind northRouter.

    Noor doesn't have to tear up the summary. Longest prefix match lets a block have exceptions: one line for Mill, 10.20.6.0/24 via 10.20.3.3, beats 10.20.4.0/22, and the summary goes on standing for everything else.

    Add that line to centralRouter. Then test Mill from two places: catalogue at the main library, and parkDesk at the Park branch.

    centralRouter:~# ip -echo route add 10.20.6.0/24 via 10.20.3.3
    catalogue:~# ping -c 1 -W 2 10.20.6.10
    parkDesk:~# ping -c 1 -W 2 10.20.6.10
  7. Give northRouter the exception

    Two lines on northRouter could take Park's packets for Mill: the blackhole and the default route. The blackhole wins, because /22 matches 22 bits, and a default route matches every address and checks no bits at all.

    Neither line is wrong on its own. northRouter needs a line for Mill that's longer than the blackhole.

    List the lines that cover Mill's address first. Then add 10.20.6.0/24 with the right next router, and ping Mill from parkDesk.

    northRouter:~# ip route show match 10.20.6.10
    northRouter:~# ip -echo route add 10.20.6.0/24 via 10.20.2.2
    parkDesk:~# ping -c 1 -W 2 10.20.6.10

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