xref: /freebsd/sbin/dhclient/dhclient-script.8 (revision 8a7df6c58d549bd2eaa5cad30b2ef93c3eca3c18)
1.\"	$OpenBSD: dhclient-script.8,v 1.2 2004/04/09 18:30:15 jmc Exp $
2.\"
3.\" Copyright (c) 1997 The Internet Software Consortium.
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\"
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of The Internet Software Consortium nor the names
16.\"    of its contributors may be used to endorse or promote products derived
17.\"    from this software without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
20.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23.\" DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
24.\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\" This software has been written for the Internet Software Consortium
34.\" by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
35.\" Enterprises.  To learn more about the Internet Software Consortium,
36.\" see ``http://www.isc.org/isc''.  To learn more about Vixie
37.\" Enterprises, see ``http://www.vix.com''.
38.\"
39.Dd October 5, 2026
40.Dt DHCLIENT-SCRIPT 8
41.Os
42.Sh NAME
43.Nm dhclient-script
44.Nd DHCP client network configuration script
45.Sh DESCRIPTION
46The DHCP client network configuration script is invoked from time to
47time by
48.Xr dhclient 8 .
49This script is used by the DHCP client to set each interface's initial
50configuration prior to requesting an address, to test the address once it
51has been offered, and to set the interface's final configuration once a
52lease has been acquired.
53If no lease is acquired, the script is used to test predefined leases, if
54any, and also called once if no valid lease can be identified.
55.Pp
56.\" No standard client script exists for some operating systems, even though
57.\" the actual client may work, so a pioneering user may well need to create
58.\" a new script or modify an existing one.
59In general, customizations specific to a particular computer should be done
60in the
61.Pa /etc/dhclient.conf
62file.
63.Sh OPERATION
64When
65.Xr dhclient 8
66needs to invoke the client configuration script, it sets up a number of
67environment variables and runs
68.Nm .
69In all cases,
70.Va $reason
71is set to the name of the reason why the script has been invoked.
72The following reasons are currently defined:
73.Li MEDIUM , PREINIT , ARPCHECK , ARPSEND , BOUND , RENEW , REBIND , REBOOT ,
74.Li EXPIRE , FAIL
75and
76.Li TIMEOUT .
77.Bl -tag -width ".Li ARPCHECK"
78.It Li MEDIUM
79The DHCP client is requesting that an interface's media type be set.
80The interface name is passed in
81.Va $interface ,
82and the media type is passed in
83.Va $medium .
84.It Li PREINIT
85The DHCP client is requesting that an interface be configured as
86required in order to send packets prior to receiving an actual address.
87.\" For clients which use the BSD socket library,
88This means configuring the interface with an IP address of 0.0.0.0
89and a broadcast address of 255.255.255.255.
90.\" For other clients, it may be possible to simply configure the interface up
91.\" without actually giving it an IP address at all.
92The interface name is passed in
93.Va $interface ,
94and the media type in
95.Va $medium .
96.Pp
97If an IP alias has been declared in
98.Xr dhclient.conf 5 ,
99its address will be passed in
100.Va $alias_ip_address ,
101and that IP alias should be deleted from the interface,
102along with any routes to it.
103.It Li ARPSEND
104The DHCP client is requesting that an address that has been offered to
105it be checked to see if somebody else is using it, by sending an ARP
106request for that address.
107It is not clear how to implement this, so no examples exist yet.
108The IP address to check is passed in
109.Va $new_ip_address ,
110and the interface name is passed in
111.Va $interface .
112.It Li ARPCHECK
113The DHCP client wants to know if a response to the ARP request sent
114using
115.Li ARPSEND
116has been received.
117If one has, the script should exit with a nonzero status, indicating that
118the offered address has already been requested and should be declined.
119The
120.Va $new_ip_address
121and
122.Va $interface
123variables are set as with
124.Li ARPSEND .
125.It Li BOUND
126The DHCP client has done an initial binding to a new address.
127The new IP address is passed in
128.Va $new_ip_address ,
129and the interface name is passed in
130.Va $interface .
131The media type is passed in
132.Va $medium .
133Any options acquired from the server are passed using the option name
134described in
135.Xr dhcp-options 5 ,
136except that dashes
137.Pq Ql -
138are replaced by underscores
139.Pq Ql _
140in order to make valid shell variables, and the variable names start with
141.Dq Li new_ .
142So for example, the new subnet mask would be passed in
143.Va $new_subnet_mask .
144.Pp
145As an exception, the captive portal API URL from DHCP option 114
146.Pq see Xr dhcp-options 5
147is passed as
148.Va $new_captive_portal_url .
149When such a URL is received, the script also writes it to
150.Pa /var/run/captive-portal. Ns Va $interface
151so that it can be discovered by other programs.
152The file is removed when the lease expires or is lost.
153.Pp
154When a binding has been completed, a lot of network parameters are
155likely to need to be set up.
156A new
157.Pa /etc/resolv.conf
158needs to be created, using the values of
159.Va $new_domain_name
160and
161.Va $new_domain_name_servers
162(which may list more than one server, separated by spaces).
163A default route should be set using
164.Va $new_routers ,
165and static routes may need to be set up using
166.Va $new_static_routes .
167.Pp
168If an IP alias has been declared, it must be set up here.
169The alias IP address will be written as
170.Va $alias_ip_address ,
171and other DHCP options that are set for the alias (e.g., subnet mask)
172will be passed in variables named as described previously except starting with
173.Dq Li $alias_
174instead of
175.Dq Li $new_ .
176Care should be taken that the alias IP address not be used if it is identical
177to the bound IP address
178.Pq Va $new_ip_address ,
179since the other alias parameters may be incorrect in this case.
180.It Li RENEW
181When a binding has been renewed, the script is called as in
182.Li BOUND ,
183except that in addition to all the variables starting with
184.Dq Li $new_ ,
185there is another set of variables starting with
186.Dq Li $old_ .
187Persistent settings that may have changed need to be deleted - for example,
188if a local route to the bound address is being configured, the old local
189route should be deleted.
190If the default route has changed, the old default route should be deleted.
191If the static routes have changed, the old ones should be deleted.
192Otherwise, processing can be done as with
193.Li BOUND .
194.It Li REBIND
195The DHCP client has rebound to a new DHCP server.
196This can be handled as with
197.Li RENEW ,
198except that if the IP address has changed,
199the ARP table should be cleared.
200.It Li REBOOT
201The DHCP client has successfully reacquired its old address after a reboot.
202This can be processed as with
203.Li BOUND .
204.It Li EXPIRE
205The DHCP client has failed to renew its lease or acquire a new one,
206and the lease has expired.
207The IP address must be relinquished, and all related parameters should be
208deleted, as in
209.Li RENEW
210and
211.Li REBIND .
212.It Li FAIL
213The DHCP client has been unable to contact any DHCP servers, and any
214leases that have been tested have not proved to be valid.
215The parameters from the last lease tested should be deconfigured.
216This can be handled in the same way as
217.Li EXPIRE .
218.It Li TIMEOUT
219The DHCP client has been unable to contact any DHCP servers.
220However, an old lease has been identified, and its parameters have
221been passed in as with
222.Li BOUND .
223The client configuration script should test these parameters and,
224if it has reason to believe they are valid, should exit with a value of zero.
225If not, it should exit with a nonzero value.
226.El
227.Pp
228Before taking action according to
229.Va $reason ,
230.Nm
231will check for the existence of
232.Pa /etc/dhclient-enter-hooks .
233If found, it will be sourced
234.Pq see Xr sh 1 .
235After taking action according to
236.Va $reason ,
237.Nm
238will check for the existence of
239.Pa /etc/dhclient-exit-hooks .
240If found, it will be sourced
241.Pq see Xr sh 1 .
242These hooks scripts can be used to dynamically modify the environment at
243appropriate times during the DHCP negotiations.
244For example, if the administrator wishes to disable alias IP numbers on
245the DHCP interface, they might want to put the following in
246.Pa /etc/dhclient-enter-hooks :
247.Bd -literal -offset indent
248[ ."$reason" = .PREINIT ] && ifconfig $interface 0.0.0.0
249.Ed
250.Pp
251The usual way to test a lease is to set up the network as with
252.Li REBIND
253(since this may be called to test more than one lease) and then ping
254the first router defined in
255.Va $routers .
256If a response is received, the lease must be valid for the network to
257which the interface is currently connected.
258It would be more complete to try to ping all of the routers listed in
259.Va $new_routers ,
260as well as those listed in
261.Va $new_static_routes ,
262but current scripts do not do this.
263.\" .Sh FILES
264.\" Each operating system should generally have its own script file,
265.\" although the script files for similar operating systems may be similar
266.\" or even identical.
267.\" The script files included in the Internet Software Consortium DHCP
268.\" distribution appear in the distribution tree under client/scripts,
269.\" and bear the names of the operating systems on which they are intended
270.\" to work.
271.Sh SEE ALSO
272.Xr sh 1 ,
273.Xr dhclient.conf 5 ,
274.Xr dhclient.leases 5 ,
275.Xr dhclient 8 ,
276.Xr dhcpd 8 ,
277.Xr dhcrelay 8
278.Sh AUTHORS
279.An -nosplit
280The original version of
281.Nm
282was written for the Internet Software Consortium by
283.An Ted Lemon Aq Mt mellon@fugue.com
284in cooperation with Vixie Enterprises.
285.Pp
286The
287.Ox
288implementation of
289.Nm
290was written by
291.An Kenneth R. Westerback Aq Mt krw@openbsd.org .
292.Sh BUGS
293If more than one interface is being used, there is no obvious way to
294avoid clashes between server-supplied configuration parameters - for
295example, the stock
296.Nm
297rewrites
298.Pa /etc/resolv.conf .
299If more than one interface is being configured,
300.Pa /etc/resolv.conf
301will be repeatedly initialized to the values provided by one server, and then
302the other.
303Assuming the information provided by both servers is valid, this should not
304cause any real problems, but it could be confusing.
305