Joining the café Wi-Fi
You sit down in a café and join its Wi-Fi. Within a second your phone has an address. Then you type a website's name and the page opens.
You never typed a number. Two small services did it for you.
One lends your phone an address. The other turns a name into an address.
By the end of this lesson
Note
I can explain how a device gets an address and finds a name.
Key words
| Word | What it means | Example |
|---|---|---|
| DHCP | the service that lends addresses to devices that ask | |
| Lease | an address lent for a set time | |
| Broadcast | a message sent to every device on the network | |
| Hardware address | the fixed number of a network card, also called a MAC address | 02:00:00:00:00:01 |
| DNS | the service that turns a name into an address | |
| Record | one fact a DNS server holds about a name |
The cells students fill in are left blank in this preview.
A new device has to ask
A device that has just joined has no address. It does not know where the DHCP server is either.
So it sends a broadcast to everybody on the network. The DHCP server hears it and offers an address.
It takes four messages, often called DORA: Discover, Offer, Request, Acknowledge.
Worked example: the four messages
| Message | Sent by | What it means |
|---|---|---|
| Discover | The phone | Is there a DHCP server here? |
| Offer | The server | You can have 192.168.5.101 |
| Request | The phone | Yes please, I will take it |
| Acknowledge | The server | It is yours for 12 hours |
The cells students fill in are left blank in this preview.
Meet the server and two clients
dnslab statusShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Make pc1 ask for an address
sudo dnslab renew pc1Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
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.
Nobody answered pc1
The status shows server with 10.0.10.1/24. Under pc1 and pc2 there is no address at all.
The renew waits about three seconds. Then it says pc1 was given nothing: no DHCPOFFER came back. The Discover went out, and no Offer came.
The last Run shows link/ether 02:00:00:00:00:01. That is how a server tells pc1 from pc2.
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.
DNS turns a name into an address
People remember names. Routers need numbers. A DNS server holds records that join the two.
Your phone asks its DNS server, "what is the address of this name?". The server answers from its records, or asks another server.
DHCP is what tells your phone which DNS server to ask.
Worked example: records in a café
| Record type | It answers | Example |
|---|---|---|
| A | Which address has this name? | till.cafe is 192.168.5.10 |
| AAAA | Which IPv6 address has this name? | A long number with colons |
| CNAME | Is this name another name? | menu.cafe is the same as web.cafe |
| MX | Which server takes the mail? | mail.cafe |
The cells students fill in are left blank in this preview.
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.
The server refused
The answer has status: REFUSED and ANSWER: 0. The server has no record for that name yet, and it cannot reach another server to ask.
Writing the records is part of the lab. After it, the same question has an answer.
A common mistake
Warning
Many people think DHCP and DNS are one service. They do two different jobs. DHCP lends addresses. DNS answers questions about names. One program can do both, as dnsmasq does in this lab, and they are still two jobs.
Going further: what a lease holds
When your lab works, read the server's real lease file: sudo cat /run/dnslab/dnsmasq.leases.
Each line has more fields than the assignment's. Match each field to what it means. Which one is the time the lease ends?