Home|Cudeso|Linux|*NIX / BSD|Misc|
 

DHCPD

Contents

1. Introduction

2. Useful resources

3. Getting the package

4. Configuration

5. Starting and stopping





1. Introduction

A DHCP-server, or Dynamic Host Configuration Protocol Server allows hosts on a TCP/IP network to request and be assigned IP addresses, and also to discover information about the network to which they are attached. This gives you the advantage that you don't have to run around every client to change a specific setting and that it's very easy to attach a new host to the network.

2. Useful resources

The main website for the DHCP-server is at http://www.isc.org/products/DHCP/.

3. Getting the packages / Install

Before you can start installing the daemon, you should check the way your current kernel is compiled. At least CONFIG_PACKET and CONFIG_FILTER should be set to 'YES' before you can continue.

Allthough there are RPM-packages for every RedHat type, I prefer to install the DHCP-server from source. Installation is very clear and simple. Download the package, unzip it and compile it.
 tar zxvf dhcp-3.tar.gz
 cd dhcp-3

 ./configure
 make
 make install

4. Configuration

Like every daemon, there's a configuration file that holds all the directives. This is how mine looks like
 deny client-updates;
 ddns-update-style interim;

 subnet 192.168.0.0 netmask 255.255.255.0 {
    range dynamic-bootp 192.168.0.190 192.168.0.240;

    option routers 192.168.0.10;
    option subnet-mask 255.255.255.0;

    option nis-domain "mydomain.com";
    option domain-name "mydomain.com";
    option domain-name-servers 192.168.0.20;
    option netbios-name-servers 192.168.0.100;
    option ntp-servers 192.168.0.25;
    option smtp-server 192.168.0.35;

    default-lease-time 360000;
    max-lease-time 259200;
    }


 # Client-definitions

 host big-daddy {
    hardware ethernet 00:a0:d9:cb:94:8a;
    fixed-address 192.168.0.18;
    }
The first two lines instruct the DHCP server NOT to accept dynamic DNS-updates. This will only work with BIND and I'm not using BIND as a name-server (note : when you install DHCP-server from RPM you'll probably don't have this option because the RPM's are build from the version 2 sourcetree).

Next, I define the subnet for which I want to handout DHCP-leases. You can have several ranges in your config-file. With subnet I indicate the net and with netmask the corresponding netmask.

For my subnet I set that the dhcp-server is allowed to hand-out ip-addresses in the range 192.168.0.190 to 192.168.0.240. This is done with range dynamic-bootp. Next I include some options.
  option routers specifies my internet-gateway.
  option subnet-mask is the default netmask for my clients.
  option nis-domain my NIS-domain
  option domain-name the default domain-name if I use FQDN
  option domain-name-servers the name-servers for my network
  option netbios-name-servers the default WINS-server
  option ntp-servers my local timeserver
  option smtp-server the smtp-server (only 1 server)
The last section in my config file is the client-definition for one host. Allthough all hosts are defined with dynamic addresses, I'd like to be sure that one host always receives the same ip. This can be done with the host-section. You only need to specify the network-interface MAC-address with hardware and the ip-address with fixed-address.

Now, before you can start the DHCP-server you need to make one last file : the leases file. Issue this :
touch /etc/dhcpd.leases

5. Starting and stopping

According to the default RedHat style, you should create a decent start / stop initscript. You can copy/paste the text below or download my dhcpd-initscript. This is how my init-script looks like :
#!/bin/sh
 #
 # dhcpd This shell script takes care of starting and stopping
 # dhcpd.
 #
 # chkconfig: - 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

 LEASEFILE="/etc/dhcpd.leases"
 [ -f /usr/sbin/dhcpd ] || exit 0
 [ -f /etc/dhcpd.conf ] || exit 0
 [ -f $LEASEFILE ] || exit 0

 RETVAL=0
 prog="dhcpd"

 start() {
    # Start daemons.
    echo -n $"Starting $prog: "
    daemon /usr/sbin/dhcpd -lf $LEASEFILE eth0
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
    return $RETVAL
 }

 stop() {
    # Stop daemons.
    echo -n $"Shutting down $prog: "
    killproc dhcpd
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dhcpd
    return $RETVAL
 }

 # See how we were called.
 case "$1" in
   start)
    start
    ;;
   stop)
    stop
    ;;
   restart|reload)
    stop
    start
    RETVAL=$?
    ;;
   condrestart)
    if [ -f /var/lock/subsys/dhcpd ]; then
     stop
     start
     RETVAL=$?
    fi
    ;;
   status)
    status dhcpd
    RETVAL=$?
    ;;
   *)
    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
    exit 1
 esac

 exit $RETVAL

This is really about all there is with setting up a DHCP-server for your local-LAN.
Copyleft 2002-2007 - cudeso.bewebmaster@cudeso.betop