Using dnsmasq with networkManager in Ubuntu 20.04

Juan Enciso
Juan Enciso
IT Architect, SRE Engineer, DevOps Tools Trainer
Jun 1, 2020 2 min read
thumbnail for this post


Remote work has been increased since covid-19. VPN appliances turned crucial devices and employees has been using more than ever their companies internal services. VPN often need to setup your DNS configuration in order to use the internal DNS server of the company, so you can resolve hostnames or services offer by your company.

The Problem:

Thus each dns request are going to use the same VPN network and these UDP packets are encrypt and transmit using your own Internet. This process will repeat for each simple dns record. So, all this round trip create an unnecessary communication overhead. To reduce this overhead, you could implement a dns cache of these requests as alternative to improve your network latency and speed up your internet browsing.

Installing a Dnsmaq service Hero

For ubuntu

Uninstall systemd-resolved package. It isn’t necessary to have.

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

Disabled dnsmasq in the /etc/NetworkManager/NetworkManager.conf. Also, ensure to have the dns=none line




Restart NetworkManager

sudo systemctl restart NetworkManager


Remove the current /etc/resolvconf file and install dnsmasq

unlink /etc/resolv.conf
sudo apt-get install dnsmasq

Config your upstream dns

echo "nameserver" | sudo tee /etc/resolv.dnsmasq
echo "nameserver" | sudo tee -a /etc/resolv.dnsmasq

Config your dnsmasq.conf file. Use a cache-size parameter:

sudo tee /etc/dnsmasq.conf << EOF

Use the dnsmasq as main dns provider

echo "nameserver" | sudo tee /etc/resolv.conf

Restart dnsmasq service

systemctl restart dnsmasq
systemctl enable dnsmasq


You should get 0 msec in the next dns query.

$ dig | grep "Query time"
;; Query time: 0 msec


comments powered by Disqus