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