Using dnsmasq with NetworkManager

I’ve decided to try using local DNS caching again, using the simple dnsmasq. The problem is that, even including

prepend domain-name-servers 127.0.0.1;

in /etc/dhcp3/dhclient.conf, NetworkManager will overwrite /etc/resolv.conf, and remove

nameserver 127.0.0.1

from there. I found out in a comment here, that I could create a script in /etc/NetworkManager/dispatcher.d/ to make this line be included in the file. The script is simple

#!/bin/sh

set -e

cp /etc/resolv.conf /etc/resolv.conf.tmp
echo nameserver 127.0.0.1 > /etc/resolv.conf
cat /etc/resolv.conf.tmp >> /etc/resolv.conf
rm /etc/resolv.conf.tmp

and it’s working

.

9 Respostas to “Using dnsmasq with NetworkManager”

  1. Julian Andres Klode Says:

    Just apt-get install resolvconf

  2. tina Says:

    — simple way —
    sed -i ‘1s|^|nameserver 127.0.0.1\n|’ /etc/resolv.conf

  3. Alexander E. Patrakov Says:

    Just stop doing that. Look at the source code: dnsmasq doesn’t cache anything.

    • Tim Retout Says:

      @Alexander: Well, src/cache.c looks pretty cache-like to me, and the documentation claims it caches.

      There are other reasons you might want to use dnsmasq as the DNS server for the local machine. For instance, it’s possible to configure reverse DNS entries for local IP addresses, or forward queries for particular subnets to private DNS servers (useful for VPNs).

  4. Dato Says:

    It’s not NetworkManager’s fault.

    You want to use /etc/dhcp/dhclient.conf and not /etc/dhcp3/dhclient.conf.

    The location has changed recently, with the introduction of isc-dhcp-client as the new package name for dhcp3-client.

    HTH.

  5. marcotmarcot Says:

    @Julian: Will it work as I want without any configuration? I took a look at it before, but I was afraid NetworkManager would not work fine with it.

    @tina: Good point, I should have thought of that! =)

    @Tim: What I want it to do is caching. If @Alexander is right, and dnsmasq does no caching despite this filename and its claims, indeed I should stop using it.

    @Dato: Thanks for that, that’s much better than my solution. And it works too.

    • Ken Bloom Says:

      Yes, resolvconf will work fine without any configuration. It will work great with NetworkManager. It’s whole raison d’etre is to save you from having to write configuration files for the various things that manipulate resolv.conf

  6. marcotmarcot Says:

    Julian and Ken: Thanks, I’ve installed resolvconf and it’s working indeed. It’s the better option for this problem without any doubt.

Deixe um comentário