Your phone joins the Wi-Fi
You walk into a café and join its Wi-Fi. Nobody types an address into your phone, yet it works in seconds.
Then you type a website's name, not a number, and the page opens.
Two small jobs happened without you seeing them. This lesson shows both.
By the end of this lesson
Note
I can give devices addresses and names.
Key words
| Word | What it means | Example |
|---|---|---|
| DHCP | the service that lends addresses to devices as they join | |
| Lease | an address lent to one device for a set time | |
| Pool | the range of addresses a DHCP server may lend | .100 to .150 |
| Hardware address | the fixed number built into a network card, also called a MAC address | 02:00:00:00:00:01 |
| Reservation | a rule that always lends one device the same address | |
| DNS | the service that turns a name into an address |
The cells students fill in are left blank in this preview.
A DHCP server lends addresses
A new device has no address, so it cannot ask anybody directly. It shouts to the whole network instead: is there a DHCP server here?
The server offers an address from its pool. The device accepts it, and the address becomes a lease. Before the lease runs out, the device asks to keep it. A device that leaves just stops asking, and the address goes back in the pool.
Worked example: four short messages
| Message | Sent by | What it means |
|---|---|---|
| DISCOVER | The new device, to everyone | Is there a DHCP server here? |
| OFFER | The server | You can have 10.0.10.100 |
| REQUEST | The device | Yes please, I will take it |
| ACK | The server | It is yours for 12 hours |
The cells students fill in are left blank in this preview.
Meet the server and two computers
dnslab statusShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ask for an address for pc1
sudo dnslab renew pc1Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Why pc1 gets nothing
The status shows the server on 10.0.10.1/24, and two computers, pc1 and pc2, with no address at all. The last line says dnsmasq: running.
The renew prints pc1 was given nothing: no DHCPOFFER came back. pc1 shouted DISCOVER, but no OFFER came. The server program is running, yet nobody has told it what it may lend.
A reservation keeps one address
A phone can have a different address every day and nobody minds. A printer is different: every laptop has to find it in the same place.
Every network card has a hardware address built in. A reservation tells the server: when this hardware address asks, always lend this one address. Pick reserved addresses outside the pool, so the server never lends them to somebody else.
Read pc1's hardware address
sudo ip netns exec pc1 ip -o link show eth0Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Read the server's settings file
cat /etc/dnsmasq.d/lab.confShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
An empty file lends nothing
The long line ends with link/ether 02:00:00:00:00:01. That is pc1's hardware address, the number a reservation would use.
The settings file holds three lines starting with #. Those are notes for people, and the server ignores them. So there is no pool, no reservation and no names. Filling this file in is your job in the lab.
A common mistake
Warning
Many people think DHCP and DNS are one service. DHCP lends an address and tells the device which DNS server to use. DNS answers names. One machine can run both, as in this lab, but they are two separate jobs.
DNS turns a name into an address
People remember names. Computers need numbers. A DNS server keeps a list of records, each one a name and its address.
When you type a name, your device asks the DNS server it was told about. The server answers with the address, and the device connects to that.
Ask the server for a name
sudo ip netns exec server dig +noall +comments @10.0.10.1 files.labShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Read where pc1 sends its questions
cat /etc/netns/pc1/resolv.confShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
No record, no answer
The answer says status: REFUSED and ANSWER: 0. The server has no record for files.lab, and it has nobody else it can ask.
pc1's file of DNS servers is empty, so the second Run prints nothing. pc1 does not even know where to ask. DHCP will tell it once the server has something to lend.
Going further: your own leases
Once your lab works, run sudo dnslab renew pc1 and then cat /run/dnslab/dnsmasq.leases. Each line is one lease.
Copy the text into your assignment and call ip_for_mac with pc1's hardware address. Does it give the address the status shows? Which part of the line is the time the lease ends?