xref: /freebsd/sbin/dhclient/dhclient-script.8 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
147c08596SBrooks Davis.\"	$OpenBSD: dhclient-script.8,v 1.2 2004/04/09 18:30:15 jmc Exp $
247c08596SBrooks Davis.\"
347c08596SBrooks Davis.\" Copyright (c) 1997 The Internet Software Consortium.
447c08596SBrooks Davis.\" All rights reserved.
547c08596SBrooks Davis.\"
647c08596SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
747c08596SBrooks Davis.\" modification, are permitted provided that the following conditions
847c08596SBrooks Davis.\" are met:
947c08596SBrooks Davis.\"
1047c08596SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
1147c08596SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
1247c08596SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
1347c08596SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
1447c08596SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
1547c08596SBrooks Davis.\" 3. Neither the name of The Internet Software Consortium nor the names
1647c08596SBrooks Davis.\"    of its contributors may be used to endorse or promote products derived
1747c08596SBrooks Davis.\"    from this software without specific prior written permission.
1847c08596SBrooks Davis.\"
1947c08596SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
2047c08596SBrooks Davis.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
2147c08596SBrooks Davis.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2247c08596SBrooks Davis.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2347c08596SBrooks Davis.\" DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
2447c08596SBrooks Davis.\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2547c08596SBrooks Davis.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2647c08596SBrooks Davis.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2747c08596SBrooks Davis.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2847c08596SBrooks Davis.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2947c08596SBrooks Davis.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3047c08596SBrooks Davis.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3147c08596SBrooks Davis.\" SUCH DAMAGE.
3247c08596SBrooks Davis.\"
3347c08596SBrooks Davis.\" This software has been written for the Internet Software Consortium
3447c08596SBrooks Davis.\" by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
3547c08596SBrooks Davis.\" Enterprises.  To learn more about the Internet Software Consortium,
3647c08596SBrooks Davis.\" see ``http://www.isc.org/isc''.  To learn more about Vixie
3747c08596SBrooks Davis.\" Enterprises, see ``http://www.vix.com''.
3847c08596SBrooks Davis.\"
3951724552SBrian Somers.Dd September 6, 2010
4047c08596SBrooks Davis.Dt DHCLIENT-SCRIPT 8
4147c08596SBrooks Davis.Os
4247c08596SBrooks Davis.Sh NAME
4347c08596SBrooks Davis.Nm dhclient-script
4447c08596SBrooks Davis.Nd DHCP client network configuration script
4547c08596SBrooks Davis.Sh DESCRIPTION
4647c08596SBrooks DavisThe DHCP client network configuration script is invoked from time to
4747c08596SBrooks Davistime by
4847c08596SBrooks Davis.Xr dhclient 8 .
4947c08596SBrooks DavisThis script is used by the DHCP client to set each interface's initial
5047c08596SBrooks Davisconfiguration prior to requesting an address, to test the address once it
5147c08596SBrooks Davishas been offered, and to set the interface's final configuration once a
5247c08596SBrooks Davislease has been acquired.
5347c08596SBrooks DavisIf no lease is acquired, the script is used to test predefined leases, if
5447c08596SBrooks Davisany, and also called once if no valid lease can be identified.
5547c08596SBrooks Davis.Pp
5647c08596SBrooks Davis.\" No standard client script exists for some operating systems, even though
5747c08596SBrooks Davis.\" the actual client may work, so a pioneering user may well need to create
5847c08596SBrooks Davis.\" a new script or modify an existing one.
5947c08596SBrooks DavisIn general, customizations specific to a particular computer should be done
6047c08596SBrooks Davisin the
6147c08596SBrooks Davis.Pa /etc/dhclient.conf
6247c08596SBrooks Davisfile.
6347c08596SBrooks Davis.Sh OPERATION
6447c08596SBrooks DavisWhen
6547c08596SBrooks Davis.Xr dhclient 8
6647c08596SBrooks Davisneeds to invoke the client configuration script, it sets up a number of
6747c08596SBrooks Davisenvironment variables and runs
689a7feaa1SRuslan Ermilov.Nm .
6947c08596SBrooks DavisIn all cases,
7047c08596SBrooks Davis.Va $reason
7147c08596SBrooks Davisis set to the name of the reason why the script has been invoked.
7247c08596SBrooks DavisThe following reasons are currently defined:
739a7feaa1SRuslan Ermilov.Li MEDIUM , PREINIT , ARPCHECK , ARPSEND , BOUND , RENEW , REBIND , REBOOT ,
749a7feaa1SRuslan Ermilov.Li EXPIRE , FAIL
759a7feaa1SRuslan Ermilovand
769a7feaa1SRuslan Ermilov.Li TIMEOUT .
779a7feaa1SRuslan Ermilov.Bl -tag -width ".Li ARPCHECK"
789a7feaa1SRuslan Ermilov.It Li MEDIUM
7947c08596SBrooks DavisThe DHCP client is requesting that an interface's media type be set.
8047c08596SBrooks DavisThe interface name is passed in
8147c08596SBrooks Davis.Va $interface ,
8247c08596SBrooks Davisand the media type is passed in
8347c08596SBrooks Davis.Va $medium .
849a7feaa1SRuslan Ermilov.It Li PREINIT
8547c08596SBrooks DavisThe DHCP client is requesting that an interface be configured as
8647c08596SBrooks Davisrequired in order to send packets prior to receiving an actual address.
8747c08596SBrooks Davis.\" For clients which use the BSD socket library,
8847c08596SBrooks DavisThis means configuring the interface with an IP address of 0.0.0.0
8947c08596SBrooks Davisand a broadcast address of 255.255.255.255.
9047c08596SBrooks Davis.\" For other clients, it may be possible to simply configure the interface up
9147c08596SBrooks Davis.\" without actually giving it an IP address at all.
9247c08596SBrooks DavisThe interface name is passed in
9347c08596SBrooks Davis.Va $interface ,
9447c08596SBrooks Davisand the media type in
9547c08596SBrooks Davis.Va $medium .
9647c08596SBrooks Davis.Pp
9747c08596SBrooks DavisIf an IP alias has been declared in
9847c08596SBrooks Davis.Xr dhclient.conf 5 ,
9947c08596SBrooks Davisits address will be passed in
10047c08596SBrooks Davis.Va $alias_ip_address ,
10147c08596SBrooks Davisand that IP alias should be deleted from the interface,
10247c08596SBrooks Davisalong with any routes to it.
1039a7feaa1SRuslan Ermilov.It Li ARPSEND
10447c08596SBrooks DavisThe DHCP client is requesting that an address that has been offered to
10547c08596SBrooks Davisit be checked to see if somebody else is using it, by sending an ARP
10647c08596SBrooks Davisrequest for that address.
1079a7feaa1SRuslan ErmilovIt is not clear how to implement this, so no examples exist yet.
10847c08596SBrooks DavisThe IP address to check is passed in
10947c08596SBrooks Davis.Va $new_ip_address ,
11047c08596SBrooks Davisand the interface name is passed in
11147c08596SBrooks Davis.Va $interface .
1129a7feaa1SRuslan Ermilov.It Li ARPCHECK
11347c08596SBrooks DavisThe DHCP client wants to know if a response to the ARP request sent
1149a7feaa1SRuslan Ermilovusing
1159a7feaa1SRuslan Ermilov.Li ARPSEND
1169a7feaa1SRuslan Ermilovhas been received.
11747c08596SBrooks DavisIf one has, the script should exit with a nonzero status, indicating that
11847c08596SBrooks Davisthe offered address has already been requested and should be declined.
1199a7feaa1SRuslan ErmilovThe
12047c08596SBrooks Davis.Va $new_ip_address
12147c08596SBrooks Davisand
12247c08596SBrooks Davis.Va $interface
1239a7feaa1SRuslan Ermilovvariables are set as with
1249a7feaa1SRuslan Ermilov.Li ARPSEND .
1259a7feaa1SRuslan Ermilov.It Li BOUND
12647c08596SBrooks DavisThe DHCP client has done an initial binding to a new address.
12747c08596SBrooks DavisThe new IP address is passed in
12847c08596SBrooks Davis.Va $new_ip_address ,
12947c08596SBrooks Davisand the interface name is passed in
13047c08596SBrooks Davis.Va $interface .
13147c08596SBrooks DavisThe media type is passed in
13247c08596SBrooks Davis.Va $medium .
13347c08596SBrooks DavisAny options acquired from the server are passed using the option name
13447c08596SBrooks Davisdescribed in
13547c08596SBrooks Davis.Xr dhcp-options 5 ,
13647c08596SBrooks Davisexcept that dashes
1379a7feaa1SRuslan Ermilov.Pq Ql -
13847c08596SBrooks Davisare replaced by underscores
1399a7feaa1SRuslan Ermilov.Pq Ql _
1409a7feaa1SRuslan Ermilovin order to make valid shell variables, and the variable names start with
1419a7feaa1SRuslan Ermilov.Dq Li new_ .
14247c08596SBrooks DavisSo for example, the new subnet mask would be passed in
14347c08596SBrooks Davis.Va $new_subnet_mask .
14447c08596SBrooks Davis.Pp
14547c08596SBrooks DavisWhen a binding has been completed, a lot of network parameters are
14647c08596SBrooks Davislikely to need to be set up.
14747c08596SBrooks DavisA new
14847c08596SBrooks Davis.Pa /etc/resolv.conf
14947c08596SBrooks Davisneeds to be created, using the values of
15047c08596SBrooks Davis.Va $new_domain_name
15147c08596SBrooks Davisand
15247c08596SBrooks Davis.Va $new_domain_name_servers
15347c08596SBrooks Davis(which may list more than one server, separated by spaces).
15447c08596SBrooks DavisA default route should be set using
15547c08596SBrooks Davis.Va $new_routers ,
15647c08596SBrooks Davisand static routes may need to be set up using
15747c08596SBrooks Davis.Va $new_static_routes .
15847c08596SBrooks Davis.Pp
15947c08596SBrooks DavisIf an IP alias has been declared, it must be set up here.
16047c08596SBrooks DavisThe alias IP address will be written as
16147c08596SBrooks Davis.Va $alias_ip_address ,
16247c08596SBrooks Davisand other DHCP options that are set for the alias (e.g., subnet mask)
16347c08596SBrooks Daviswill be passed in variables named as described previously except starting with
1649a7feaa1SRuslan Ermilov.Dq Li $alias_
1659a7feaa1SRuslan Ermilovinstead of
1669a7feaa1SRuslan Ermilov.Dq Li $new_ .
16747c08596SBrooks DavisCare should be taken that the alias IP address not be used if it is identical
16847c08596SBrooks Davisto the bound IP address
16947c08596SBrooks Davis.Pq Va $new_ip_address ,
17047c08596SBrooks Davissince the other alias parameters may be incorrect in this case.
1719a7feaa1SRuslan Ermilov.It Li RENEW
1729a7feaa1SRuslan ErmilovWhen a binding has been renewed, the script is called as in
1739a7feaa1SRuslan Ermilov.Li BOUND ,
1749a7feaa1SRuslan Ermilovexcept that in addition to all the variables starting with
1759a7feaa1SRuslan Ermilov.Dq Li $new_ ,
1769a7feaa1SRuslan Ermilovthere is another set of variables starting with
1779a7feaa1SRuslan Ermilov.Dq Li $old_ .
1789a7feaa1SRuslan ErmilovPersistent settings that may have changed need to be deleted - for example,
17947c08596SBrooks Davisif a local route to the bound address is being configured, the old local
18047c08596SBrooks Davisroute should be deleted.
18147c08596SBrooks DavisIf the default route has changed, the old default route should be deleted.
18247c08596SBrooks DavisIf the static routes have changed, the old ones should be deleted.
1839a7feaa1SRuslan ErmilovOtherwise, processing can be done as with
1849a7feaa1SRuslan Ermilov.Li BOUND .
1859a7feaa1SRuslan Ermilov.It Li REBIND
18647c08596SBrooks DavisThe DHCP client has rebound to a new DHCP server.
1879a7feaa1SRuslan ErmilovThis can be handled as with
1889a7feaa1SRuslan Ermilov.Li RENEW ,
1899a7feaa1SRuslan Ermilovexcept that if the IP address has changed,
19047c08596SBrooks Davisthe ARP table should be cleared.
1919a7feaa1SRuslan Ermilov.It Li REBOOT
19247c08596SBrooks DavisThe DHCP client has successfully reacquired its old address after a reboot.
1939a7feaa1SRuslan ErmilovThis can be processed as with
1949a7feaa1SRuslan Ermilov.Li BOUND .
1959a7feaa1SRuslan Ermilov.It Li EXPIRE
19647c08596SBrooks DavisThe DHCP client has failed to renew its lease or acquire a new one,
19747c08596SBrooks Davisand the lease has expired.
19847c08596SBrooks DavisThe IP address must be relinquished, and all related parameters should be
1999a7feaa1SRuslan Ermilovdeleted, as in
2009a7feaa1SRuslan Ermilov.Li RENEW
2019a7feaa1SRuslan Ermilovand
2029a7feaa1SRuslan Ermilov.Li REBIND .
2039a7feaa1SRuslan Ermilov.It Li FAIL
20447c08596SBrooks DavisThe DHCP client has been unable to contact any DHCP servers, and any
20547c08596SBrooks Davisleases that have been tested have not proved to be valid.
20647c08596SBrooks DavisThe parameters from the last lease tested should be deconfigured.
2079a7feaa1SRuslan ErmilovThis can be handled in the same way as
2089a7feaa1SRuslan Ermilov.Li EXPIRE .
2099a7feaa1SRuslan Ermilov.It Li TIMEOUT
21047c08596SBrooks DavisThe DHCP client has been unable to contact any DHCP servers.
21147c08596SBrooks DavisHowever, an old lease has been identified, and its parameters have
2129a7feaa1SRuslan Ermilovbeen passed in as with
2139a7feaa1SRuslan Ermilov.Li BOUND .
21447c08596SBrooks DavisThe client configuration script should test these parameters and,
21547c08596SBrooks Davisif it has reason to believe they are valid, should exit with a value of zero.
21647c08596SBrooks DavisIf not, it should exit with a nonzero value.
21747c08596SBrooks Davis.El
21847c08596SBrooks Davis.Pp
21951724552SBrian SomersBefore taking action according to
22051724552SBrian Somers.Va $reason ,
22151724552SBrian Somers.Nm
22251724552SBrian Somerswill check for the existence of
22351724552SBrian Somers.Pa /etc/dhclient-enter-hooks .
22451724552SBrian SomersIf found, it will be sourced
22551724552SBrian Somers.Pq see Xr sh 1 .
22651724552SBrian SomersAfter taking action according to
22751724552SBrian Somers.Va $reason ,
22851724552SBrian Somers.Nm
22951724552SBrian Somerswill check for the existence of
23051724552SBrian Somers.Pa /etc/dhclient-exit-hooks .
23151724552SBrian SomersIf found, it will be sourced
23251724552SBrian Somers.Pq see Xr sh 1 .
2334b85a12fSUlrich SpörleinThese hooks scripts can be used to dynamically modify the environment at
23451724552SBrian Somersappropriate times during the DHCP negotiations.
23551724552SBrian SomersFor example, if the administrator wishes to disable alias IP numbers on
23651724552SBrian Somersthe DHCP interface, they might want to put the following in
23751724552SBrian Somers.Pa /etc/dhclient-enter-hooks :
23851724552SBrian Somers.Bd -literal -offset indent
23951724552SBrian Somers[ ."$reason" = .PREINIT ] && ifconfig $interface 0.0.0.0
24051724552SBrian Somers.Ed
24151724552SBrian Somers.Pp
2429a7feaa1SRuslan ErmilovThe usual way to test a lease is to set up the network as with
2439a7feaa1SRuslan Ermilov.Li REBIND
24447c08596SBrooks Davis(since this may be called to test more than one lease) and then ping
24547c08596SBrooks Davisthe first router defined in
24647c08596SBrooks Davis.Va $routers .
24747c08596SBrooks DavisIf a response is received, the lease must be valid for the network to
24847c08596SBrooks Daviswhich the interface is currently connected.
24947c08596SBrooks DavisIt would be more complete to try to ping all of the routers listed in
25047c08596SBrooks Davis.Va $new_routers ,
25147c08596SBrooks Davisas well as those listed in
25247c08596SBrooks Davis.Va $new_static_routes ,
25347c08596SBrooks Davisbut current scripts do not do this.
25447c08596SBrooks Davis.\" .Sh FILES
25547c08596SBrooks Davis.\" Each operating system should generally have its own script file,
25647c08596SBrooks Davis.\" although the script files for similar operating systems may be similar
25747c08596SBrooks Davis.\" or even identical.
25847c08596SBrooks Davis.\" The script files included in the Internet Software Consortium DHCP
25947c08596SBrooks Davis.\" distribution appear in the distribution tree under client/scripts,
26047c08596SBrooks Davis.\" and bear the names of the operating systems on which they are intended
26147c08596SBrooks Davis.\" to work.
26247c08596SBrooks Davis.Sh SEE ALSO
26351724552SBrian Somers.Xr sh 1 ,
26447c08596SBrooks Davis.Xr dhclient.conf 5 ,
26547c08596SBrooks Davis.Xr dhclient.leases 5 ,
26647c08596SBrooks Davis.Xr dhclient 8 ,
26747c08596SBrooks Davis.Xr dhcpd 8 ,
26847c08596SBrooks Davis.Xr dhcrelay 8
26947c08596SBrooks Davis.Sh AUTHORS
2709a7feaa1SRuslan Ermilov.An -nosplit
27147c08596SBrooks DavisThe original version of
27247c08596SBrooks Davis.Nm
27347c08596SBrooks Daviswas written for the Internet Software Consortium by
274*bd0891ceSBaptiste Daroussin.An Ted Lemon Aq Mt mellon@fugue.com
27547c08596SBrooks Davisin cooperation with Vixie Enterprises.
27647c08596SBrooks Davis.Pp
27747c08596SBrooks DavisThe
27847c08596SBrooks Davis.Ox
27947c08596SBrooks Davisimplementation of
28047c08596SBrooks Davis.Nm
28147c08596SBrooks Daviswas written by
282*bd0891ceSBaptiste Daroussin.An Kenneth R. Westerback Aq Mt krw@openbsd.org .
28347c08596SBrooks Davis.Sh BUGS
2849a7feaa1SRuslan ErmilovIf more than one interface is being used, there is no obvious way to
2859a7feaa1SRuslan Ermilovavoid clashes between server-supplied configuration parameters - for
2869a7feaa1SRuslan Ermilovexample, the stock
2879a7feaa1SRuslan Ermilov.Nm
2889a7feaa1SRuslan Ermilovrewrites
28947c08596SBrooks Davis.Pa /etc/resolv.conf .
29047c08596SBrooks DavisIf more than one interface is being configured,
29147c08596SBrooks Davis.Pa /etc/resolv.conf
29247c08596SBrooks Daviswill be repeatedly initialized to the values provided by one server, and then
29347c08596SBrooks Davisthe other.
2949a7feaa1SRuslan ErmilovAssuming the information provided by both servers is valid, this should not
29547c08596SBrooks Daviscause any real problems, but it could be confusing.
296