How to get networkmanager to configure domain specific name servers with openresolv + dnsmasq

NetworkManager has the functionality to manage a local dnsmasq server built in. It is not necessary to use resolvconf/openresolv to do this.

To enable this:

  • Disable the resolvconf/openresolv dnsmasq configuration if it was previously enabled, and ensure there are no instances of dnsmasq running.
  • Ensure dnsmasq is installed
  • Add dns=dnsmasq to /etc/NetworkManager/NetworkManager.conf.
  • Restart NetworkManager

Once you have done this, you will see that NetworkManager has started a dnsmasq process:

$ pgrep dnsmasq -fl
1697 /usr/bin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/nm-dns-dnsmasq.pid --listen-address=127.0.0.1 --conf-file=/var/run/nm-dns-dnsmasq.conf --cache-size=400 --proxy-dnssec

/etc/resolve.conf should be pointing to the local dnsmasq instance:

$ cat /etc/resolv.conf
# Generated by NetworkManager
domain company1.corp
search company1.corp
nameserver 127.0.0.1

and we can see what servers dnsmasq is using:

# cat /var/run/nm-dns-dnsmasq.conf 
server=/company2.corp/10.102.208.51
server=/10.in-addr.arpa/10.102.208.51
server=192.168.1.244
server=192.168.1.239