Using dnsmasq to setup your own dhcp/dns server on your local computer

Tue, 09/04/2012 - 17:04 -- jamie

At this point, you have learned that DHCP is a protocol that allows a server to assign an IP address to a client and DNS is a protocol that takes a domain name and returns an IP address.

Now, we are going to install a program called dnsmasq that provides both a DHCP server and DNS server that will run from your laptop computer.

By installing this server, you will be able to assign, via DHCP, IP addresses to your virtual servers and provide DNS lookup for them.

Begin by installing the dnsmasq package with:

sudo apt-get install dnsmasq

The dnsmasq program creates a directory called /etc/dnsmasq.d. You can create additional configuration for dnsmasq by creating a file in this directory. It doesn't matter what the name of the file is, so I suggest naming the file "local" to indicate that it's a local customization you have made.

You can begin editing the file by typing:

sudo nano /etc/dnsmasq.d/local

The content of the file should contain:

interface=virbr0
dhcp-range=10.11.13.2,10.11.13.100,1h

This configuration means: listen on the interface virbr0 for DHCP requests (first line) and assign IP addresses between 10.11.13.2 and 10.11.13.100 and force each network device to renew it's address once an hour.

Now, we just need to restart dnsmasq for the changes to take affect:

service dnsmasq restart