How can I set up local wildcard (127.0.0.1) domain resolution on 18.04..20.04?
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
First make sure in /etc/NetworkManager/NetworkManager.conf
the following line is not present or commented out:
dns=dnsmasq
Restart NetworkManager:
sudo systemctl restart NetworkManager
Make sure the NetworkManager-controlled dnsmasq is not running anymore, either by killing the process or rebooting your system.
Then install dnsmasq:
sudo apt install dnsmasq
Add the following to /etc/dnsmasq.d/example.com
:
address=/example.com/127.0.0.1
Restart dnsmasq:
sudo systemctl restart dnsmasq
Now you should have a wildcard dns override for example.com.