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