DHCLIENT-SCRIPT(8) | MidnightBSD System Manager's Manual | DHCLIENT-SCRIPT(8) |
dhclient-script
—
DHCP client network configuration script
The DHCP client network configuration script is invoked from time to time by dhclient(8). This script is used by the DHCP client to set each interface's initial configuration prior to requesting an address, to test the address once it has been offered, and to set the interface's final configuration once a lease has been acquired. If no lease is acquired, the script is used to test predefined leases, if any, and also called once if no valid lease can be identified.
In general, customizations specific to a particular computer should be done in the /etc/dhclient.conf file.
When
dhclient(8) needs to
invoke the client configuration script, it sets up a number of environment
variables and runs dhclient-script
. In all cases,
$reason is set to the name of the reason why the
script has been invoked. The following reasons are currently defined:
MEDIUM
, PREINIT
,
ARPCHECK
, ARPSEND
,
BOUND
, RENEW
,
REBIND
, REBOOT
,
EXPIRE
, FAIL
and
TIMEOUT
.
MEDIUM
PREINIT
If an IP alias has been declared in dhclient.conf(5), its address will be passed in $alias_ip_address, and that IP alias should be deleted from the interface, along with any routes to it.
ARPSEND
ARPCHECK
ARPSEND
has been received. If one has, the script
should exit with a nonzero status, indicating that the offered address has
already been requested and should be declined. The
$new_ip_address and $interface
variables are set as with ARPSEND
.BOUND
-
’) are
replaced by underscores (‘_
’) in
order to make valid shell variables, and the variable names start with
“new_
”. So for example, the new
subnet mask would be passed in $new_subnet_mask.
When a binding has been completed, a lot of network parameters are likely to need to be set up. A new /etc/resolv.conf needs to be created, using the values of $new_domain_name and $new_domain_name_servers (which may list more than one server, separated by spaces). A default route should be set using $new_routers, and static routes may need to be set up using $new_static_routes.
If an IP alias has been declared, it must be set up here. The
alias IP address will be written as
$alias_ip_address, and other DHCP options that are
set for the alias (e.g., subnet mask) will be passed in variables named
as described previously except starting with
“$alias_
” instead of
“$new_
”. Care should be taken that
the alias IP address not be used if it is identical to the bound IP
address ($new_ip_address), since the other alias
parameters may be incorrect in this case.
RENEW
BOUND
, except that in addition to all the
variables starting with “$new_
”,
there is another set of variables starting with
“$old_
”. Persistent settings that
may have changed need to be deleted - for example, if a local route to the
bound address is being configured, the old local route should be deleted.
If the default route has changed, the old default route should be deleted.
If the static routes have changed, the old ones should be deleted.
Otherwise, processing can be done as with
BOUND
.REBIND
RENEW
, except that if the IP address has
changed, the ARP table should be cleared.REBOOT
BOUND
.EXPIRE
RENEW
and REBIND
.FAIL
EXPIRE
.TIMEOUT
BOUND
. The client configuration script should
test these parameters and, if it has reason to believe they are valid,
should exit with a value of zero. If not, it should exit with a nonzero
value.Before taking action according to $reason,
dhclient-script
will check for the existence of
/etc/dhclient-enter-hooks. If found, it will be
sourced (see sh(1)). After
taking action according to $reason,
dhclient-script
will check for the existence of
/etc/dhclient-exit-hooks. If found, it will be
sourced (see sh(1)). These
hooks scripts can be used to dynamically modify the environment at
appropriate times during the DHCP negotiations. For example, if the
administrator wishes to disable alias IP numbers on the DHCP interface, they
might want to put the following in
/etc/dhclient-enter-hooks:
[ ."$reason" = .PREINIT ] && ifconfig $interface 0.0.0.0
The usual way to test a lease is to set up the network as with
REBIND
(since this may be called to test more than
one lease) and then ping the first router defined in
$routers. If a response is received, the lease must be
valid for the network to which the interface is currently connected. It
would be more complete to try to ping all of the routers listed in
$new_routers, as well as those listed in
$new_static_routes, but current scripts do not do
this.
sh(1), dhclient.conf(5), dhclient.leases(5), dhclient(8), dhcpd(8), dhcrelay(8)
The original version of dhclient-script
was written for the Internet Software Consortium by Ted
Lemon
<mellon@fugue.com> in
cooperation with Vixie Enterprises.
The OpenBSD implementation of
dhclient-script
was written by
Kenneth R. Westerback
<krw@openbsd.org>.
If more than one interface is being used, there is no obvious way
to avoid clashes between server-supplied configuration parameters - for
example, the stock dhclient-script
rewrites
/etc/resolv.conf. If more than one interface is
being configured, /etc/resolv.conf will be
repeatedly initialized to the values provided by one server, and then the
other. Assuming the information provided by both servers is valid, this
should not cause any real problems, but it could be confusing.
September 6, 2010 | midnightbsd-3.1 |