I'm trying to configure
dnsmasq(8) on a Debian GNU/Linux system in a private
DHCP-based network. During a local, manual setup - after installing
dnsmasq istelf - one could simply include the line
prepend domain-name-servers 127.0.0.1;
/etc/dhcp/dhclient.conf and restart networking. This will include the local host in
/etc/resolv.conf and one is ready to go. (See also: http://wiki.debian.org/HowTo/dnsmasq#Local_Caching)
But attempts to do the same remotely, especially when working with configuration-managment software, would result in the network connection being lost. Well, since the goal is not the network restart, but updating
How can one force
dhclient(8) to update
resolv.conf whilst keeping the network connections up and running?
Below please find a script that worked for me:
if grep '^\s*nameserver\>.\+\<127\.0\.0\.1\>' /etc/resolv.conf >/dev/null; then : # do nothing else grep -v '^\s*nameserver\>' /etc/resolv.conf > /tmp/resolv.conf.new echo "nameserver 127.0.0.1" >> /tmp/resolv.conf.new grep '^\s*nameserver\>' /etc/resolv.conf >> /tmp/resolv.conf.new mv -f /tmp/resolv.conf.new /etc/resolv.conf fi
It's kind of awkward - and I'm still searching for a better solution.