Mittwoch, 27. Februar 2019

Switch from systemd-resolved to dnsmasq

So DNS handling is rather messy on (K)Ubuntu, especially if you need to change some settings. Your best bet is to switch back to using dnsmasq, here's how to do that:
  1. Remove /etc/resolv.conf

  2. Install dnsmasq:
    sudo apt-get install dnsmasq

  3. Disable and stop systemd-resolve (if currently being used):
    sudo systemctl disable systemd-resolved.service
    sudo systemctl stop systemd-resolved

  4. Make sure /etc/resolv.conf is a link to /run/resolvconf/resolv.conf, which should just contain the line
    nameserver 127.0.0.1

  5. Edit /etc/NetworkManager/NetworkManager.conf to contain this line in [main] section:
    dns=dnsmasq

  6. Restart the system to be on the safe side.
Now this should use the DNS nameservers NetworkManager received via DHCP. If you need to manually override it, you can edit /etc/dnsmasq.conf, e.g. to override DNS servers from DHCP to resolve Dropbox and Google queries via Google' DNS 8.8.8.8, and fallback to 1.2.3.4 for all other domains:
server=/dropbox.com/8.8.8.8
server=/dropboxapi.com/8.8.8.8
server=/google.com/8.8.8.8
server=/#/1.2.3.4