Labs / IP Addressing & NAT / IPv6

Lab 2 of 3 · IPv6

IPv6 addressing: read, shorten and split any address

Read IPv6 addresses at a glance, split a block and see who hands them out.

Start this lab 6 steps

The idea

Hillside School has its own block of IPv6 addresses from its internet provider. Learn to read any address, tell how far it reaches, split the block into networks and see who gives each machine its address.

One gap, never two
One gap, never two
An fd address stops at the edge
An fd address stops at the edge
Three owners, one address
Three owners, one address
The temporary address goes out
The temporary address goes out
Who gives a machine what
Who gives a machine what
A loan, and a record of it
A loan, and a record of it

Steps

  1. Spell one address three ways

    An IPv6 address is 128 bits long. Written in full, it takes 8 groups of 4 hexadecimal digits, which count from 0 to 9 and then from a to f. That gives 2001:0db8:0099:0002:0000:0000:0000:0050, which nobody wants to read out over the phone.

    Two rules shorten it. First, drop the zeros at the front of any group, so 0db8 becomes db8 and 0000 becomes 0. Second, replace one run of all-zero groups with ::.

    The machine knows there must be 8 groups in all, so it can work out how many zero groups :: stands for.

    Together, they give 2001:db8:99:2::50, the address of weatherSite, a website outside Hillside School.

    You're at teacherDesk, in a classroom. Ping the site with the long spelling, then the short one. Then try a spelling with :: in it twice.

    teacherDesk:~# ping -c 1 -w 1 2001:0db8:0099:0002:0000:0000:0000:0050
    teacherDesk:~# ping -c 1 -w 1 2001:db8:99:2::50
    teacherDesk:~# ping -c 1 -w 1 2001:db8::2::50
  2. Tell how far an address reaches

    The first digits of an address say how far it reaches, which saves a lookup when you read a log.

    • 2 or 3: global. It works across the internet, and the block comes from a provider. Hillside's 2001:db8 block is set aside for examples, so it stands in for a real one here.
    • fd: unique local. It's private to one organization.
    • fe80: link-local. It works on one link only: the stretch of network with no Router in the way.
    • ff: Multicast. It names a group of machines, not one.
    • ::1: loopback. It's this machine talking to itself.

    Unique local addresses do the job of IPv4's private addresses. gradesServer, in the staff room, holds pupils' grades and has no business on the internet. So its only address that crosses a router is fd3f:8a21:77c4:2::80.

    List teacherDesk's addresses. Then ping gradesServer from teacherDesk, one router away, and from weatherSite, outside the school.

    teacherDesk:~# ip -6 addr
    teacherDesk:~# ping -c 1 -w 1 fd3f:8a21:77c4:2::80
    weatherSite:~# ping -c 1 -w 1 fd3f:8a21:77c4:2::80
  3. Split the provider's block

    Hillside's provider gave it 2001:db8:70::/48. The number after the slash says how many bits are fixed, and those fixed bits are the prefix.

    Each group holds 16, so /48 fixes the first three groups: 2001:db8:70. The school chooses everything after them.

    Networks are normally /64, so the last four groups belong to the machines. Machines that build their own addresses expect exactly 64 bits to fill. That leaves one group in the middle, the fourth, for the school to number its networks: the classrooms are 2001:db8:70:1::/64, and the staff room is 2001:db8:70:2::/64.

    If you've done IPv4 subnetting, notice what's missing. A /64 has room for far more machines than any network will hold, so you never size a network to fit. You number your rooms.

    The provider doesn't need to know any of this. carrierRouter keeps one route for the whole block, and a short prefix fixes few bits, so one route covers every address that shares them.

    Read carrierRouter's routes. Then ask which way it would send an address in a network the school hasn't built yet, and one a single digit outside the block.

    carrierRouter:~# ip -6 route
    carrierRouter:~# ip -6 route get 2001:db8:70:abcd::1
    carrierRouter:~# ip -6 route get 2001:db8:71:2::80
  4. See what a website sees

    A machine can fill the last 64 bits in several ways. teacherDesk uses the oldest one: its digits come from the MAC address of its network card, the number fixed into the card itself. Its MAC is 02:42:0a:00:01:0a, and its digits are 42:aff:fe00:10a: the same digits, with ff:fe pushed into the middle and one bit changed.

    The MAC doesn't change from network to network, so those digits follow a laptop from home to school to a café, and any website can connect the visits.

    Temporary addresses fix that. The machine makes up a second address from random digits, uses it for the connections it opens, and swaps it for a new one after a day or so.

    Its stable address stays in place, so that other machines can still reach it. Phones and laptops usually have this turned on.

    pupilTablet has temporary addresses, and teacherDesk doesn't. List the tablet's addresses, then fetch the weather page from each machine. The page prints the sender it saw.

    pupilTablet:~# ip -6 addr show dev classrooms
    pupilTablet:~# curl -sS -m 3 http://[2001:db8:99:2::50]/
    teacherDesk:~# curl -sS -m 3 http://[2001:db8:99:2::50]/
  5. Read what the router orders

    The classroom machines built their own addresses from what the router told them. That's SLAAC, and it keeps no record of who holds what.

    Some networks need that record, so they want addresses from a DHCPv6 server, which lends them out and writes them down, as DHCP does on IPv4. The loan is called a lease.

    The router decides which method a network uses, and says so in its router advertisement, the message that it sends to every machine on the link. Three flags, each on or off, carry the orders:

    • A sits on each prefix, and means "build your own address from this".
    • M, for managed, means "get your address from DHCPv6".
    • O, for other, means "get other settings, such as DNS servers, from DHCPv6".

    Ask for the advertisement on teacherDesk, then on bursarPc in the staff room. Then read bursarPc's routes.

    teacherDesk:~# rdisc6 -1 classrooms
    bursarPc:~# rdisc6 -1 staffRoom
    bursarPc:~# ip -6 route
  6. Ask a server for an address

    The advertisement told bursarPc to ask, so ask.

    A client doesn't need to know where the server is. It sends its request from its link-local address to ff02::1:2, the multicast group of DHCPv6 servers on this link. That's why the card needed a link-local address first.

    Here the server is dnsmasq, a small program running on schoolRouter, with the pool 2001:db8:70:2::100 to 2001:db8:70:2::1ff to give out. The client on bursarPc is udhcpc6. It knows a card only by its first name, eth0, the name Linux gave it.

    Run the client. Then read the address that bursarPc got, and the list that the server keeps on schoolRouter, in /tmp/leases.

    bursarPc:~# udhcpc6 -i eth0 -q -n -s /etc/udhcpc6.script
    bursarPc:~# ip -6 addr show dev staffRoom
    schoolRouter:~# cat /tmp/leases

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