Can I configure dhclient to execute a bash script after a successful DHCP renewal?
I've found a solution to my problem. man dhclient
states that a script is invoked by dhclient
when it gets a lease. Further reading of man dhclient-script
and the actual script itself describes the location of scripts that dhclient
executes depending on the phase of the dhcp process.
The hooks are located in /etc/dhcp/dhclient-enter-hooks.d
and /etc/dhcp/dhclient-exit-hooks.d
directories for before and after dhclient
execution. Since I'm interested in executing a script after a successful renewal, I placed my script inside the ...-enter-hooks.d
directory.
Here's the script, checking for the particular phases which signify a new dhcp ip address before executing the dynamic dns script:
case "$reason" in
BOUND|RENEW|REBIND|REBOOT)
sh /etc/network/rinker.sh
;;
esac
I got rinker.sh
from http://www.changeip.com/accounts/downloads.php?action=displaycat&catid=4, which is just a simple wget call to the website's update URL.