Originally Published: Tuesday, 21 November 2000 Author: Elmo Recio
Published to: enhance_articles_sysadmin/Sysadmin Page: 1/1 - [Printable]

DHCP Daemon Made Easy

Got friends coming over, and they all want to share your internet connection? Running low on IP addresses? DHCP might be just your bag. Sysadmin rogue Elmo Recio takes you on a trip through the wonderful world of DHCP.

   Page 1 of 1  

When my friends visited with their laptops, they plugged into the local area network and would have to muck about with their network settings. I got tired of reconfiguring everything from Solaris to Windows 98 when they came over, so I bit the bullet and installed the DHCP daemon. It was actually easier than I expected. The reader should have previous knowledge of networks, subnets, routers, syslog, and TCP/IP.

First Things First: Downloading

The first step is downloading and configuring the DHCP daemon. The particular DHCPD we will be using is the Internet Software Consortium's Daemon Version Two. The ISC's DHCPD homepage is http://www.isc.org/products/DHCP/dhcp-v2.html. The particular version we'll be using is DHCP 2.0 Patch Level 5 and can be downloaded from the following location: ftp://ftp.isc.org/isc/dhcp/dhcp-2.0pl5.tar.gz

This version is a well tested and compatible daemon which is included in many distributions. Furthermore, it's like getting the news straight from the horse's mouth, so-to-speak.


The next step is the installation, which is pretty much straight forward.

su root

gzip -d dhcp-2.0pl5.tar.gz
tar -xf dhcp-2.0pl5.tar
cd dhcp-2.0pl5
make && make install

You should not run into any compile problems on the more modern distributions like Caldera, Debian, SuSE. One thing to note is that if you are upgrading from a previous version of DHCPD there's a change in the location of the lease files. Nothing to worry about if you are reading this to install it for the first time.

What you should have now are a set of binaries the one that interests us is the dhcpd.


For the purposes of this demonstration we will assume that your LAN is set up so that it fully utilizes the 192.168 subnet. Furthermore, that the server which you are running the DHCP client has the IP of Still logged in as root, the first thing that you have to do is edit the /etc/dhcpd.conf file and setup your subnets.

Global Declarations

One of the first things that you ought to do (even if you only have one network card or modem in your machine) is to set the interface device.

server-identifier This tells the DHCP daemon which interface card to bind to. For example, on my LAN at home, I have the DHCP server running on the same machine as the router, which has a modem in it. On that system, then, there are two interface cards, the modem, and the NIC. This line is crucial because it tells the DHCP server to use the NIC card for servicing DHCP requests from clients.

It's also good practice to hand over a domain name to the client, as well as the ip addresses of the DNS Servers; there are several ways to do this:

option domain-name "thesmiths.net"
option domain-name-severs


option domain-name "thesmiths.net"
option domain-name-servers ns1.thesmiths.net ns2.thesmiths.net

It really does not matter to the client if you send over the hostname or the ip address of the nameserver. If it's done the second way there are some advantages. The DHCP server will look up and send the ip address translation of the nameserver's hostname to the client. This is advantageous in that if the host name of the nameserver has several ip addresses associated with it, all of those ip addresses will be sent to the DHCP client.

In other words, if ns1.thesmiths.net has, .11, .12, and 13, all of those ip addresses will be given to the client. This is much nicer than hardcoding the nameserver's ip address in your DHCP configuration file (especially in larger network installations) because it decreases the number of possible points of failure.

Subnet Declarations

Now let's declare our subnet. There are many ways to design the network topology. I am going to discuss the most common case in production enviornments: several subnets on one physical network. The discussion, however, is also applicable to those networks which have only one subnet on a physical network.

It is possible, and most often the case that one physical network is shared by multiple subnets. For example, there might be a Class B network which utilizes an 8-bit subnet mask. While there are less than 254 network appliances installed, there's no problem. However, if they expand their network beyond the 254 devices, they will need to implement a second 8-bit subnet on the same physical network.

To this end, we will alter the DHCP daemon configuration file with one subnet. However we will provide the structure in the configuration file to have multiple subnets on one physical network, should we need it later.

