HOW TO MAKE A LINUX BOX A DHCP SERVER




What is DHCP?

DHCP is an acronym for Dynamic Host Configuration Protocol.  The creation of DHCP has made configuring the network on multiple hosts (running clients) extremely simple.  Instead of having to configure each host separately you can assign all of the commonly used parameters by the hosts using a DHCP server.

Each time the host boots up it will broadcast a packet to the network.  This packet is a call to any DHCP servers that are located on the same segment to configure the host.

DHCP is extremely useful in assigning items such as the IP address, Netmask, and gateway of each host.
 
 

Enable DHCP On A Host Computer
 

  1. First, open the console.
  2. Second, logon as the user root.
  3. Once you are logged in, type the following command:  linuxconf
  4. This will start running the linuxconf program.
  5. A menu box appears “main entry to LINUX configuration”
  6. Select Networking
  7. The “Network Configurator” menu appears
  8. Select Basic Host Information
  9. The “Host Basic Configuration Menu” appears
  10. Select Adaptor 1 tab
  11. Select Enable
  12. Select DHCP
  13. Click accept
  14. Click quit on “main entry to LINUX configuration” menu
  15. “A Status of the System Menu” appears
  16. Select Activate the Changes
DHCP Server Setup for LINUX
 


Type the following to make the DHCPD file work:
 

  1. gunzip dhcp-2.0pl5.tar.gz (or what ever file you downloaded)
  2. tar –xvf dhcp-2.0pl5.tar  (untars the file)
  3. cd dhcp-2.0pl5
  4. ./configure
  5. make
  6. make install
  7. ifconfig –a


NOTE:  If it does not say UP BROADCAST RUNNING MULTICAST you should reconfigure  your kernel and add multicast support.  On most systems you will not need to do this.

Edit your /etc/rc.d/rc.local to reflect an addition of a route for 255.255.255.255
 

Quoted from DHCPd README:
In order for dhcpd to work correctly with picky DHCP clients (e.g., Windows 95), it must be able to send packets with an IP destination address of 255.255.255.255. Unfortunately, Linux insists on changing 255.255.255.255 into the local subnet broadcast address (here, that's 192.5.5.223). This results in a DHCP protocol violation, and while many DHCP clients don't notice the problem, some (e.g., all Microsoft DHCP clients) do. Clients that have this problem will appear not to see DHCPOFFER messages from the server.
Type the following as root:


Route add –host 255.255.255.255 dev eth0

If the message appears:

255.255.255.255:  Unknown host
 
 

Try adding the following entry to your /etc/hosts file:

255.255.255.255 dhcp

Then, try:

Route add –host dhcp dev eth0

Eth0 is of course the name of the network device you are using.  If it differs change appropriately.
 

Options for DHCPD

Now you need to configure DHCPD. In order to do this you will have to create or edit /etc/dhcpd.conf. There is a graphical interface for DHCPD configuration under linuxconf. This makes configuring and managing DHCPD extremely simple.

If you want to configure it by hand follow instructions below. I suggest configuring it by hand at least once. It will help in the diagnostics that a GUI can't give you. Unfortunately Microsoft doesn't believe this.

The easiest thing to do is assign IP addresses randomly. Below is a sample configuration file that shows this type of setup.

Copy and paste the following to your screen and make the necessary changes so that you don’t have to retype the whole thing!

# Assigns IP addresses randomly
default-lease-time 1200;
max-lease-time 9200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name "Southernview.com";

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
range 192.168.1.150 192.168.1.200;
}
 

NOTE:  We did this in the training center and we had to change all of the dot ones (.1) to .100 because that is the IP address that is being used in there.  Also you might have to change your range to accommodate the IP addresses that you may be using when you are creating your DHCP server.

For example in the training center we changed the range from:  192.168.1.150 - 192.168.1.200 to 192.168.100.202  192.168.100.220.  That is what is meant to make the necessary changes. You can also delete one of the range lines unless you want two ranges.

After you have made the necessary changes, this script will allow  the DHCP server to assign the client an IP address from the provided range.

It will lease an IP address for 1200 seconds (which can be changed) if the client does not request a longer time frame.  Otherwise the maximum (allowed) lease the server will allow is 9200 seconds.  The server sends the following parameters to the client:
 

Use 255.255.255.0 as your subnet mask Use 192.168.1.255 as your broadcast address Use 192.168.1.254 as your default gateway USE 192.168.1.1 and 192.168.1.2 as your DNS servers.

If you specify a WINS server for your Windows clients you need to include the following option in the dhcpd.conf file.

Option netbios-name-servers 192.168.1.1;

You can also assign specific IP addresses based on clients Ethernet MAC address e.g.

host haagen {
     hardware ethernet 08:00:2b:4c:59:23;
     fixed-address 192.168.1.222;
}

This will assign IP address 192.168.1.222 to a client with Ethernet MAC address of 08:00:2b:4c:59:23.
 
 

Starting the Server
 

In most cases the DHCP installation does not create a dhcpd.leases file.  Therefore before you start the server you must type the following to create an empty file:

Touch /var/state/dhcp/dhcpd.leases
 

To start the DHCP server simply type (or include in the bootup scripts)

/usr/sbin/dhcpd

This will start dhcpd on eth0 device.  If you need to start it on another device simply supply it on the command line e.g.

/usr/sbin/dhcpd eth1

If you wish to test the configuration for any oddities you can start dhcpd with the debugging mode.  Typing the command below will allow you to see exactly what is going on with the server.

/usr/sbin/dhcpd –d –f

Boot up a client.  Take a look at the console of the server.  You will see a number of debugging messages come up.

You're done!
 
 

How to Get the IP Address from your new DHCP Server
 


NOTES:




HOME