1dhclient-script(8) System Manager's Manual dhclient-script(8)
2
3
4
6 dhclient-script - DHCP client network configuration script
7
9 The DHCP client network configuration script is invoked from time to
10 time by dhclient(8). This script is used by the dhcp client to set
11 each interface's initial configuration prior to requesting an address,
12 to test the address once it has been offered, and to set the inter‐
13 face's final configuration once a lease has been acquired. If no lease
14 is acquired, the script is used to test predefined leases, if any, and
15 also called once if no valid lease can be identified.
16
17 This script is not meant to be customized by the end user. If local
18 customizations are needed, they should be possible using the enter and
19 exit hooks provided (see HOOKS for details). These hooks will allow
20 the user to override the default behaviour of the client in creating a
21 /etc/resolv.conf file, and to handle DHCP options not handled by
22 default.
23
24 No standard client script exists for some operating systems, even
25 though the actual client may work, so a pioneering user may well need
26 to create a new script or modify an existing one. In general, cus‐
27 tomizations specific to a particular computer should be done in the
28 /etc/dhclient.conf file. If you find that you can't make such a cus‐
29 tomization without customizing /etc/dhclient.conf or using the enter
30 and exit hooks, please submit a bug report.
31
33 When it starts, the client script first defines a shell function,
34 make_resolv_conf , which is later used to create the /etc/resolv.conf
35 file. To override the default behaviour, redefine this function in
36 the enter hook script.
37
38 On after defining the make_resolv_conf function, the client script
39 checks for the presence of an executable /etc/dhclient-enter-hooks
40 script, and if present, it invokes the script inline, using the Bourne
41 shell '.' command. The entire environment documented under OPERATION
42 is available to this script, which may modify the environment if needed
43 to change the behaviour of the script. If an error occurs during the
44 execution of the script, it can set the exit_status variable to a
45 nonzero value, and /sbin/dhclient-script will exit with that error code
46 immediately after the client script exits.
47
48 After all processing has completed, /sbin/dhclient-script checks for
49 the presence of an executable /etc/dhclient-exit-hooks script, which if
50 present is invoked using the '.' command. The exit status of dhclient-
51 script will be passed to dhclient-exit-hooks in the exit_status shell
52 variable, and will always be zero if the script succeeded at the task
53 for which it was invoked. The rest of the environment as described
54 previously for dhclient-enter-hooks is also present. The
55 /etc/dhclient-exit-hooks script can modify the valid of exit_status to
56 change the exit status of dhclient-script.
57
58 Immediately after dhclient brings an interface UP with a new IP
59 address, subnet mask, and routes, in the REBOOT/BOUND states, it will
60 check for the existence of an executable /etc/dhclient-up-hooks script,
61 and source it if found. This script can handle DHCP options in the
62 environment that are not handled by default. A per-interface
63 /etc/dhclient-${IF}-up-hooks script will override the generic script
64 and be sourced when interface $IF has been brought up.
65
66 Immediately before dhclient brings an interface DOWN, removing its IP
67 address, subnet mask, and routes, in the STOP/RELEASE states, it will
68 check for the existence of an executable /etc/dhclient-down-hooks
69 script, and source it if found. This script can handle DHCP options in
70 the environment that are not handled by default. A per-interface
71 /etc/dhclient-${IF}-down-hooks script will override the generic script
72 and be sourced when interface $IF is about to be brought down.
73
74
76 When dhclient needs to invoke the client configuration script, it
77 defines a set of variables in the environment, and then invokes
78 /sbin/dhclient-script. In all cases, $reason is set to the name of the
79 reason why the script has been invoked. The following reasons are
80 currently defined: MEDIUM, PREINIT, BOUND, RENEW, REBIND, REBOOT,
81 EXPIRE, FAIL, STOP, RELEASE, NBI and TIMEOUT.
82
84 The DHCP client is requesting that an interface's media type be set.
85 The interface name is passed in $interface, and the media type is
86 passed in $medium.
87
89 The DHCP client is requesting that an interface be configured as
90 required in order to send packets prior to receiving an actual address.
91 For clients which use the BSD socket library, this means configuring
92 the interface with an IP address of 0.0.0.0 and a broadcast address of
93 255.255.255.255. For other clients, it may be possible to simply con‐
94 figure the interface up without actually giving it an IP address at
95 all. The interface name is passed in $interface, and the media type
96 in $medium.
97
98 If an IP alias has been declared in dhclient.conf, its address will be
99 passed in $alias_ip_address, and that ip alias should be deleted from
100 the interface, along with any routes to it.
101
103 The DHCP client has done an initial binding to a new address. The new
104 ip address is passed in $new_ip_address, and the interface name is
105 passed in $interface. The media type is passed in $medium. Any
106 options acquired from the server are passed using the option name
107 described in dhcp-options, except that dashes ('-') are replaced by
108 underscores ('_') in order to make valid shell variables, and the vari‐
109 able names start with new_. So for example, the new subnet mask would
110 be passed in $new_subnet_mask.
111
112 Before actually configuring the address, dhclient-script should somehow
113 ARP for it and exit with a nonzero status if it receives a reply. In
114 this case, the client will send a DHCPDECLINE message to the server and
115 acquire a different address. This may also be done in the RENEW,
116 REBIND, or REBOOT states, but is not required, and indeed may not be
117 desirable.
118
119 When a binding has been completed, a lot of network parameters are
120 likely to need to be set up. A new /etc/resolv.conf needs to be cre‐
121 ated, using the values of $new_domain_name and $new_domain_name_servers
122 (which may list more than one server, separated by spaces). A default
123 route should be set using $new_routers, and static routes may need to
124 be set up using $new_static_routes.
125
126 If an IP alias has been declared, it must be set up here. The alias
127 IP address will be written as $alias_ip_address, and other DHCP options
128 that are set for the alias (e.g., subnet mask) will be passed in vari‐
129 ables named as described previously except starting with $alias_
130 instead of $new_. Care should be taken that the alias IP address not
131 be used if it is identical to the bound IP address ($new_ip_address),
132 since the other alias parameters may be incorrect in this case.
133
135 When a binding has been renewed, the script is called as in BOUND,
136 except that in addition to all the variables starting with $new_, there
137 is another set of variables starting with $old_. Persistent settings
138 that may have changed need to be deleted - for example, if a local
139 route to the bound address is being configured, the old local route
140 should be deleted. If the default route has changed, the old default
141 route should be deleted. If the static routes have changed, the old
142 ones should be deleted. Otherwise, processing can be done as with
143 BOUND.
144
146 The DHCP client has rebound to a new DHCP server. This can be handled
147 as with RENEW, except that if the IP address has changed, the ARP table
148 should be cleared.
149
151 The DHCP client has successfully reacquired its old address after a
152 reboot. This can be processed as with BOUND.
153
155 The DHCP client has failed to renew its lease or acquire a new one, and
156 the lease has expired. The IP address must be relinquished, and all
157 related parameters should be deleted, as in RENEW and REBIND.
158
160 The DHCP client has been unable to contact any DHCP servers, and any
161 leases that have been tested have not proved to be valid. The parame‐
162 ters from the last lease tested should be deconfigured. This can be
163 handled in the same way as EXPIRE.
164
166 The dhclient has been informed to shut down gracefully, the dhclient-
167 script should unconfigure or shutdown the interface as appropriate.
168
170 The dhclient has been executed using the -r flag, indicating that the
171 administrator wishes it to release its lease(s). dhclient-script
172 should unconfigure or shutdown the interface.
173
175 No-Broadcast-Interfaces...dhclient was unable to find any interfaces
176 upon which it believed it should commence DHCP. What dhclient-script
177 should do in this situation is entirely up to the implementor.
178
180 The DHCP client has been unable to contact any DHCP servers. However,
181 an old lease has been identified, and its parameters have been passed
182 in as with BOUND. The client configuration script should test these
183 parameters and, if it has reason to believe they are valid, should exit
184 with a value of zero. If not, it should exit with a nonzero value.
185
186 The usual way to test a lease is to set up the network as with REBIND
187 (since this may be called to test more than one lease) and then ping
188 the first router defined in $routers. If a response is received, the
189 lease must be valid for the network to which the interface is currently
190 connected. It would be more complete to try to ping all of the
191 routers listed in $new_routers, as well as those listed in
192 $new_static_routes, but current scripts do not do this.
193
195 Each operating system should generally have its own script file,
196 although the script files for similar operating systems may be similar
197 or even identical. The script files included in Internet Systems Con‐
198 sortium DHCP distribution appear in the distribution tree under
199 client/scripts, and bear the names of the operating systems on which
200 they are intended to work.
201
203 If more than one interface is being used, there's no obvious way to
204 avoid clashes between server-supplied configuration parameters - for
205 example, the stock dhclient-script rewrites /etc/resolv.conf. If more
206 than one interface is being configured, /etc/resolv.conf will be
207 repeatedly initialized to the values provided by one server, and then
208 the other. Assuming the information provided by both servers is
209 valid, this shouldn't cause any real problems, but it could be confus‐
210 ing.
211
213 dhclient(8), dhcpd(8), dhcrelay(8), dhclient.conf(5) and
214 dhclient.leases(5).
215
217 dhclient-script(8) has been written for Internet Systems Consortium by
218 Ted Lemon in cooperation with Vixie Enterprises. To learn more about
219 Internet Systems Consortium, see http://www.isc.org. To learn more
220 about Vixie Enterprises, see http://www.vix.com.
221
222
223
224 dhclient-script(8)