[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: DHClient Exit Scripts



On Aug 15, 2010, at 5:41 PM, Hal Vaughan wrote:

> I've been reading the man pages for dhclient, but I'm stuck with one key question I've missed.
> 
> I have an exit script set up to notify me of the IP address of a particular system (on a LAN) whenever the IP address changes.  For now I'm testing, but in the future it'll be running where I have no control over DHCP or any servers.  This system will be just plugged into the power outlet and into a CAT5 cable hooked to a hub or switch, so it has to get a dynamic IP address from the DHCP and it has to be able to alert me to what the new IP address is.
> 
> I know whenever dhclient runs, it runs the exit scripts.  The one issue I'm not clear of is whether the exit scripts will be run any time the IP address changes, like when a lease expires.  I know it'll run at reboot or if networking is restarted, but will the exit scripts be run when the IP address is changed by the DHCP?  If it's not, is there any program that runs under those conditions?

I had different answers from different people and finally wrote to Ted Lemon, the author of dhclient to clarify.  Here is my note to him with his response:

-----
On Aug 16, 2010, at 9:57 AM, Ted Lemon wrote:

> On Aug 16, 2010, at 12:05 AM, Hal Vaughan wrote:
>> If it is running as a daemon, will it run dhclient-script whenever the IP on an interface is changed, such as when the lease runs out or when the DNS changes the address for some other reason?
> 
> dhclient-script runs whenever a transaction completes, whether it's an INIT, an INIT-REBOOT, a RENEW, or a REBIND.   It also runs when a transaction times out, or when the client *fails* to renew a lease.   Its purpose in life is to take whatever happened on a protocol level and translate it into configuration actions.   At renewal, it's responsible for *noticing* that things have changed, like the DNS server, and updating the resolv.conf file.
-----

A few notes on this:

1) On Debian there is a directory, /etc/dhcp3/dhclient-exit-hooks.d instead of one exit script.  Any scripts in that directory will be run when dhclient-script runs, which, as Ted clarified, is on any event involving the interface, instead of just running one script (which would force one to put commands at the end of that one script for each additional script one needs to run).

2) It will only run bash scripts.  I tried putting a Perl script in that directory and it wouldn't work, so I had to put a bash script in that directory to run my Perl script.

3) The packages I found that work with DynDNS or similar services mostly ran Perl or Python scripts and were daemons, meaning that using one would mean keeping an instance of Perl or Python in memory, in addition to the needed program.  In my case, I'm working on an embedded system, so that's too much memory to use.  Since dhclient is used by default on most systems, there's no need for an additional daemon, just a script that dhclient-script can run to update a dynamic DNS service.  (Why run two daemons when you need only one?)  I may modify one of the scripts in the Debian packages and send the info back to the author in case he wants to let it work with dhclient as an option.



Hal

Reply to: