Method for acting on IP address change from the ISP?

As Wouter commented, your existing setup seems pretty decent already.

If you want something less dependent on dhclient, you could have a look at the many dynamic DNS clients packaged in Debian.

For example, ddclient can react to DHCP changes or simply monitor an Ethernet interface; when the IP address changes (and only then), it can update a dynamic DNS entry (on any number of providers), as well as run a separate script (which would cover both your use-cases).


I propose to further simplify/split up your solution following the principle of separation of concerns:

  • a script /etc/dhcp/dhclient-exit-hooks.d/trigger_on_ip_change should only decide whether action needs to be taken and defer the action to a separate script /usr/local/bin/act_on_ip_change
  • the script /usr/local/bin/act_on_ip_change should only execute the necessary changes

The reasons for separating those concerns are:

  • you can test separately whether dhclient is triggering correctly (without actually modifying anything on your system during debugging)
  • you can test the "change making" without the need to renew (and thus potential loose) your IP
  • you can execute /usr/local/bin/act_on_ip_change manually in case there's a need
  • the parts are much easier to understand

In short, I'd suggest to have this in /etc/dhcp/dhclient-exit-hooks.d/trigger_on_ip_change_action:

# based on /etc/dhcp/dhclient-exit-hooks.d/debug

if [ "$reason" = "BOUND" -a "$old_ip_address" != "$new_ip_address" ]; then
  /usr/local/bin/act_on_ip_change
fi

Tags:

Linux

Debian

Dhcp