Dnsmasq is a lightweight, easy-to-configure DNS forwarding server that can serve DNS requests for multiple networks from one interface. It’s particularly useful if you need a dynamic DNS service or simply want to improve DNS resolution on your network without the complexity of setting up BIND (Berkeley Internet Name Domain). This guide will walk you through installing Dnsmasq and configuring it as your primary DNS server.

Step 1: Installing Dnsmasq

The installation process varies depending on your operating system, but generally, you can install Dnsmasq using the package manager with root privileges. Here’s how to do it for popular distributions like Debian/Ubuntu or CentOS/RHEL:

For Debian-based systems (like Ubuntu):

sudo apt update sudo apt install dnsmasq

For Red Hat-based systems (like CentOS and RHEL):

sudo yum install epel-release # For CentOS, enable EPEL repository if not already enabled sudo yum install dnsmasq

Step 2: Configuring Dnsmasq

Dnsmasq doesn’t require extensive configuration to be useful as a DNS server. However, you will need to define how it should behave in your network. The main configuration file is usually located at /etc/dnsmasq.conf. Here are some basic settings you might want to adjust:

  1. Interface Configuration:
    • You can specify which network interfaces Dnsmasq should listen on by adding lines like this for each interface:interface=eth0
  2. DNS Servers:
    • By default, Dnsmasq comes with Google’s public DNS servers configured. If you want to use a different upstream DNS server, add the following line and replace with your preferred DNS server:server=
    • You can also specify multiple DNS servers for failover or load balancing if you prefer:server= server=
  3. DNS Forwarding:
    • Dnsmasq acts as a DNS proxy, forwarding queries to the defined upstream servers unless it has an answer in its local cache or hosts file:# Enable forward lookup listen-address=
  4. Caching:
    • To enable DNS caching, set a maximum size for the cache (e.g., 5MB):cache-size=512

Step 3: Starting Dnsmasq and Enabling It at Boot

After configuring Dnsmasq, start the service and ensure it starts automatically on boot:

sudo systemctl start dnsmasq sudo systemctl enable dnsmasq

For Red Hat-based systems, you might need to use systemctl instead of service:

sudo systemctl start dnsmasq sudo systemctl enable dnsmasq

Step 4: Testing Your Setup

To verify that Dnsmasq is working correctly, check its status and test DNS resolution by querying a public server:

sudo systemctl status dnsmasq dig @ example.com

If everything is set up correctly, you should see the DNS response from your configured upstream DNS server(s).


Dnsmasq provides an excellent way to quickly and easily deploy a DNS server on Linux without much hassle. Its lightweight design makes it ideal for small networks where performance and simplicity are key. With this guide, you should now be able to install and configure Dnsmasq as your primary or secondary DNS server, improving the DNS resolution capabilities of your network infrastructure.

Leave a Reply

Your email address will not be published. Required fields are marked *

Take your startup to the next level