[Dnsmasq-discuss] writing a dhclient-exit-hooks script to manage dnsmasq
ranceh at gmail.com
Thu Jul 9 02:12:19 BST 2009
hey gang, Im trying to do something I've done repeatedly with static
external ip addresses but now that I have a external dhcp address
things have gone a little off.
What I used to do was mv /etc/resolv.conf to /etc/resolv.conf.dnsmasq
and tell dnsmasq to read this file instead of /etc/resolv.conf then I
would edit /etc/resolv.conf to point the machine back to itself.
This way during normal operation the dhcp server ping, ssh, etc to the
same machines by hostname that the clients all did.
Enter a dhcp based external interface
/etc/resolv.conf is rewritten from time to time as my ISP uses a set
of DNS servers and selects the least busy one to give out for load
There are lots of tutorials on how to get /etc/resolv.conf to NOT get
rewritten, but if the ISP changes it on purpose, not rewriting the
file is not an option.
so, I came up with the idea of creating an extra file called
/etc/resolv.conf.perm for the permanant /etc/resolv.conf to reside.
Then as part of dhclient-exit-hooks, I would check if /etc/resolv.conf
had been rewritten some way and if it did, move the .conf file to
.conf.dnsmasq and then copy the .conf.perm into .conf
then I would have to send dnsmasq a signal (a SIGHUP if I read the
Then I need the script to do something strange, I want it to upload a
file to my isp's webhosting account so that my public ip address is
available via a simple grep of a downloaded .html file I already know
how to script an ftp session, so that part is easy.
I have several questions...
1) according to dnsmasq documentation a SIGHUP will cause all the
config files to re re-read and it will also re-read /etc/resolv.conf
if the no-poll option is set.
Am I reading this correctly? Is there a way to ask dnsmasq to just
re-read the resolv file without having to reload everything?
2) I'm not convinced that dhclient-exit-hooks is the right place for
this, but I cant think of another. There are lots of google hits on
errors with dhclient-exit-hooks not running.
Not to mention that I dont yet understand when the various things
happen that dhclient-script asks for. (like "Is /etc/resolv.conf
created before or after the exit-hooks-script is run?"
or "What about one of the interface specific scripts that
dhclient-script executes at different places in the process?" or "Is
the value of the new IP available to a dhclient-exit-hooks script so I
could just reference the variable, or do I have to look it up on my
If someone would be so kind as to help straighten me out with a
pointer to a good primer, or something like that I would be grateful.
Is there a better way/place to do what I want to do?
3) if anyone has done anything like this, and wouldn't mind sharing,
I'd love to see a reasonably active script that really does some
Thanks all for the time, and I apologize for the parts of this that
are related, but maybe off topic
As a way of saying thanks I would like to contribute the script for
public use when its done.
Simon, you think there is room for something like this in /contrib?
More information about the Dnsmasq-discuss