EnderUnix Software Development Team

Introduction

Tue Jan 2002

DHCP (Dynamic Host Configuration Protocol)

DHCP, the Dynamic Host Configuration Protocol, describes the means by which a system can connect to a network and obtain the necessary information for communication upon that network                 

In this article i will briefly explain howto setup DHCP Server and client on various Operating Systems, such as FreeBSD,OpenBSD,NetBSD and Linux. We will use the ISC (Internet Software Consortium) DHCP implementation.

You can get latest versions of this document from  http://www.enderunix.org/documents/eng/dhcp.html

Ismail YENIGUL
[email protected]
EnderUNIX SDT Team Member

DHCP Installation  
 

FreeBSD :
#cd /usr/ports/net/isc-dhcp2
#make install

OpenBSD and NetBSD :
You do not do anything. dhcp comes with the default installation.
Make sure that you have BPF support in your kernel on *BSD's.

 Linux:
You can install dhcp from Redhat and  Mandrake distribution CDs.

#rpm -ivh dhcpd-version.rpm dhclient-version.rpm

DHCP Configuration

We will set up the configuration file called "dhcpd.conf"  
The file path  is  /usr/local/etc/dhcpd.conf on FreeBSD and
/etc/dhcpd.conf  on OpenBSD & NetBSD & Linux 

--------------------- sample dhcpd.conf file-----------------------

# option definitions common to all supported networks...

options domain-name-servers 192.168.1.2 , ns2.enderunix.com ;
options domain-name "enderunix.net";
default-lease-time 6000;
max-lease-time 72000;

#options definations for one subnet

subnet 192.168.1.0 255.255.255.0  {

   range 192.168.1.20 192.168.1.200;
   options domain-name-servers 192.168.1.2 , ns2.enderunix.com ;
   options domain-name "enderunix.com";
   options routers  192.168.1.254 ;
   options broadcast-address 192.168.1.255
   default-lease-time 600;
    max-lease-time 7200;
   }

host freefall {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address  "192.168.1.10";
}

-------------------dhpcd.conf end-------------------------
Lets describe above parameters

subnet 192.168.1.0 255.255.255.0: the subnet and it's subnet mask  that dhcpd will serve

range 192.168.1.20 192.168.1.200; IP address range for clients
options domain-name-servers 192.168.1.2 , ns2.enderunix.com:defines domain server
options domain-name "enderunix.com" : defines domain name 
options routers  192.168.1.1 : defines default gateway for clients
options broadcast-address 192.168.1.255: defines broadcast for clients

default-lease-time TIME: TIME should be length in seconds that will be assigned to a lease; if the client requesting the lease does not ask for a specific expiration time 

max-lease-time TIME; Time should be the maximum length in seconds that will be assigned to a lease; if the client requesting the lease asks for a specific expiration time

host freefall  {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address 192.168.1.10;

you can assing static IP's to some clients. above we assigned 192.168.1.10  IP address to
machine whose MAC address is   08:00:07:26:c0:a5;

Note: As you see freefall's IP address is out of range!  and freefall's domain is enderunix.net not enderunix.com (because general domain name is enderunix.net)

Running DHCP
Before running dhcpd be sure dhat /var/db/dhcpd.leases file  exists. if not create it:

#touch  /var/db/dhcpd.leases 

dhcpd.leases contains information on leased IPs

to run dhcpd 
root# dhcpd  dhcp_ethernet_interface, as in:
root#dhcpd fxp0  (on FreeBSD).

when you make changes on dhcpd.conf file you must at kill and restart dhcpd daemon.
#kill -HUP dhcpd_pid does nothing!

Configuring Clients

FreeBSD: 
comment out following values in /etc/rc.conf file
#
hostname="freefall.enderunix.com" 
#ifconfig_fxp0="inet 192.168.1.60 netmask 255.255.255.0" 
#defaultrouter="200.2001.201.1"
and add following value
ifconfig_fxp0="DHCP"

Note: Be sure to replace fxp0 with the designation for the interface that you wish to dynamically configure

OpenBSD & NetBSD:

echo  dhcp >/etc/hostname.fxp0
Note: Be sure to replace fxp0 with the designation for the interface that you wish to dynamically configure

Linux:

on Redhat & Mandrake write

BOOTPROTO=dhcp
to  /etc/sysconfig/network-scripts/ifcfg-eth0   file

on All UNIX and UNIX like OS you can run dhcpclient manually to get an IP
#dhclient fxp0  (replace fxp0 with your ethernet interface name)

Windows:

Start->Settings -> Control Panel ->Network ->TCP/IP -> Obtain an IP address automatically 

 

DHCP  Server Startup Configuration
FreeBSD: 
create dhcp.sh and write it  
#####################
#!/bin/sh
/usr/local/sbin/dhcpd fxp0 -q

#####################
Note: replace fxp0 with your ethernet interface name
#cp  dhcp.sh /usr/local/etc/rc.d
#chmod 755 /usr/local/etc/rc.d/dhcpd.sh

OpenBSD & NetBSD :

add following value to /etc/rc.conf 
dhcpd_flags="YES"

Linux:

add following value to /etc/rc.d/rc.local 
/usr/sbin/dhcpd eth0 -q
Note: replace eth0 with your ethernet interface name

Resources:

man dhcpd
man dhcpd.conf
FreeBSD Handbook ( http://freebsd.enderunix.org)