FreeUnix.Dyndns.Org Sat, 21 November 2009 - 10:54:52 CET
Home ·  AcpiTool ·  Howto ? ·  Links ·  Hardware ·  FTP Archive ·  Search ·  Contact ·  About
>  Using DHCP on Linux/*BSD : The ISC DHCP Server  <
Installation

Enough theory for now, time to install a DHCP server. Every Linux distribution and FreeBSD release are shipped with binary packages of a recent version of the ISC DHCP server. You can then simply install your vendor supplied package.
If, for whatever reason, you don't like binary packages, you can always obtain the source of the latest version at the ISC DHCP site and compile it yourself. The usual "./configure, make && make install" will do. After installation, if you did not alter the destination directory, you can find the server binary, dhcpd, in /usr/sbin.

On a Linux box, you must make sure your kernel has CONFIG_PACKET (Packet socket) and CONFIG_FILTER (Socket Filtering) enabled. If this is not the case, you can edit your linux kernel .config file directly: set CONFIG_FILTER=y and CONFIG_PACKET=y. Afterwards, build a new Linux kernel, and then install it in the usual way.

Configuration

To configure your server, you will have to create or edit the configuration file, /etc/dhcpd.conf. This is just a plain text file. When changes are made to this file, the server must be killed and restarted to ensure it uses the new configuration.
You will most likely want a DHCP server that simply hands out IP adressess, netmasks, gateways, what DNS server(s) to use, and maybe some other options. The following config file will do just that :

#--------------------------------
# /etc/dhcpd.conf              
# ISC DHCP daemon 3.0.1rc12    
#--------------------------------
# Last update: Mon, 07-05-2003 
# Author     : Al Bundy   
#--------------------------------
# default lease : 5 days (max=6)
#--------------------------------

server-identifier 192.168.1.2;
server-name "peggy.bundynet.org";

subnet 192.168.1.0 netmask 255.255.255.0 {
    default-lease-time 432000;               
    max-lease-time 518400;                   
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.1.255;
    option routers 192.168.1.1;
    option domain-name-servers 192.168.1.2, 192.168.1.3;
    option domain-name "bundynet.org";
    option time-servers 192.168.1.3;
    option netbios-name-servers 192.168.1.4; 
    range 192.168.1.10 192.168.1.100;}

This configuration will hand out IP addresses in the range 192.168.1.10 - 192.168.1.100. The default lease time is 5 days(=432000 seconds). It will also tell clients to use 192.168.1.1 as gateway and to use 192.168.1.2 and 192.168.1.3 as DNS servers. The server at 192.168.1.3 also serves as NTP server. Furthermore, Windows clients can use 192.168.1.4 for Netbios (WINS) resolving.
As usual, lines starting with # are regarded as comment. You will need at least 1 subnet declaration.

You may want some clients on your network to have static addresses. Instead of configuring the host with a static address, you can make it a DHCP client, and then let your server assign this host always the same address. This can be achieved by assigning an IP address to the MAC address of the client's interface. An example :

host stargate {
   hardware ethernet 00:90:4b:69:c2:eb;
   fixed-address 192.168.1.7;}
Starting the server

Before starting your server, you most likely will have to create another file, /var/state/dhcp/dhcpd.leases. This file will be used to store information about current leases. This file too is a plain text file. If it does not exist, or is not accessible by dhcpd, your server will refuse to start.
Information is added to the end of the file. To prevent the file from becoming too large, the server periodically recreates the file from it's internal database. To create the file (albeit empty), type this :

touch /var/state/dhcp/dhcpd.leases

To start your DHCP server, just type /usr/sbin/dhcpd. Now check your system log for following messages:

Feb  7 01:57:10 zeus dhcpd: Internet Software Consortium DHCP Server V3.0.1rc12
Feb  7 01:57:10 zeus dhcpd: Copyright 1995-2003 Internet Software Consortium.
Feb  7 01:57:10 zeus dhcpd: All rights reserved.
Feb  7 01:57:10 zeus dhcpd: For info, please visit http://www.isc.org/products/DHCP
Feb  7 01:57:10 zeus dhcpd: Wrote 26 leases to leases file.
Feb  7 01:57:10 zeus dhcpd: Listening on LPF/eth0/00:02:b4:45:ba:d8/192.168.1.0/24
Feb  7 01:57:10 zeus dhcpd: Sending on   LPF/eth0/00:02:b4:45:ba:d8/192.168.1.0/24
Feb  7 01:57:10 zeus dhcpd: Sending on   Socket/fallback/fallback-net

Instead of starting dhcpd manually after each reboot, you would of course adapt your server to start dhcpd automatically. On any decent Linux or FreeBSD, a script will already exist somewhere in /etc/rc.d/ that starts dhcpd. If there isn't one, or you want to write one yourself, the next example may help you :

#!/bin/sh
#
DHCPD=/usr/sbin/dhcpd

if [ ! -d /usr/sbin ]; then
  echo "The /usr file system is not mounted."
  exit 1
fi

if [ ! -f /etc/dhcpd.conf ]; then
  echo "Can not read the server config file (/etc/dhcpd.conf)."
  exit 1
fi

killproc() {
   pid=`/bin/ps ax | grep -w $1 | sed -e 's/^  *//' -e 's/ .*//'`
   echo "Stopping $1 now."
   [ "$pid" != "" ] && kill -15 $pid
   echo $pid
}

# Start/stop processes required for the ISC DHCP server
case "$1" in

  'start')
	  echo "Starting DHCPD"
	  $DHCPD
	  echo "Done."
		  ;;
  'stop')
	  echo "Stopping DHCPD"
	  killproc dhcpd
	  echo "Done."
	  ;;
  *)
	  echo "Usage: $0 [ start | stop ]"
	  ;;
esac

Now boot one of your dhcp clients and check if it gets a lease.

Previous Top Index Next