1 .\" $NetBSD: dhclient-script.8,v 1.1.1.3 2014/07/12 11:57:34 spz Exp $
5 .\" Copyright (c) 2012,2014 by Internet Systems Consortium, Inc. ("ISC")
6 .\" Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC")
7 .\" Copyright (c) 2004-2005 by Internet Systems Consortium, Inc. ("ISC")
8 .\" Copyright (c) 1996-2003 by Internet Software Consortium
10 .\" Permission to use, copy, modify, and distribute this software for any
11 .\" purpose with or without fee is hereby granted, provided that the above
12 .\" copyright notice and this permission notice appear in all copies.
14 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
15 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
17 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20 .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 .\" Internet Systems Consortium, Inc.
23 .\" 950 Charter Street
24 .\" Redwood City, CA 94063
26 .\" https://www.isc.org/
28 .\" Support and other services are available for ISC products - see
29 .\" https://www.isc.org for more information or to learn more about ISC.
31 .\" Id: dhclient-script.8,v 1.14 2010/07/02 23:09:14 sar Exp
35 dhclient-script - DHCP client network configuration script
37 The DHCP client network configuration script is invoked from time to
38 time by \fBdhclient(8)\fR. This script is used by the dhcp client to
39 set each interface's initial configuration prior to requesting an
40 address, to test the address once it has been offered, and to set the
41 interface's final configuration once a lease has been acquired. If no
42 lease is acquired, the script is used to test predefined leases, if
43 any, and also called once if no valid lease can be identified.
45 This script is not meant to be customized by the end user. If local
46 customizations are needed, they should be possible using the enter and
47 exit hooks provided (see HOOKS for details). These hooks will allow the
48 user to override the default behaviour of the client in creating a
52 No standard client script exists for some operating systems, even though
53 the actual client may work, so a pioneering user may well need to create
54 a new script or modify an existing one. In general, customizations specific
55 to a particular computer should be done in the
56 .B ETCDIR/dhclient.conf
57 file. If you find that you can't make such a customization without
59 .B ETCDIR/dhclient.conf
60 or using the enter and exit hooks, please submit a bug report.
62 When it starts, the client script first defines a shell function,
64 which is later used to create the
66 file. To override the default behaviour, redefine this function in
67 the enter hook script.
69 On after defining the make_resolv_conf function, the client script checks
70 for the presence of an executable
71 .B ETCDIR/dhclient-enter-hooks
72 script, and if present, it invokes the script inline, using the Bourne
73 shell \'.\' command. The entire environment documented under OPERATION
74 is available to this script, which may modify the environment if needed
75 to change the behaviour of the script. If an error occurs during the
76 execution of the script, it can set the exit_status variable to a nonzero
78 .B CLIENTBINDIR/dhclient-script
79 will exit with that error code immediately after the client script exits.
81 After all processing has completed,
82 .B CLIENTBINDIR/dhclient-script
83 checks for the presence of an executable
84 .B ETCDIR/dhclient-exit-hooks
85 script, which if present is invoked using the \'.\' command. The exit
86 status of dhclient-script will be passed to dhclient-exit-hooks in the
87 exit_status shell variable, and will always be zero if the script
88 succeeded at the task for which it was invoked. The rest of the
89 environment as described previously for dhclient-enter-hooks is also
91 .B ETCDIR/dhclient-exit-hooks
92 script can modify the valid of exit_status to change the exit status
95 When dhclient needs to invoke the client configuration script, it
96 defines a set of variables in the environment, and then invokes
97 .B CLIENTBINDIR/dhclient-script.
98 In all cases, $reason is set to the name of the reason why the script
99 has been invoked. The following reasons are currently defined:
100 MEDIUM, PREINIT, BOUND, RENEW, REBIND, REBOOT, EXPIRE, FAIL, STOP, RELEASE,
104 The DHCP client is requesting that an interface's media type
105 be set. The interface name is passed in $interface, and the media
106 type is passed in $medium.
108 The DHCP client is requesting that an interface be configured as
109 required in order to send packets prior to receiving an actual
110 address. For clients which use the BSD socket library, this means
111 configuring the interface with an IP address of 0.0.0.0 and a
112 broadcast address of 255.255.255.255. For other clients, it may be
113 possible to simply configure the interface up without actually giving
114 it an IP address at all. The interface name is passed in $interface,
115 and the media type in $medium.
117 If an IP alias has been declared in dhclient.conf, its address will be
118 passed in $alias_ip_address, and that ip alias should be deleted from
119 the interface, along with any routes to it.
121 The DHCP client has done an initial binding to a new address. The
122 new ip address is passed in $new_ip_address, and the interface name is
123 passed in $interface. The media type is passed in $medium. Any
124 options acquired from the server are passed using the option name
125 described in \fBdhcp-options\fR, except that dashes (\'-\') are replaced
126 by underscores (\'_\') in order to make valid shell variables, and the
127 variable names start with new_. So for example, the new subnet mask
128 would be passed in $new_subnet_mask. The options that the client
129 explicitly requested via a PRL or ORO option are passed with the same
130 option name as above but prepended with requested_ and with a value of 1,
131 or example requested_subnet_mask=1. No such variable is defined for
132 options not requested by the client or options that don't require a
133 request option, such as the ip address (*_ip_address) or expiration
136 Before actually configuring the address, dhclient-script should
137 somehow ARP for it and exit with a nonzero status if it receives a
138 reply. In this case, the client will send a DHCPDECLINE message to
139 the server and acquire a different address. This may also be done in
140 the RENEW, REBIND, or REBOOT states, but is not required, and indeed
141 may not be desirable.
143 When a binding has been completed, a lot of network parameters are
144 likely to need to be set up. A new /etc/resolv.conf needs to be
145 created, using the values of $new_domain_name and
146 $new_domain_name_servers (which may list more than one server,
147 separated by spaces). A default route should be set using
148 $new_routers, and static routes may need to be set up using
151 If an IP alias has been declared, it must be set up here. The alias
152 IP address will be written as $alias_ip_address, and other DHCP
153 options that are set for the alias (e.g., subnet mask) will be passed
154 in variables named as described previously except starting with
155 $alias_ instead of $new_. Care should be taken that the alias IP
156 address not be used if it is identical to the bound IP address
157 ($new_ip_address), since the other alias parameters may be incorrect
160 When a binding has been renewed, the script is called as in BOUND,
161 except that in addition to all the variables starting with $new_, and
162 $requested_ there is another set of variables starting with $old_.
163 Persistent settings that may have changed need to be deleted - for
164 example, if a local route to the bound address is being configured,
165 the old local route should be deleted. If the default route has changed,
166 the old default route should be deleted. If the static routes have changed,
167 the old ones should be deleted. Otherwise, processing can be done as with
170 The DHCP client has rebound to a new DHCP server. This can be handled
171 as with RENEW, except that if the IP address has changed, the ARP
172 table should be cleared.
174 The DHCP client has successfully reacquired its old address after a
175 reboot. This can be processed as with BOUND.
177 The DHCP client has failed to renew its lease or acquire a new one,
178 and the lease has expired. The IP address must be relinquished, and
179 all related parameters should be deleted, as in RENEW and REBIND.
181 The DHCP client has been unable to contact any DHCP servers, and any
182 leases that have been tested have not proved to be valid. The
183 parameters from the last lease tested should be deconfigured. This
184 can be handled in the same way as EXPIRE.
186 The dhclient has been informed to shut down gracefully, the
187 dhclient-script should unconfigure or shutdown the interface as
190 The dhclient has been executed using the -r flag, indicating that the
191 administrator wishes it to release its lease(s). dhclient-script should
192 unconfigure or shutdown the interface.
194 No-Broadcast-Interfaces...dhclient was unable to find any interfaces
195 upon which it believed it should commence DHCP. What dhclient-script
196 should do in this situation is entirely up to the implementor.
198 The DHCP client has been unable to contact any DHCP servers.
199 However, an old lease has been identified, and its parameters have
200 been passed in as with BOUND. The client configuration script should
201 test these parameters and, if it has reason to believe they are valid,
202 should exit with a value of zero. If not, it should exit with a
205 The usual way to test a lease is to set up the network as with REBIND
206 (since this may be called to test more than one lease) and then ping
207 the first router defined in $routers. If a response is received, the
208 lease must be valid for the network to which the interface is
209 currently connected. It would be more complete to try to ping all of
210 the routers listed in $new_routers, as well as those listed in
211 $new_static_routes, but current scripts do not do this.
213 Each operating system should generally have its own script file,
214 although the script files for similar operating systems may be similar
215 or even identical. The script files included in Internet
216 Systems Consortium DHCP distribution appear in the distribution tree
217 under client/scripts, and bear the names of the operating systems on
218 which they are intended to work.
220 If more than one interface is being used, there's no obvious way to
221 avoid clashes between server-supplied configuration parameters - for
222 example, the stock dhclient-script rewrites /etc/resolv.conf. If
223 more than one interface is being configured, /etc/resolv.conf will be
224 repeatedly initialized to the values provided by one server, and then
225 the other. Assuming the information provided by both servers is
226 valid, this shouldn't cause any real problems, but it could be
229 dhclient(8), dhcpd(8), dhcrelay(8), dhclient.conf(5) and
232 .B dhclient-script(8)
233 To learn more about Internet Systems Consortium,
235 .B https://www.isc.org.