oreilly.comSafari Books Online.Conferences.


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:

Creating Network Diagrams

Exploring the /proc/net/ Directory

Building High Performance Linux Routers

Traffic Shaping

What is a Network Administrator Anyway?

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: and In each, we will dynamically allocate addresses from the range .32-.254 to 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 .1 on it.
  • All hosts will be assigned names from the domain and there is a shared name server with address
  • 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 "";
option domain-name-servers;
option subnet-mask
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 netmask {
  range dynamic-bootp;
  option broadcast-address;
  option routers;
  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 netmask {
  range dynamic-bootp;
  option broadcast-address;
  option routers;

# 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 "";
	use-host-decl-names on;
	host guava {
		hardware ethernet 08:00:00:1a:2b:3c;
	host nectarine {
		hardware ethernet 08:00:00:3b:4f:fa;
	host banana {
		hardware ethernet 08:00:02:01:55:cb;

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';

  # application server parameters
  option ntp-servers;
  option x-display-manager,;
  option font-servers,;
  option lpr-servers;
  option nisplus-domain testnet;
  option nisplus-servers,;

  # Workstation specific parameters
  host mango {
    hardware ethernet 08:00:02:30:02:ba;
    option ip-forwarding 1;
    option static-routes;

  host passionfruit {
    hardware ethernet 08:00:a3:6c:0b:21;

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.

Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: