Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

DHCP and DNS Basics

The whole lesson is here to read. Create a free account to run it in a live lab.

Virtual machine lab5 min read4 commands

What you will do

When a computer joins a network it needs an address, and a way to turn a name like files.lab into one. Usually a single small program does both: DHCP hands out addresses and DNS answers names. Here that program is dnsmasq, and it is running on a server with nothing set up. You will ask it for an address and a name, and see it say no. You will not fix it: the configuration is the lab's own task.

Before you start

Note

Press Start the lab on the bar at the top of this lesson. This lab is a whole Ubuntu machine of your own, with a small network built inside it, so it takes a little longer to come up than a container. Each Run button below types its command into the machine's terminal, one after another. If one says the machine is still starting, wait a few seconds and press it again. To watch them, or to type your own, press Open terminal on the bar.

1. Meet the machines

Everything here is built inside your one Ubuntu machine: each computer is a separate network namespace with its own addresses. dnslab status lists them. The server has the address 10.0.10.1, and pc1 and pc2 have none: nothing is listed under them. It also says that dnsmasq is running.

Command
dnslab status

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

2. Ask for an address

A computer with no address asks the whole network for one, and a DHCP server answers. dnslab renew makes pc1 ask, and it waits about three seconds. The answer is that pc1 was given nothing: nobody replied, because dnsmasq has not been told to hand out any.

Command
sudo dnslab renew pc1

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

3. Ask for a name

dig asks a DNS server for a name, here the one on the server, 10.0.10.1. You ask from the server itself, because pc1 has no address to ask from. The header says status: REFUSED and ANSWER: 0: dnsmasq knows nothing about files.lab, and it has nowhere to look.

Command
sudo ip netns exec server dig +noall +comments @10.0.10.1 files.lab

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

4. Read the configuration

dnsmasq reads its settings from files in /etc/dnsmasq.d. The lab left one for you, lab.conf. It holds three lines of comments and nothing else, which is why it hands out nothing.

Command
cat /etc/dnsmasq.d/lab.conf

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Now do the lab

Tip

You have seen what is missing: addresses to give out and names to answer. Making the server do both is the task of this lab: open README.md in your home folder with cat README.md in the terminal. It says what to do and gives none of the answers.

For teachers

Tip

This lesson is a small example of a lesson worked in a lab: the steps and the Run buttons are the lesson, and the lab is each student's own copy. This lesson is worked in a VM lab: each student has an Ubuntu machine of their own with a server and two clients inside it, and a Run types into its terminal and shows what it printed. The lab itself has a check that restarts dnsmasq from the saved file and has the clients ask again. Copy it into your own module and change it, or build one from scratch with the Lab menu in the lesson builder.

About this lab and its source: DHCP and DNS lab: configure dnsmasq for a small network in your browser

Teaching a class? Set these lessons for your students with marking and a lab for every student.