Configure a local DNS server for local development work on Linux with NetworkManager and dnsmasq.
-
Check if the
systemd-resolvedstub listener is running:If the output of:
netstat -tulpn | grep "LISTEN"shows
systemd-resolvedlistening on127.0.0.53:53, then edit/etc/systemd/resolved.confand set the following option:DNSStubListener=noRestart
systemd-resolvedwith: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.confwith the contents:[main] dns=dnsmasq -
Configure dnsmasq to listen on the correct address by adding
/etc/NetworkManager/dnsmasq.d/10-dnsmasq.confwith 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.confwith 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 dnsYou should be able to resolve
*.lhe.g.:dig +short test.lh 127.0.0.1