dhclient-script
Configure network interfaces after DHCP lease events
SYNOPSIS
dhclient-script interface reason
While not typically run by users directly, dhclient invokes it with the network interface being configured (e.g., eth0) and the current DHCP reason (e.g., BOUND, RENEW). The actual configuration data is passed via environment variables.
PARAMETERS
interface
The name of the network interface currently being configured or deconfigured by dhclient (e.g., eth0, enp0s3).
reason
Indicates the current state or event in the DHCP client's lifecycle that triggered the script execution. Common reasons include: PREINIT, BOUND, RENEW, REBIND, EXPIRE, RELEASE, FAIL.
DESCRIPTION
dhclient-script is a crucial shell script invoked internally by the dhclient daemon, which is the ISC DHCP client. Its primary purpose is to configure the system's network interfaces based on the DHCP lease information received from a DHCP server. When dhclient successfully obtains or renews a lease, it executes dhclient-script, passing various DHCP option values as environment variables (e.g., IP address, netmask, gateway, DNS servers).
The script then uses these variables to apply the appropriate network settings, which typically involves: configuring the IP address and netmask for the interface, adding default routes, and updating the /etc/resolv.conf file with DNS server information. It's invoked at different stages of the DHCP negotiation lifecycle, identified by a 'reason' argument (e.g., PREINIT, BOUND, RENEW, EXPIRE, RELEASE, FAIL). Users generally do not execute this script directly; it operates as an internal component of the DHCP client process.
CAVEATS
dhclient-script is not intended for direct user execution in most typical scenarios; it's an internal component of the dhclient daemon.
It relies heavily on environment variables set by dhclient to receive lease information. Without these, manual execution is largely ineffective for network configuration.
Customization should generally be done via hook scripts in designated directories rather than directly modifying dhclient-script, to maintain compatibility and ease upgrades.
Behavior can slightly vary between different versions of the ISC DHCP client or if a different DHCP client is used.
ENVIRONMENT VARIABLES
When dhclient-script is invoked, dhclient populates numerous environment variables with information from the DHCP lease. These include:
new_ip_address, new_subnet_mask, new_routers, new_broadcast_address for network settings.
new_domain_name, new_domain_name_servers for DNS configuration.
new_ntp_servers, new_host_name, etc., for other DHCP options.
The script uses these variables to perform its configuration tasks.
HOOK SCRIPTS AND CUSTOMIZATION
The dhclient-script is designed to be extensible. It sources and executes scripts from various directories during its execution, allowing administrators to add custom logic. Common hook directories include:
/etc/dhcp/dhclient-enter-hooks.d/: Scripts executed at the beginning of the script's run.
/etc/dhcp/dhclient-exit-hooks.d/: Scripts executed at the end of the script's run.
/etc/dhcp/dhclient-event-hooks.d/: Scripts executed for specific events (e.g., pre-init, bound).
This mechanism is the recommended way to extend or modify dhclient's behavior without altering the main script.
HISTORY
dhclient-script is an integral part of the ISC DHCP client suite, which has been a foundational component for DHCP client functionality in Unix-like operating systems for decades. Its modular and script-based design allows for high flexibility and system-specific customization, a common characteristic of Linux networking tools. It has evolved alongside the dhclient daemon, adapting to new network configurations and operating system features while maintaining its core responsibility of applying DHCP-provided network settings.