shared-network net-thesmihs-1 {
option subnet-mask;
default-lease-time 600;
max-lease-time 7200;
subnet netmask {
option broadcast-address;
option routers moz.thesmiths.net;
# additional subnet would go here

Your lease times can vary depending on your individual preference.

The first line states that we are declaring a shared physical network [arbitrarily] named net-thesmiths-1. Before we declare any other subnets, we put in some network wide parameters. First we declare the option called subnet mask and set it to

Then we declare the default lease time in seconds. I set it to 10 minutes, because I noticed that my laptop kept wanting to use its lease from my home network at work. The default lease time is about one day. It's pretty smart to specify a max lease time, because many clients like to grab as long a lease as possible on IP addresses. Not setting this could cause inefficient usage of IP addresses.

The next declaration is the subnet. Using the simplest case possible, we use the subnet (or network address under windows) and an optional netmask of The next is a range of IP addresses that are valid for this network. In this case, I am allocating through to be given up in the pool as possible IP addresses to clients.

The next declarations are options that are sent to the client. The DHCP daemon will send as the broadcast address to the client. It will also tell the client that the router (gateway) will be the hostname moz.thesmiths.net. [Once again, it's a good idea to use hostnames as much as possible so that if the IP changes, or for some reason you must use a different machine, you will only need to change one thing, the entry in the nameserver.]

Test Run

Before we continue, you should have a simple DHCP configuration file.

Go into the directory which contains the DHCP daemon; invoke the daemon in the following way:

./dhcpd -q -cf /etc/dhpcd.conf -lf /var/state/dhpcd.leases eth0
The command line syntax is easy:
don't print out the copyright message. When it's fully configured you will want to start it from your system's boot up sequence initialization files and will not want to see the copyright message.
-cf /etc/dhcpd.conf
Use the file /etc/dhcpd.conf as your configuration file. This is an optional command line argument. You do not have to use this command line option. It will automatically use the /etc/dhcpd.conf file. However, this is given in case you are upgrading your configuration file, and want to see if it works before moving it into the /etc directory. (man page recommends not to use this option in a "production" environment and always use /etc/dhcpd.conf so the cfg is in a "known" location. The same applies to the -lf. )
-lf /var/state/dhcpd.leases
Use the file /var/state/dhcpd.leases as your lease file. This is used to keep track of the leases given out to clients between system reboots or daemon restarts. By default, it uses /var/state/dhcpd.leases to store its leases, so you don't have to worry about issuing this command line option. Like the one for the configuration, you should use this if you are testing thed aemon, and you do not want to pollute your lease file.
Binds the daemon to the first ethernet device on your system. You can use multiple interfaces to bind to by itemizing them here, too. For example, if your DHCP server handles several physical networks, and as a result has several different interfaces, you would list them here: eth0 eth1 ethn . Now boot up another machine on your network and configure it to use DHCP.
Under Windows 95/98 you would do the following:

Start -> Settings -> Control Panel -> Network
Click on TCP/IP in the list box, then click on the properties button.
Click on the IP Address tab, then select the radio button labeled: Obtain IP Address automatically.
Reboot the computer.

Under UNIX, if it's not already installed, you will have to download the above package and run the client from ISC's DHCP package known as dhclient. Or you can download and run an alternate client known as dhcpcd.

DHCPd Notes

Ok, so if everything went smoothly, you will have had an ip address automagically assigned to your client machine. Here are some tips to help you with your DHCP server.

Static Hosts

If you have a particular machine on the network to which you would like to assign an IP address, it's very simple. Consider the following: You have a laptop whose hostname is GANNON, and you would like the IP address of the machine to always be

In the global section of your configuration file:

host gannon {

hardware ethernet 00:60:09:C5:9C:DB;
fixed-address gannon.thesmiths.net;

You want to tell the DHCP daemon that if it encounters a client whose hostname is gannon with the hardware ethernet address (aka: MAC address) of 00:60:09:C5:9C:DB assign it the IP address that resolves as gannon.thesmiths.net.

Note that the nameserver must have an entry for the hostname (gannon.thesmiths.net) to point to If you are not running a nameserver, you can place this translation in the server's /etc/hosts file. Otherwise, you can just type in in place of gannon.thesmiths.net. Also note that the IP address is now used. So it should not be in the pool of dynamic addresses to be distributed.

Other options

You can specify a plethora of options for sending to the client. Some of the more interesting ones are as follows (from dhcp-options(5) man page)

option ntp-servers; # Time server
option nntp-server;
option www-server;
option smtp-server;
option pop-server;
option netbios-name-servers; # WINS Server
option nis-servers; # NIS Domain Controller
option netbios-node-type [1,2,4,8]; # WINS Server Type (1=bcast, 2=WINS, 4=bcast then WINS, 8=WINS then bcast)

All together now

Putting it all together we now have a really nice DHCP daemon and LAN. Our configuration file (based on this article) should look like:

# The configuration file for the network.

server-identifier moz.thesmiths.net;
option domain-name "thesmiths.net";
option domain-name-severs;
# Some cool options
option ntp-servers ntp1.thesmiths.net;
option www-servers www.thesmiths.net;
option smtp-servers mail1.thesmiths.net mail2.thesmiths.net;
option nntp-servers news1.thesmiths.net news2.thesmiths.net;
option pop-servers mail1.thesmiths.net mail2.thesmiths.net;

# For our Windows/Sun clients
option netbios-name-servers; # WINS Server
option nis-servers; # NIS Domain Controller
option netbios-node-type 2; # WINS Server Type (1=bcast, 2=WINS, 4=bcast then WINS, 8=WINS then bcast)
shared-network net-thesmihs-1 {
option subnet-mask;
default-lease-time 600;
max-lease-time 7200;
subnet netmask {
# let's leave some room in the range for our special
# host at
option broadcast-address;
option routers;
# additional subnet would go here
host gannon {
hardware ethernet 00:60:09:C5:9C:DB;


   Page 1 of 1