]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sbin/dhclient/dhclient-script.8
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sbin / dhclient / dhclient-script.8
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 .\" $FreeBSD$
40 .\"
41 .Dd September 6, 2010
42 .Dt DHCLIENT-SCRIPT 8
43 .Os
44 .Sh NAME
45 .Nm dhclient-script
46 .Nd DHCP client network configuration script
47 .Sh DESCRIPTION
48 The DHCP client network configuration script is invoked from time to
49 time by
50 .Xr dhclient 8 .
51 This script is used by the DHCP client to set each interface's initial
52 configuration prior to requesting an address, to test the address once it
53 has been offered, and to set the interface's final configuration once a
54 lease has been acquired.
55 If no lease is acquired, the script is used to test predefined leases, if
56 any, and also called once if no valid lease can be identified.
57 .Pp
58 .\" No standard client script exists for some operating systems, even though
59 .\" the actual client may work, so a pioneering user may well need to create
60 .\" a new script or modify an existing one.
61 In general, customizations specific to a particular computer should be done
62 in the
63 .Pa /etc/dhclient.conf
64 file.
65 .Sh OPERATION
66 When
67 .Xr dhclient 8
68 needs to invoke the client configuration script, it sets up a number of
69 environment variables and runs
70 .Nm .
71 In all cases,
72 .Va $reason
73 is set to the name of the reason why the script has been invoked.
74 The following reasons are currently defined:
75 .Li MEDIUM , PREINIT , ARPCHECK , ARPSEND , BOUND , RENEW , REBIND , REBOOT ,
76 .Li EXPIRE , FAIL
77 and
78 .Li TIMEOUT .
79 .Bl -tag -width ".Li ARPCHECK"
80 .It Li MEDIUM
81 The DHCP client is requesting that an interface's media type be set.
82 The interface name is passed in
83 .Va $interface ,
84 and the media type is passed in
85 .Va $medium .
86 .It Li PREINIT
87 The DHCP client is requesting that an interface be configured as
88 required in order to send packets prior to receiving an actual address.
89 .\" For clients which use the BSD socket library,
90 This means configuring the interface with an IP address of 0.0.0.0
91 and a broadcast address of 255.255.255.255.
92 .\" For other clients, it may be possible to simply configure the interface up
93 .\" without actually giving it an IP address at all.
94 The interface name is passed in
95 .Va $interface ,
96 and the media type in
97 .Va $medium .
98 .Pp
99 If an IP alias has been declared in
100 .Xr dhclient.conf 5 ,
101 its address will be passed in
102 .Va $alias_ip_address ,
103 and that IP alias should be deleted from the interface,
104 along with any routes to it.
105 .It Li ARPSEND
106 The DHCP client is requesting that an address that has been offered to
107 it be checked to see if somebody else is using it, by sending an ARP
108 request for that address.
109 It is not clear how to implement this, so no examples exist yet.
110 The IP address to check is passed in
111 .Va $new_ip_address ,
112 and the interface name is passed in
113 .Va $interface .
114 .It Li ARPCHECK
115 The DHCP client wants to know if a response to the ARP request sent
116 using
117 .Li ARPSEND
118 has been received.
119 If one has, the script should exit with a nonzero status, indicating that
120 the offered address has already been requested and should be declined.
121 The
122 .Va $new_ip_address
123 and
124 .Va $interface
125 variables are set as with
126 .Li ARPSEND .
127 .It Li BOUND
128 The DHCP client has done an initial binding to a new address.
129 The new IP address is passed in
130 .Va $new_ip_address ,
131 and the interface name is passed in
132 .Va $interface .
133 The media type is passed in
134 .Va $medium .
135 Any options acquired from the server are passed using the option name
136 described in
137 .Xr dhcp-options 5 ,
138 except that dashes
139 .Pq Ql -
140 are replaced by underscores
141 .Pq Ql _
142 in order to make valid shell variables, and the variable names start with
143 .Dq Li new_ .
144 So for example, the new subnet mask would be passed in
145 .Va $new_subnet_mask .
146 .Pp
147 When a binding has been completed, a lot of network parameters are
148 likely to need to be set up.
149 A new
150 .Pa /etc/resolv.conf
151 needs to be created, using the values of
152 .Va $new_domain_name
153 and
154 .Va $new_domain_name_servers
155 (which may list more than one server, separated by spaces).
156 A default route should be set using
157 .Va $new_routers ,
158 and static routes may need to be set up using
159 .Va $new_static_routes .
160 .Pp
161 If an IP alias has been declared, it must be set up here.
162 The alias IP address will be written as
163 .Va $alias_ip_address ,
164 and other DHCP options that are set for the alias (e.g., subnet mask)
165 will be passed in variables named as described previously except starting with
166 .Dq Li $alias_
167 instead of
168 .Dq Li $new_ .
169 Care should be taken that the alias IP address not be used if it is identical
170 to the bound IP address
171 .Pq Va $new_ip_address ,
172 since the other alias parameters may be incorrect in this case.
173 .It Li RENEW
174 When a binding has been renewed, the script is called as in
175 .Li BOUND ,
176 except that in addition to all the variables starting with
177 .Dq Li $new_ ,
178 there is another set of variables starting with
179 .Dq Li $old_ .
180 Persistent settings that may have changed need to be deleted - for example,
181 if a local route to the bound address is being configured, the old local
182 route should be deleted.
183 If the default route has changed, the old default route should be deleted.
184 If the static routes have changed, the old ones should be deleted.
185 Otherwise, processing can be done as with
186 .Li BOUND .
187 .It Li REBIND
188 The DHCP client has rebound to a new DHCP server.
189 This can be handled as with
190 .Li RENEW ,
191 except that if the IP address has changed,
192 the ARP table should be cleared.
193 .It Li REBOOT
194 The DHCP client has successfully reacquired its old address after a reboot.
195 This can be processed as with
196 .Li BOUND .
197 .It Li EXPIRE
198 The DHCP client has failed to renew its lease or acquire a new one,
199 and the lease has expired.
200 The IP address must be relinquished, and all related parameters should be
201 deleted, as in
202 .Li RENEW
203 and
204 .Li REBIND .
205 .It Li FAIL
206 The DHCP client has been unable to contact any DHCP servers, and any
207 leases that have been tested have not proved to be valid.
208 The parameters from the last lease tested should be deconfigured.
209 This can be handled in the same way as
210 .Li EXPIRE .
211 .It Li TIMEOUT
212 The DHCP client has been unable to contact any DHCP servers.
213 However, an old lease has been identified, and its parameters have
214 been passed in as with
215 .Li BOUND .
216 The client configuration script should test these parameters and,
217 if it has reason to believe they are valid, should exit with a value of zero.
218 If not, it should exit with a nonzero value.
219 .El
220 .Pp
221 Before taking action according to
222 .Va $reason ,
223 .Nm
224 will check for the existence of
225 .Pa /etc/dhclient-enter-hooks .
226 If found, it will be sourced
227 .Pq see Xr sh 1 .
228 After taking action according to
229 .Va $reason ,
230 .Nm
231 will check for the existence of
232 .Pa /etc/dhclient-exit-hooks .
233 If found, it will be sourced
234 .Pq see Xr sh 1 .
235 These hooks scripts can be used to dynamically modify the enviornment at
236 appropriate times during the DHCP negotiations.
237 For example, if the administrator wishes to disable alias IP numbers on
238 the DHCP interface, they might want to put the following in
239 .Pa /etc/dhclient-enter-hooks :
240 .Bd -literal -offset indent
241 [ ."$reason" = .PREINIT ] && ifconfig $interface 0.0.0.0
242 .Ed
243 .Pp
244 The usual way to test a lease is to set up the network as with
245 .Li REBIND
246 (since this may be called to test more than one lease) and then ping
247 the first router defined in
248 .Va $routers .
249 If a response is received, the lease must be valid for the network to
250 which the interface is currently connected.
251 It would be more complete to try to ping all of the routers listed in
252 .Va $new_routers ,
253 as well as those listed in
254 .Va $new_static_routes ,
255 but current scripts do not do this.
256 .\" .Sh FILES
257 .\" Each operating system should generally have its own script file,
258 .\" although the script files for similar operating systems may be similar
259 .\" or even identical.
260 .\" The script files included in the Internet Software Consortium DHCP
261 .\" distribution appear in the distribution tree under client/scripts,
262 .\" and bear the names of the operating systems on which they are intended
263 .\" to work.
264 .Sh SEE ALSO
265 .Xr sh 1 ,
266 .Xr dhclient.conf 5 ,
267 .Xr dhclient.leases 5 ,
268 .Xr dhclient 8 ,
269 .Xr dhcpd 8 ,
270 .Xr dhcrelay 8
271 .Sh AUTHORS
272 .An -nosplit
273 The original version of
274 .Nm
275 was written for the Internet Software Consortium by
276 .An Ted Lemon Aq mellon@fugue.com
277 in cooperation with Vixie Enterprises.
278 .Pp
279 The
280 .Ox
281 implementation of
282 .Nm
283 was written by
284 .An Kenneth R. Westerback Aq krw@openbsd.org .
285 .Sh BUGS
286 If more than one interface is being used, there is no obvious way to
287 avoid clashes between server-supplied configuration parameters - for
288 example, the stock
289 .Nm
290 rewrites
291 .Pa /etc/resolv.conf .
292 If more than one interface is being configured,
293 .Pa /etc/resolv.conf
294 will be repeatedly initialized to the values provided by one server, and then
295 the other.
296 Assuming the information provided by both servers is valid, this should not
297 cause any real problems, but it could be confusing.