dhclient triggers / hooks with dhclient-script
dhclient overwrites custom network configuration (read routes) with the defaults provided from the dhcp server. dhclient-script can be used to set custom rules for dhclient. It provides a way to hook into dhclient before and after updating network configuration.
Application specific DHCP options can be handled by creating a script with two functions and placing it in /etc/dhcp/dhclient.d
The script must follow a specific form:
- The script must be named NAME.sh. NAME can be anything, but it makes sense to name it for the service it handles. e.g., network_routes.sh
- The script must provide a NAME_config() function to read the options and do whatever it takes to put those options in place
- The script must provide a NAME_restore() function to restore original configuration state when dhclient stops
- The script must be ‘chmod +x’ or dhclient-script will ignore it
The scripts execute in the same environment as dhclient-script. That means all of the functions and variables available to it are available to your NAME.sh script.
Things of note:
- ${SAVEDIR} is where original configuration files are saved. Save your original configuration files here before you take the DHCP provided values and generate new files
- Variables set in /etc/sysconfig/network, /etc/sysconfig/networking/network, and /etc/sysconfig/network-scripts/ifcfg-$interface are available to you
Took me a while to find this documentation. No more surprises from now on when dhclient updates the lease