Linux for Network Engineers: How to set up a DNS server with Dnsmasq

By December 4, 2019Linux

In two previous blog posts we talked about Dnsmasq’s DNS caching and read-only TFTP server set up. Continuing with a third dnsmasq-related post, we’ll talk about how to set up a DNS server in your network.

Set Up

Literally, all you have to do is install dnsmasq on a host:

After the installation the dnsmasq process starts running and you have a DNS server in your network! Of course, it’s advisable to set a static IP on your new DNS server in order to be able to use it from other hosts. My DNS server runs on

To demonstrate how this improves look up time I use dig below to time the lookup time for

By using the default DNS servers on this machine,, it takes around 15 mseconds to resolve No matter how many times I repeat this command, the resolution time is about the same.

The first time I use my new DNS server ( it also takes 15 mseconds. The first time you resolve a new host, dnsmasq has also to do a look up using another DNS server since it doesn’t have the lookup information stored.

Moving forward, for all subsequent look ups of the lookup time is 0 mseconds. That’s because now dnsmasq has cached the lookup information, and returns it itself when it receives a query:

You just saved 15 mseconds look up time!


Even if you don’t touch at all the dnsmasq configurations you will have a working DNS server. However, there are quite a few options you can use to fine tune your DNS server. For example, you can enable or disable DNSSEC, filter out useless Windows-originated DNS requests, or require to forward domain names only.

The dnsmasq team has done a good job documenting each option in the actual configuration file /etc/dnsmasq.conf. So, if you open that file, you should see towards the top all available options with extensive comments. I could copy and paste those options here, but in case they change with a newer version it would make this blog post inaccurate. 

In the following blog post we’ll talk about how to set up a DHCP server which is the last functionality of dnsmasq we haven’t covered.