Here are the steps for ubuntu since 18.04. It's a little bit long since systemd-resolved
does not play very well with NetworkManager
when configured with dnsmasq
.
Yet I still recommend starting dnsmasq
from NetworkManager
, because network connectivity changes (WIFI, wired, ...) will be handled transparently.
Enable dnsmasq in NetworkManager
Edit the file /etc/NetworkManager/NetworkManager.conf
, and add the line dns=dnsmasq
to the [main]
section, it will look like this :
[main]
plugins=ifupdown,keyfile
dns=dnsmasq
[ifupdown]
managed=false
[device]
wifi.scan-rand-mac-address=no
Let NetworkManager manage /etc/resolv.conf
sudo rm /etc/resolv.conf ; sudo ln -s /var/run/NetworkManager/resolv.conf /etc/resolv.conf
Configure example.com
echo 'address=/.example.com/127.0.0.1' | sudo tee /etc/NetworkManager/dnsmasq.d/example.com-wildcard.conf
Reload NetworkManager
and testing
NetworkManager should be reloaded for the changes to take effect.
sudo systemctl reload NetworkManager
Then we can verify that we can reach some usual site :
dig askubuntu.com +short
151.101.129.69
151.101.65.69
151.101.1.69
151.101.193.69
And lastly verify that the example.com
and subdomains are resolved as 127.0.0.1
:
dig example.com askubuntu.example.com a.b.c.d.example.com +short
127.0.0.1
127.0.0.1
127.0.0.1