|
> Using DHCP on Linux/*BSD : Client setup (cont.) <
Releasing a DHCP lease (stopping a DHCP client)
Normally, a dhcp client is not supposed to release the lease it is bound to when, for example, the machine is
shut down. However, if you want to make sure leases are freed when computers go off-line, or you simply want to release
an ip address, following examples will show you how :
When the lease is released, the client exits and the routing table is adjusted.
Clients with multiple network interfaces
If more than one network interface must be configured on a certain host, the DHCP client will setup a separate state
machine for each interface. These state machines operate independently from one another. As such, they can be
in a different state (INIT, BOUND , . . . ) at the same moment.
This works perfectly well, each interface will operate with it's own IP address. Problems however can arise
when we consider the DHCP options (ex: default gateway, DNS, . . . ). The ISC DHCP client (dhclient) does not
provide a way to figure out wich set of options to use. It simply configures the host with the options
most recently received. This means that the interface configured as last, will prevail.
There are some things about dhcp clients you can configure which might be very usefull in some cases :
- If you have a (home build)router or server running, being a dhcp client, hooked up to your ISP connection, and you registered it
with some of those cool free Dynamic DNS account providers - like Dyndns.org -
you are faced with the problem of updating your IP address for this account whenever your ISP decides to change
your IP address (unless of course you have a static address).
When using dhcpcd, you can then edit /etc/dhcpc/dhcpcd-ethX.exe. Don't worry about the .exe, it's not a Windoze executable. Instead, it's
a shell script which is called whenever your IP address changes. There will be a script for every Ethernet interface
available on your machine, resulting in dhcpcd-eth0.exe, dhcpcd-eth1.exe, . . . You can then edit the appropriate script
and invoke your Dynamic DNS account client - like ddclient -
to update your account with the new IP address.
- If you have a machine, being a dhcp client, running as router/firewall/NAT, hooked up to your ISP connection, you
have to restart your firewall rules whenever your (external) IP address changes.
When using dhcpcd, you can then edit /etc/dhcpc/dhcpcd-ethX.exe. Just edit the appropriate script
and it will restart your firewall script with the new external IP address. Next example will show you how :
#!/bin/sh
#--------------------------------------------------------------------------
# /etc/dhcpc/dhcpcd-eth1.exe
#--------------------------------------------------------------------------
# Restart firewall rules + update the DynDns server unless the IP address
# is a private address that may be used as a internal LAN address.
#--------------------------------------------------------------------------
case "$1" in
10.*) ;;
172.1[6-9].* | 172.2[0-9].* | 172.31.*) ;;
192.168.*) ;;
*)
/etc/rc.d/rc.firewall start
echo "new IP address : $1" | logger
echo "Firewall started by dhcpcd-eth1.exe, so our IP address changed" | logger
sleep 3
/usr/sbin/ddclient -daemon=0 -syslog -use=ip -ip=$1 >/dev/null 2>&1
;;
esac
exit
- If you have a laptop, you may arrive in places without any network available. Upon booting, you may then
notice that your dhcp client may take some time before deciding to give up, since it obviously can't find
any DHCP server. Fact is, dhcpcd uses a default timeout value of 60 seconds. If you do not intend to wait
that long, you can alter your network startup script and invoke dhcpcd with a more reasonable timeout value like
say 10 seconds. Example :
/sbin/dhcpcd -t 10 eth0
If you want to do the same for dhclient, you will have to edit /etc/dhclient.conf to add
a timeout option like this :
# $FreeBSD: src/etc/dhclient.conf,v 1.2.2.1 2001/12/14 11:44:31 rwatson Exp $
#
# This file is required by the ISC DHCP client.
# See ``man 5 dhclient.conf'' for details.
#
# In most cases an empty file is sufficient for most people as the
# defaults are usually fine.
#
interface "rl0" {
timeout 10;
}
|