Dynamic Address Assignment
Pages: 1, 2
Dynamic Host Configuration Protocol 'DHCP' (RFC-2131)
DHCP leverages off the success of BootP and extends it by defining mechanisms for IP address allocation with a wide range of configuration data. DHCP describes backward-compatability with BootP, ensuring that BootP clients can effectively make use of a DHCP server without reconfiguration. DHCP servers can make use of the BootP relay feature provided by many routers.
DHCP describes three types of IP address allocation:
- Dynamic Allocation
- A host requests an address and is assigned any of the currently unallocated addresses. The host may be assigned a different address with each request.
- Automatic Allocation
- When a host requests an address for the first time, an unallocated address is found and assigned. That address is then reserved for use by that host and with every subsequent request from that host the same address is assigned.
- Static Allocation
- This is the same as "automatic allocation" except that the address that is assigned has been specifically reserved by the network administrator for that host. The host still requests and receives its address automatically using DHCP, but everyone knows in advance what address it will get.
An important concept that DHCP introduces is the idea of "lease" time for an address. A DHCP client may request an address for a period of time, and the DHCP server guarantees not to reallocate the address to another host within that time. The client may, of course, make another request for an address at the expiration of the lease, and the DHCP server will attempt to reallocate the same address when this occurs.
The DHCP implementation most commonly found on Linux systems is that produced by the Internet Software Consortium. It will be available pre-packaged in just about all Linux distributions.
|
Also in Linux Network Administration: Exploring the /proc/net/ Directory |
DHCP is easily the most commonly used dynamic address assignment mechanism as just about every desktop machine supports it, and many ADSL and cable-modem providers also use it.
Configuring the DHCP daemon
Let's move on and start configuring. First, some assumptions:
- We have the ISC's DHCP daemon program installed on the host we wish to use as a DHCP server, and that host has a working network configuration.
- Our DHCP server host is directly attached to the same networks as the hosts we wish to manage addresses for. (A DHCP server can have multiple Ethernet cards and be attached to, and serve, multiple networks simultaneously.)
- In our network, we have two subnets with 24-bit prefixes:
192.168.1.0and192.168.2.0. In each, we will dynamically allocate addresses from the range.32-.254to hosts. The remainder of the addresses are reserved for use by application servers, routers, and other shared infrastructure. - Each network has a router port with address
.1on it. - All hosts will be assigned names from the
testnet.netdomain and there is a shared name server with address192.168.2.16. - We will offer leases of 10 minutes by default, but hosts may request leases of up to 2 hours if they wish.
The configuration file for the ISC DHCP daemon is named /etc/dhcpd.conf and contains two types of statements, parameter statements and declaration statements. The parameter statements supply values for a number of DHCP variables such as lease times, and data to supply to client hosts such as gateway addresses. Declaration statements are used to describe collections of hosts to manage and collections of parameter statements to supply to hosts. Parameter statements can appear outside declaration statements and are then considered global parameters, or they may appear within declaration statements and then apply only to the hosts described by that declaration. Parameter statements are terminated with the ; character and declarations are enclosed within the curly brace {} characters.
You can build quite sophisticated configurations, but in most cases a simple one is all that is required. A configuration to meet the requirements specified for our network described above might look something like:
# dhcpd.conf - configuration for simple network
# Our global default configurations
option domain-name "testnet.net";
option domain-name-servers 192.168.2.16;
option subnet-mask 255.255.255.0
default-lease-time 600;
max-lease-time 7200;
# On our .1 subnet we will dynamically allocate
# address to any host that requests one using
# either DHCP or BootP.
subnet 192.168.1.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.1.32 192.168.1.254;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
get-lease-hostnames true;
}
# On our .2 subnet we have a mixture of dynamically
# assigned addresses and a collection of hosts that
# should have fixed addresses.
subnet 192.168.2.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.2.32 192.168.2.254;
option broadcast-address 192.168.2.255;
option routers 192.168.2.1;
}
# Our fixed address hosts belong to a different
# name domain and should have names assigned to
# them in addition to addresses.
group {
option domain-name "apps.testnet.net";
use-host-decl-names on;
host guava {
hardware ethernet 08:00:00:1a:2b:3c;
fixed-address 192.168.2.16;
}
host nectarine {
hardware ethernet 08:00:00:3b:4f:fa;
fixed-address 192.168.2.17;
}
host banana {
hardware ethernet 08:00:02:01:55:cb;
fixed-address 192.168.2.18;
}
}
More advanced dynamic configuration
In our example we used only a small number of configurable parameters. If you're in a complex environment of mixed computer and operating system types, you will likely need more sophisticated configurations.
If you have any or many diskless workstations, you may need to build a somewhat more complex configuration. The following sample is what you might use if you had a collection of diskless X11 workstations. You can cluster the information that is common to all workstations together inside the group statement and then pass host-specific information in a host statement for each workstation. You can see that this sample passes a wider range of configuration data to the workstations including the addresses of time, font, display manager, printer, and NIS+ servers. Additionally the mango workstation is configured for IP routing and has a static route configured.
group {
# machine boot parameters
filename "/tftp/fruit.boot';
next-server guava.apps.testnet.net;
# application server parameters
option ntp-servers 192.168.1.32;
option x-display-manager 192.168.1.32, 192.168.2.32;
option font-servers 192.168.1.32, 192.168.2.32;
option lpr-servers 192.168.1.32;
option nisplus-domain testnet;
option nisplus-servers 192.168.1.32, 192.168.2.32;
# Workstation specific parameters
host mango {
hardware ethernet 08:00:02:30:02:ba;
fixed-address 192.168.2.19;
option ip-forwarding 1;
option static-routes 10.1.0.1 192.168.2.1;
}
host passionfruit {
hardware ethernet 08:00:a3:6c:0b:21;
fixed-address 192.168.2.20;
}
}
More information
More detailed configuration information is available from the dhcpd.conf, dhcp.leases and dhcp-options man pages, and from the Internet Software Consortium web site.
Terry Dawson is the author of a number of network-related HOWTO documents for the Linux Documentation Project, a co-author of the 2nd edition of O'Reilly's Linux Network Administrators Guide, and is an active participant in a number of other Linux projects.
Read more Linux Network Administration columns.
Return to the Linux DevCenter.