3
1
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;
in /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 resolv.conf
..:
How can one force dhclient(8)
to update resolv.conf
whilst keeping the network connections up and running?
[EDIT]
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.
I expect the answer would depend on your client. With OpenBSD's client which is based on ISC DHCP (which might be what you use), there is an /etc/dhclient.conf that is usually used. "dhclient -c /etc/dhclient.conf" can specify a custom file. The file specifies to do things like figure out the subnet mask, routers (default gateway), and DNS stuff. You could take out what you want. But IP address doesn't seem to be one of the options. There may be no default built-in support to not query. .conf's "supersede" could ignore the info, though. Maybe see also: man dhclient-script – TOOGAM – 2015-02-15T22:24:11.350
1The
dhclient(8)
manual page tells it supports some funky protocol called "Omapi" which allows remote configuration, and refers to theomshell
tool which can be used to set/unset certain parameters in the client and update it, as well as shut it down and restart. Did you explore this route? – kostix – 2013-04-08T09:56:04.5431Yes, but it doesn't provide a way to update
resolv.conf
. Note that the DHCP client itself is not the issue here, it's theresolv.conf
file: It's considered by theresolver(3)
C-API and thus used by other software. Usually, the update is performed by eitherdhclient(8)
orresolvconf(8)
, but the first resets the network connection and the latter fails to preserve the existing configuration -- – mjhennig – 2013-04-08T14:22:32.490