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.\" 399a7feaa1SRuslan Ermilov.\" $FreeBSD$ 409a7feaa1SRuslan Ermilov.\" 41*51724552SBrian Somers.Dd September 6, 2010 4247c08596SBrooks Davis.Dt DHCLIENT-SCRIPT 8 4347c08596SBrooks Davis.Os 4447c08596SBrooks Davis.Sh NAME 4547c08596SBrooks Davis.Nm dhclient-script 4647c08596SBrooks Davis.Nd DHCP client network configuration script 4747c08596SBrooks Davis.Sh DESCRIPTION 4847c08596SBrooks DavisThe DHCP client network configuration script is invoked from time to 4947c08596SBrooks Davistime by 5047c08596SBrooks Davis.Xr dhclient 8 . 5147c08596SBrooks DavisThis script is used by the DHCP client to set each interface's initial 5247c08596SBrooks Davisconfiguration prior to requesting an address, to test the address once it 5347c08596SBrooks Davishas been offered, and to set the interface's final configuration once a 5447c08596SBrooks Davislease has been acquired. 5547c08596SBrooks DavisIf no lease is acquired, the script is used to test predefined leases, if 5647c08596SBrooks Davisany, and also called once if no valid lease can be identified. 5747c08596SBrooks Davis.Pp 5847c08596SBrooks Davis.\" No standard client script exists for some operating systems, even though 5947c08596SBrooks Davis.\" the actual client may work, so a pioneering user may well need to create 6047c08596SBrooks Davis.\" a new script or modify an existing one. 6147c08596SBrooks DavisIn general, customizations specific to a particular computer should be done 6247c08596SBrooks Davisin the 6347c08596SBrooks Davis.Pa /etc/dhclient.conf 6447c08596SBrooks Davisfile. 6547c08596SBrooks Davis.Sh OPERATION 6647c08596SBrooks DavisWhen 6747c08596SBrooks Davis.Xr dhclient 8 6847c08596SBrooks Davisneeds to invoke the client configuration script, it sets up a number of 6947c08596SBrooks Davisenvironment variables and runs 709a7feaa1SRuslan Ermilov.Nm . 7147c08596SBrooks DavisIn all cases, 7247c08596SBrooks Davis.Va $reason 7347c08596SBrooks Davisis set to the name of the reason why the script has been invoked. 7447c08596SBrooks DavisThe following reasons are currently defined: 759a7feaa1SRuslan Ermilov.Li MEDIUM , PREINIT , ARPCHECK , ARPSEND , BOUND , RENEW , REBIND , REBOOT , 769a7feaa1SRuslan Ermilov.Li EXPIRE , FAIL 779a7feaa1SRuslan Ermilovand 789a7feaa1SRuslan Ermilov.Li TIMEOUT . 799a7feaa1SRuslan Ermilov.Bl -tag -width ".Li ARPCHECK" 809a7feaa1SRuslan Ermilov.It Li MEDIUM 8147c08596SBrooks DavisThe DHCP client is requesting that an interface's media type be set. 8247c08596SBrooks DavisThe interface name is passed in 8347c08596SBrooks Davis.Va $interface , 8447c08596SBrooks Davisand the media type is passed in 8547c08596SBrooks Davis.Va $medium . 869a7feaa1SRuslan Ermilov.It Li PREINIT 8747c08596SBrooks DavisThe DHCP client is requesting that an interface be configured as 8847c08596SBrooks Davisrequired in order to send packets prior to receiving an actual address. 8947c08596SBrooks Davis.\" For clients which use the BSD socket library, 9047c08596SBrooks DavisThis means configuring the interface with an IP address of 0.0.0.0 9147c08596SBrooks Davisand a broadcast address of 255.255.255.255. 9247c08596SBrooks Davis.\" For other clients, it may be possible to simply configure the interface up 9347c08596SBrooks Davis.\" without actually giving it an IP address at all. 9447c08596SBrooks DavisThe interface name is passed in 9547c08596SBrooks Davis.Va $interface , 9647c08596SBrooks Davisand the media type in 9747c08596SBrooks Davis.Va $medium . 9847c08596SBrooks Davis.Pp 9947c08596SBrooks DavisIf an IP alias has been declared in 10047c08596SBrooks Davis.Xr dhclient.conf 5 , 10147c08596SBrooks Davisits address will be passed in 10247c08596SBrooks Davis.Va $alias_ip_address , 10347c08596SBrooks Davisand that IP alias should be deleted from the interface, 10447c08596SBrooks Davisalong with any routes to it. 1059a7feaa1SRuslan Ermilov.It Li ARPSEND 10647c08596SBrooks DavisThe DHCP client is requesting that an address that has been offered to 10747c08596SBrooks Davisit be checked to see if somebody else is using it, by sending an ARP 10847c08596SBrooks Davisrequest for that address. 1099a7feaa1SRuslan ErmilovIt is not clear how to implement this, so no examples exist yet. 11047c08596SBrooks DavisThe IP address to check is passed in 11147c08596SBrooks Davis.Va $new_ip_address , 11247c08596SBrooks Davisand the interface name is passed in 11347c08596SBrooks Davis.Va $interface . 1149a7feaa1SRuslan Ermilov.It Li ARPCHECK 11547c08596SBrooks DavisThe DHCP client wants to know if a response to the ARP request sent 1169a7feaa1SRuslan Ermilovusing 1179a7feaa1SRuslan Ermilov.Li ARPSEND 1189a7feaa1SRuslan Ermilovhas been received. 11947c08596SBrooks DavisIf one has, the script should exit with a nonzero status, indicating that 12047c08596SBrooks Davisthe offered address has already been requested and should be declined. 1219a7feaa1SRuslan ErmilovThe 12247c08596SBrooks Davis.Va $new_ip_address 12347c08596SBrooks Davisand 12447c08596SBrooks Davis.Va $interface 1259a7feaa1SRuslan Ermilovvariables are set as with 1269a7feaa1SRuslan Ermilov.Li ARPSEND . 1279a7feaa1SRuslan Ermilov.It Li BOUND 12847c08596SBrooks DavisThe DHCP client has done an initial binding to a new address. 12947c08596SBrooks DavisThe new IP address is passed in 13047c08596SBrooks Davis.Va $new_ip_address , 13147c08596SBrooks Davisand the interface name is passed in 13247c08596SBrooks Davis.Va $interface . 13347c08596SBrooks DavisThe media type is passed in 13447c08596SBrooks Davis.Va $medium . 13547c08596SBrooks DavisAny options acquired from the server are passed using the option name 13647c08596SBrooks Davisdescribed in 13747c08596SBrooks Davis.Xr dhcp-options 5 , 13847c08596SBrooks Davisexcept that dashes 1399a7feaa1SRuslan Ermilov.Pq Ql - 14047c08596SBrooks Davisare replaced by underscores 1419a7feaa1SRuslan Ermilov.Pq Ql _ 1429a7feaa1SRuslan Ermilovin order to make valid shell variables, and the variable names start with 1439a7feaa1SRuslan Ermilov.Dq Li new_ . 14447c08596SBrooks DavisSo for example, the new subnet mask would be passed in 14547c08596SBrooks Davis.Va $new_subnet_mask . 14647c08596SBrooks Davis.Pp 14747c08596SBrooks DavisWhen a binding has been completed, a lot of network parameters are 14847c08596SBrooks Davislikely to need to be set up. 14947c08596SBrooks DavisA new 15047c08596SBrooks Davis.Pa /etc/resolv.conf 15147c08596SBrooks Davisneeds to be created, using the values of 15247c08596SBrooks Davis.Va $new_domain_name 15347c08596SBrooks Davisand 15447c08596SBrooks Davis.Va $new_domain_name_servers 15547c08596SBrooks Davis(which may list more than one server, separated by spaces). 15647c08596SBrooks DavisA default route should be set using 15747c08596SBrooks Davis.Va $new_routers , 15847c08596SBrooks Davisand static routes may need to be set up using 15947c08596SBrooks Davis.Va $new_static_routes . 16047c08596SBrooks Davis.Pp 16147c08596SBrooks DavisIf an IP alias has been declared, it must be set up here. 16247c08596SBrooks DavisThe alias IP address will be written as 16347c08596SBrooks Davis.Va $alias_ip_address , 16447c08596SBrooks Davisand other DHCP options that are set for the alias (e.g., subnet mask) 16547c08596SBrooks Daviswill be passed in variables named as described previously except starting with 1669a7feaa1SRuslan Ermilov.Dq Li $alias_ 1679a7feaa1SRuslan Ermilovinstead of 1689a7feaa1SRuslan Ermilov.Dq Li $new_ . 16947c08596SBrooks DavisCare should be taken that the alias IP address not be used if it is identical 17047c08596SBrooks Davisto the bound IP address 17147c08596SBrooks Davis.Pq Va $new_ip_address , 17247c08596SBrooks Davissince the other alias parameters may be incorrect in this case. 1739a7feaa1SRuslan Ermilov.It Li RENEW 1749a7feaa1SRuslan ErmilovWhen a binding has been renewed, the script is called as in 1759a7feaa1SRuslan Ermilov.Li BOUND , 1769a7feaa1SRuslan Ermilovexcept that in addition to all the variables starting with 1779a7feaa1SRuslan Ermilov.Dq Li $new_ , 1789a7feaa1SRuslan Ermilovthere is another set of variables starting with 1799a7feaa1SRuslan Ermilov.Dq Li $old_ . 1809a7feaa1SRuslan ErmilovPersistent settings that may have changed need to be deleted - for example, 18147c08596SBrooks Davisif a local route to the bound address is being configured, the old local 18247c08596SBrooks Davisroute should be deleted. 18347c08596SBrooks DavisIf the default route has changed, the old default route should be deleted. 18447c08596SBrooks DavisIf the static routes have changed, the old ones should be deleted. 1859a7feaa1SRuslan ErmilovOtherwise, processing can be done as with 1869a7feaa1SRuslan Ermilov.Li BOUND . 1879a7feaa1SRuslan Ermilov.It Li REBIND 18847c08596SBrooks DavisThe DHCP client has rebound to a new DHCP server. 1899a7feaa1SRuslan ErmilovThis can be handled as with 1909a7feaa1SRuslan Ermilov.Li RENEW , 1919a7feaa1SRuslan Ermilovexcept that if the IP address has changed, 19247c08596SBrooks Davisthe ARP table should be cleared. 1939a7feaa1SRuslan Ermilov.It Li REBOOT 19447c08596SBrooks DavisThe DHCP client has successfully reacquired its old address after a reboot. 1959a7feaa1SRuslan ErmilovThis can be processed as with 1969a7feaa1SRuslan Ermilov.Li BOUND . 1979a7feaa1SRuslan Ermilov.It Li EXPIRE 19847c08596SBrooks DavisThe DHCP client has failed to renew its lease or acquire a new one, 19947c08596SBrooks Davisand the lease has expired. 20047c08596SBrooks DavisThe IP address must be relinquished, and all related parameters should be 2019a7feaa1SRuslan Ermilovdeleted, as in 2029a7feaa1SRuslan Ermilov.Li RENEW 2039a7feaa1SRuslan Ermilovand 2049a7feaa1SRuslan Ermilov.Li REBIND . 2059a7feaa1SRuslan Ermilov.It Li FAIL 20647c08596SBrooks DavisThe DHCP client has been unable to contact any DHCP servers, and any 20747c08596SBrooks Davisleases that have been tested have not proved to be valid. 20847c08596SBrooks DavisThe parameters from the last lease tested should be deconfigured. 2099a7feaa1SRuslan ErmilovThis can be handled in the same way as 2109a7feaa1SRuslan Ermilov.Li EXPIRE . 2119a7feaa1SRuslan Ermilov.It Li TIMEOUT 21247c08596SBrooks DavisThe DHCP client has been unable to contact any DHCP servers. 21347c08596SBrooks DavisHowever, an old lease has been identified, and its parameters have 2149a7feaa1SRuslan Ermilovbeen passed in as with 2159a7feaa1SRuslan Ermilov.Li BOUND . 21647c08596SBrooks DavisThe client configuration script should test these parameters and, 21747c08596SBrooks Davisif it has reason to believe they are valid, should exit with a value of zero. 21847c08596SBrooks DavisIf not, it should exit with a nonzero value. 21947c08596SBrooks Davis.El 22047c08596SBrooks Davis.Pp 221*51724552SBrian SomersBefore taking action according to 222*51724552SBrian Somers.Va $reason , 223*51724552SBrian Somers.Nm 224*51724552SBrian Somerswill check for the existence of 225*51724552SBrian Somers.Pa /etc/dhclient-enter-hooks . 226*51724552SBrian SomersIf found, it will be sourced 227*51724552SBrian Somers.Pq see Xr sh 1 . 228*51724552SBrian SomersAfter taking action according to 229*51724552SBrian Somers.Va $reason , 230*51724552SBrian Somers.Nm 231*51724552SBrian Somerswill check for the existence of 232*51724552SBrian Somers.Pa /etc/dhclient-exit-hooks . 233*51724552SBrian SomersIf found, it will be sourced 234*51724552SBrian Somers.Pq see Xr sh 1 . 235*51724552SBrian SomersThese hooks scripts can be used to dynamically modify the enviornment at 236*51724552SBrian Somersappropriate times during the DHCP negotiations. 237*51724552SBrian SomersFor example, if the administrator wishes to disable alias IP numbers on 238*51724552SBrian Somersthe DHCP interface, they might want to put the following in 239*51724552SBrian Somers.Pa /etc/dhclient-enter-hooks : 240*51724552SBrian Somers.Bd -literal -offset indent 241*51724552SBrian Somers[ ."$reason" = .PREINIT ] && ifconfig $interface 0.0.0.0 242*51724552SBrian Somers.Ed 243*51724552SBrian Somers.Pp 2449a7feaa1SRuslan ErmilovThe usual way to test a lease is to set up the network as with 2459a7feaa1SRuslan Ermilov.Li REBIND 24647c08596SBrooks Davis(since this may be called to test more than one lease) and then ping 24747c08596SBrooks Davisthe first router defined in 24847c08596SBrooks Davis.Va $routers . 24947c08596SBrooks DavisIf a response is received, the lease must be valid for the network to 25047c08596SBrooks Daviswhich the interface is currently connected. 25147c08596SBrooks DavisIt would be more complete to try to ping all of the routers listed in 25247c08596SBrooks Davis.Va $new_routers , 25347c08596SBrooks Davisas well as those listed in 25447c08596SBrooks Davis.Va $new_static_routes , 25547c08596SBrooks Davisbut current scripts do not do this. 25647c08596SBrooks Davis.\" .Sh FILES 25747c08596SBrooks Davis.\" Each operating system should generally have its own script file, 25847c08596SBrooks Davis.\" although the script files for similar operating systems may be similar 25947c08596SBrooks Davis.\" or even identical. 26047c08596SBrooks Davis.\" The script files included in the Internet Software Consortium DHCP 26147c08596SBrooks Davis.\" distribution appear in the distribution tree under client/scripts, 26247c08596SBrooks Davis.\" and bear the names of the operating systems on which they are intended 26347c08596SBrooks Davis.\" to work. 26447c08596SBrooks Davis.Sh SEE ALSO 265*51724552SBrian Somers.Xr sh 1 , 26647c08596SBrooks Davis.Xr dhclient.conf 5 , 26747c08596SBrooks Davis.Xr dhclient.leases 5 , 26847c08596SBrooks Davis.Xr dhclient 8 , 26947c08596SBrooks Davis.Xr dhcpd 8 , 27047c08596SBrooks Davis.Xr dhcrelay 8 27147c08596SBrooks Davis.Sh AUTHORS 2729a7feaa1SRuslan Ermilov.An -nosplit 27347c08596SBrooks DavisThe original version of 27447c08596SBrooks Davis.Nm 27547c08596SBrooks Daviswas written for the Internet Software Consortium by 27647c08596SBrooks Davis.An Ted Lemon Aq mellon@fugue.com 27747c08596SBrooks Davisin cooperation with Vixie Enterprises. 27847c08596SBrooks Davis.Pp 27947c08596SBrooks DavisThe 28047c08596SBrooks Davis.Ox 28147c08596SBrooks Davisimplementation of 28247c08596SBrooks Davis.Nm 28347c08596SBrooks Daviswas written by 28447c08596SBrooks Davis.An Kenneth R. Westerback Aq krw@openbsd.org . 28547c08596SBrooks Davis.Sh BUGS 2869a7feaa1SRuslan ErmilovIf more than one interface is being used, there is no obvious way to 2879a7feaa1SRuslan Ermilovavoid clashes between server-supplied configuration parameters - for 2889a7feaa1SRuslan Ermilovexample, the stock 2899a7feaa1SRuslan Ermilov.Nm 2909a7feaa1SRuslan Ermilovrewrites 29147c08596SBrooks Davis.Pa /etc/resolv.conf . 29247c08596SBrooks DavisIf more than one interface is being configured, 29347c08596SBrooks Davis.Pa /etc/resolv.conf 29447c08596SBrooks Daviswill be repeatedly initialized to the values provided by one server, and then 29547c08596SBrooks Davisthe other. 2969a7feaa1SRuslan ErmilovAssuming the information provided by both servers is valid, this should not 29747c08596SBrooks Daviscause any real problems, but it could be confusing. 298