Link Exchange Fast Counter

DHCP Server Step-by-Step

This page is a set of terse instructions for setting up a DHCP Server.  It is not an in-depth article, but will get you up and running in no time.

What Is It

DHCP (Dynamic Host Configuration Protocol) is a protocol where by IP addresses are automatically assigned by a server to clients.  This means that the DHCP server takes care of assigning IP addresses, so the other computers on the network don't have to manually assigned IP addresses.

Why Do I Want This

Setting up a DHCP server eliminates the need to manually setup the network settings for each new PC that connects to your network.  For example, if all your friends come over with the computers to play  network games every Saturday, they won't have to fuss with their network settings to get connected.

What You Need

I am using Redhat 6.0, so these instructions are heavily geared towards that setup:

A stock Redhat 6.0 kernel will have everything you need compiled in.  On my LAN I have two network interfaces:

  1. eth0 - connects to the Internet
  2. eth1 - connects to my LAN

Some of you may have more, so you have to be careful which interfaces you enable DHCP services for.  In my case, I would only want my DHCP server to answer to requests from eth1, I don't want to disturb eth0, which connects to my ISP.

Getting DHCP

First you must install the DHCP server software.  If you are using RedHat, grab:

You should be able to find this on your CD, if not try looking for it at http://ww.rpmfind.net or if you need to find the it fromthe DHCP homepage at http://www.isc.org/products/DHCP/.

Configuring /etc/dhcpd.conf

After you install DHCP (either by RPM or by source), you will need to create the configuration file /etc/dhcpd.conf.  Let's assume that your internal network IP addresses are 192.168.0.x, your configuration file should look a bit like this:

# /etc/dhcpd.conf
# DHCPD Configuration
default-lease-time 86400;       # one day
max-lease-time 86400;           # one day

subnet 192.168.0.0 netmask 255.255.255.0 {
        range 192.168.0.2 192.168.0.250;

        option subnet-mask 255.255.255.0;
        option broadcast-address 192.168.0.255;
        option routers 192.168.0.1;

	## The IP address of the name server 
	##
        option domain-name-servers 192.168.0.1;
        option domain-name "mydomain.com";

	## If you have Samba acting as a WINS server
	##
        option netbios-name-servers 192.168.0.1;
        option netbios-dd-server 192.168.0.1;
        option netbios-node-type 8;
        option netbios-scope "";
}

Note that I have Samba and DNS running on my Linux box as well, that is why I have the extra options to specify what they are.  If your settings are different:

Configuring /etc/rc.d/init.d/dhcpd

If you installed DHCP by the RPM in Redhat, you will have a startup script /etc/rc.d/init.d/dhcpd.  You have to change this file a little bit to work properly.  The lines in bold are what I changed from the default:

#!/bin/sh
#
# dhcpd         This shell script takes care of starting and stopping
#               dhcpd.
#
# chkconfig: 2345 65 35
# description: dhcpd provide access to Dynamic Host Control Protocol.

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/sbin/dhcpd ] || exit 0
[ -f /etc/dhcpd.conf ] || exit 0

# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting dhcpd: "
        /sbin/route add -host 255.255.255.255 dev eth1 2> /dev/null
        daemon /usr/sbin/dhcpd eth1
        echo
        touch /var/lock/subsys/dhcpd
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down dhcpd: "
        /sbin/route del -host 255.255.255.255 dev eth1 2> /dev/null
        killproc dhcpd
        echo
        rm -f /var/lock/subsys/dhcpd
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  status)
        status dhcpd
        ;;
  *)
        echo "Usage: dhcpd {start|stop|restart|status}"
        exit 1
esac

exit 0

I added the line /sbin/route add -host 255.255.255.255 dev eth1 2> /dev/null to the startup.  If you are interested in why you need this, read up more on the DHCP docs.  The other change was that I added eth1 to the end of the dhcpd command to tell it only to listen for requests on my eth1 interface.  Change this as necessary for your network.

Starting DHCP

Before you start DHCP for the first time, you must create an empty leases file:

# touch /etc/dhcpd.leases

If you are using the RPM, start it up by running:

# /etc/rc.d/init.d/dhcpd start

Otherwise, start it manually by:

route add -host 255.255.255.255 dev eth1 2> /dev/null
dhcpd eth1

That's it!  Now you just have to configure your other computers to use DHCP.  For example, in Windows, you have to tell it that the server dynamically assigns an IP address, and name server.

Tell Me More

Here are some resources that will give you more information: