12

I often connect to multiple network simultaneously. Each of these networks provide nameserver configuration via dhcp. E.g. Network 1: (eth0):

domain company1.corp #
nameserver 192.168.0.253
nameserver 192.168.0.254

Network 2 (tun0):

domain company2.corp #
nameserver 10.102.204.51
nameserver 10.102.208.51

# Names changed

When connected to both networks simultaneously:

# resolv.conf from NetworkManager
domain company1.corp, company2.corp
nameserver 192.168.0.253
nameserver 192.168.0.254
nameserver 10.102.204.51
# NOTE: the libc resolver may not support more than 3 nameservers.
# The nameservers listed below may not be recognized.
nameserver 10.102.208.51

Resolving service.company2.corp does not work because the first name server only knows about company1.corp names.

So inspired by this article, I've setup openresolv (a resolvconf implementation) configuring a local dnsmasq service on my Arch linux install.

If I configure the nameservers manually using resolvconf:

# resolvconf -d NetworkManager
# echo "domain company1.corp
nameserver 192.168.0.253
nameserver 192.168.0.254
" | resolvconf -a eth0
# echo "domain company2.corp
nameserver 10.102.204.51
nameserver 10.102.208.51
" | resolvconf -a tun0

Then I am able to resolve names from both company1.corp and company2.corp (the local dnsmasq server handles this.)

Note that after the manual config, resolveconf -l shows the 2 configurations separately:

~ # resolvconf -l
# resolv.conf from tun0
domain company2.corp
nameserver 10.102.204.51
nameserver 10.102.208.51

# resolv.conf from eth0
domain company1.corp
nameserver 192.168.0.253
nameserver 192.168.0.254

However, when letting network manager do the configuration, the 2 configurations are not separate, as the would be if network manager was writing to /etc/resolve.conf

~ # resolvconf -l
# resolv.conf from NetworkManager
# Generated by NetworkManager
domain company1.corp, company2.corp
nameserver 192.168.0.253
nameserver 192.168.0.254
nameserver 10.102.204.51
# NOTE: the libc resolver may not support more than 3 nameservers.
# The nameservers listed below may not be recognized.
nameserver 10.102.208.51

My question is how can I get network manager to correctly call resolveconf so the the name servers for each interface are registered separately. (Unfortunately googling for this is useless because google thinks that "resolveconf" == "resolve.conf")

1
  • 2
    On Google, search for "resolvconf" with the quotes. Always put quotes around proper names on Google. Apr 25, 2012 at 23:45

3 Answers 3

15

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
5
  • real nice, thank you! very straightforward and easy solution but sadly not well known -- couldn't resist, sorry Dec 7, 2012 at 22:46
  • This seems to work when combining a local connection with one or two VPNs. It seems it doesn't work with two local connections. Currently I'm connected to the office network over Ethernet, where sadly the upstream Internet connection has failed. Also I'm connected over USB Ethernet (my phone) to a functioning Internet. I can't get NetworkManager to apply the domain-name to the office DNS server. Aug 6, 2014 at 9:10
  • @OskarBerggren: On your office ethernet, under the IPv4 tab, tick the "Use this connection only for resources on it's network." Aug 8, 2014 at 10:56
  • @GaryvanderMerwe That's exactly what I tried, forgot to write it. There seems to be a related bug/feature request: bugzilla.gnome.org/show_bug.cgi?id=685962 Aug 11, 2014 at 11:59
  • FYI there is not an option to use ubound so also DNSSEC is working, see fedoraproject.org/wiki/Networking/NameResolution/DNSSEC May 4, 2015 at 10:48
1

Do as Gary van der Merwe answered, but in

/etc/NetworkManager/NetworkManager.conf

I had to add

[main]
dns=dnsmasq

to the file. Not just

dns=dnsmasq

This is because all the settings in that file must be under a section, and my distro's, manjaro (archlinux), version of the NetworkManager package does not populate the config file. (I am assuming that Gary's distro does since his suggested line worked for him an others)

Another note, any dnsmasq configuration must go in a config file in this

/etc/NetworkManager/dnsmasq.d/

directory. It may be a different directory on your machine. I learned the directory being used by looking at the line NetworkManager uses to start the dnsmasq daemon. You can see this line by running ps aux|grep dnsmasq. You must wait to run this until after modifying NetworkManager's configuration and restarting its service.

0

It looks like NetworkManager is simply overwriting /etc/resolv.conf and not using openresolv. According to FS#24635, NetworkManager does have support for openreslov, but it wasn't initially enabled in the build. What version of Arch Linux are you running and what is the version of the networkmanager package?

1
  • networkmanager 0.9.4.0-6 NetworkManager is calling resolveconf, and not writing to /etc/resolev.conf. The issues is that NetworkManager is merging the dns information, and passing it to resolveconf as one interface, and not as information for the separate interfaces. Jun 26, 2012 at 11:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .