Skip to content

Installing DNSMASQ on Debian and Ubuntu

Tutorials & Guides  ·   ·   ·  Updated on  ·  2 min Reading time

Installing DNSMASQ on Debian and Ubuntu

What is a DNS server?
DNS servers are responsible for resolving domain names into IP addresses. That means when I type, for example, www.prepaid-host.com into my browser, my PC connects via the configured DNS server, i.e. it sends a request asking which IP address is stored for the domain name. With DNSMASQ you can host and configure your own DNS server efficiently. You can use it to manipulate specific domains and set up caches, and even redirect trackers (like Google), so that marketing agencies can't track you. There are many ways to make your browsing experience safer with your own DNS servers.

1. Disable the systemd-resolved service

sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved

sudo rm /etc/resolv.conf

echo 'nameserver 1.1.1.1' >> /etc/resolv.conf
echo 'nameserver 1.0.0.1' >> /etc/resolv.conf

With these commands you can disable the current resolution services so that DNSMASQ has room for the DNS UDP port 53. Normally the systemd-resolved service occupies this port, so DNSMASQ logically can't work properly. That's why we disable the systemd-resolved service.

2. Install DNSMASQ

sudo apt-get install dnsmasq -y

With this command we can install DNSMASQ.

Now we can configure the DNSMASQ DNS server.

sudo nano /etc/dnsmasq.conf

Here are the parameters that can be used in the config:

# The DNS servers to use if DNSMASQ hasn't already found this in the cache.
server=5.1.66.255
server=185.150.99.255
address=/domain.com/127.0.0.1
address=/analytics.google.com/127.0.0.1

With the parameter "address=" we can redirect the domain to a different target IP address. For example, we could redirect Google trackers so that our computer couldn't even reach Google Analytics in the first place.

Restart DNSMASQ

sudo service dnsmasq restart

Now the DNS server can be restarted, and after that the end devices can use the DNS server.

Frequently asked questions

What does a DNS server do?
A DNS server resolves domain names into IP addresses. When you type a domain like www.prepaid-host.com into your browser, your PC sends a request to the configured DNS server asking which IP address is stored for that domain name.
Why do I need to disable systemd-resolved before installing DNSMASQ?
The systemd-resolved service normally occupies UDP port 53. DNSMASQ needs that port free to work properly, so systemd-resolved must be disabled and stopped first.
How do I redirect a domain with DNSMASQ?
Add an address= line in /etc/dnsmasq.conf, for example address=/analytics.google.com/127.0.0.1, then restart DNSMASQ with sudo service dnsmasq restart.
Prepaid-Host.com is itself a provider of servers, web hosting and domains, and reports here on its own market. How we handle that is set out in our disclosure statement.