Go to main content

Working With DHCP in Oracle® Solaris 11.3

Exit Print View

Updated: October 2017

DHCP Client Event Scripts

You can set up the DHCP client to run an executable program or script, called an event script, that can perform any action that is appropriate for the client system. The program or script is automatically executed after certain DHCP lease events occur. You can use the event script to run other commands, programs, or scripts in response to specific lease events. You must provide your own event script to use this feature.

The event keywords listed in the following table are used by dhcpagent to signify DHCP lease events.

Table 2  DHCP Client Event Script Keywords
Event Keyword
The interface is configured for DHCP. The client receives the acknowledgement message (DHCPv4 ACK) or (DHCPv6 Reply) from the DHCP server, which grants the lease request for an IP address. The event script is invoked immediately after the interface is configured successfully.
The client drops the lease to remove the interface from DHCP control. The event script is invoked immediately before the interface is removed from DHCP control.
The lease expires when the lease time is up. For DHCPv4, the event script is invoked immediately before the leased address is removed from the interface and the interface is marked as down. For DHCPv6, the event script is invoked just before the last remaining leased addresses are removed from the interface.
The client successfully extends a lease. The event script is invoked immediately after the client receives the acknowledgement message from the DHCP server for the renew request.
An interface acquires new or updated configuration information from a DHCP server through the DHCPv4 INFORM or the DHCPv6 Information-Request message. These events occur when the DHCP client obtains only configuration parameters from the server and does not obtain an IP address lease.
During lease expiration, when one or more valid leases still remain, the event script is invoked just before expired addresses are removed. The addresses being removed are marked with the IFF_DEPRECATED flag.
The client relinquishes the IP address. The event script is invoked immediately before the client releases the address on the interface and sends the DHCPv4 RELEASE or DHCPv6 Release packet to the DHCP server.

With each of these events, dhcpagent invokes the following command:

/etc/dhcp/eventhook interface event

where interface is the interface that is using DHCP and event is one of the event keywords described previously. For example, when the interface is first configured for DHCP, the dhcpagent invokes the event script as follows:

/etc/dhcp/eventhook net0 BOUND

    To use the event script feature, you must do the following:

  • Name the executable file /etc/dhcp/eventhook.

  • Set the owner of the file to be root.

  • Set permissions to 755 (rwxr-xr-x).

  • Write the script or program to perform a sequence of actions in response to any of the documented events.

    Because new events might be added in the future, the program must silently ignore any events that are not recognized or do not require action. For example, the program or script might write to a log file when the event is RELEASE and ignore all other events.

  • Make the script or program noninteractive. Before the event script is invoked, stdin, stdout, and stderr are connected to /dev/null. To see the output or errors, you must redirect to a file.

The event script inherits its program environment from dhcpagent, and runs with root privileges. The script can use the dhcpinfo utility to obtain more information about the interface, if necessary. See the dhcpinfo(1) man page for more information.

The dhcpagent daemon waits for the event script to exit on all events. If the event script does not exit after 55 seconds, dhcpagent sends a SIGTERM signal to the script process. If the process still does not exit after three additional seconds, the daemon sends a SIGKILL signal to kill the process.

The dhcpagent(1M) man page includes one example of an event script.