How can I make local dnsmasq play nicely with NetworkManager?

Robert Nichols rnicholsNOSPAM at
Thu Jul 29 15:05:33 UTC 2010

On 06/28/2010 02:33 PM, Robert Nichols wrote:
> I am trying to set up dnsmasq as a local resolver cache on my F-12
> laptop, and can't find any way to pass the nameservers returned by DHCP
> to dnsmasq as upstream nameservers and still have appear as
> the primary nameserver in /etc/resolv.conf.
> NetworkManager creates a resolv.conf file that contains only the servers
> returned by DHCP.  That does not allow queries from local processes to
> be routed through the local caching resolver.
> Without NetworkManager, I would just put a line in dhclient.conf to
> prepend "" to the list of nameservers returned by DHCP.
> dnsmasq would then read resolv.conf, nicely ignore that entry, and use
> the other nameserver entries as upstream servers.  NetworkManager always
> invokes dhclient with a custom config file that is created anew for each
> invocation, and gives no means to add this customization.
> If I configure NetworkManager to put "" as a nameserver in
> resolv.conf, then _only_ that nameserver will appear, and dnsmasq has
> no way to discover the upstream servers.

FWIW, I've written a C program that makes this work.  The program sets
up a file alteration monitor on /etc/resolv.conf.  Whenever that file
changes, the code ensures that "" is the first nameserver
listed there and passes the upstream server addresses to dnsmasq.  A
short script in /etc/NetworkManager/dispatcher.d makes sure this program
is running whenever a network interface is started.  I believe it's
pretty bulletproof, and most of its configuration can be overridden from
the command line.

Source is available from

Comments & suggestions are welcome.

Bob Nichols     "NOSPAM" is really part of my email address.
                 Do NOT delete it.

More information about the users mailing list