Configure a local DNS server for local development work on Linux with NetworkManager and dnsmasq.
-
Check if the
systemd-resolved
stub listener is running:If the output of:
netstat -tulpn | grep "LISTEN"
shows
systemd-resolved
listening on127.0.0.53:53
, then edit/etc/systemd/resolved.conf
and set the following option:DNSStubListener=no
Restart
systemd-resolved
with:systemctl restart systemd-resolved.service
-
On Ubuntu / Fedora dnsmasq is pre-installed with NetworkManager, we just need to enable it by creating a file
/etc/NetworkManager/conf.d/10-dnsmasq.conf
with the contents:[main] dns=dnsmasq
-
Configure dnsmasq to listen on the correct address by adding
/etc/NetworkManager/dnsmasq.d/10-dnsmasq.conf
with the contents:listen-address=127.0.0.53
-
Add domains to dnsmasq by creating files in
/etc/NetworkManager/dnsmasq.d/
, for example:Create the a file
/etc/NetworkManager/dnsmasq.d/20-lh.conf
with the following:address=/lh/127.0.0.1
-
Restart NetworkManager and verify:
systemctl restart NetworkManager # Should show dnsmasq listening on 127.0.0.53:53 netstat -tulpn | grep "LISTEN" # Should show a dnsmasq process ps aux | grep dns
You should be able to resolve
*.lh
e.g.:dig +short test.lh 127.0.0.1