Next Previous Contents

4. DHCP Server Setup

4.1 DHCP server for UNIX

There are several DHCP servers available for U*X-like OSes, both commercial and free. One of the more popular free DHCP servers is Paul Vixie/ISC DHCPd. Currently the latest version is 2.0 (suggested for most users) but 3.0 is in beta testing. You can get them from

ftp://ftp.isc.org/isc/dhcp/

RedHat distribution (version 5.2) includes a binary RPM with DHCP server. The RPM is called dhcp-2.0b1pl6-2.platform.rpm. To install it simply type

rpm -i dhcp-2.0b1pl6-2.i386.rpm

You can skip following section if you used this procedure.

After you download it you need to unpack it. After you do cd into the distribution directory and type:

./configure

It will take some time to configure the settings. After it is done type:

make

and

make install

4.2 Network Configuration.

When done with installation type ifconfig -a. You should see something like this:


eth0      Link encap:10Mbps Ethernet  HWaddr 00:C0:4F:D3:C4:62
          inet addr:183.217.19.43  Bcast:183.217.19.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2875542 errors:0 dropped:0 overruns:0
          TX packets:218647 errors:0 dropped:0 overruns:0
          Interrupt:11 Base address:0x210

If it doesn't say MULTICAST you should reconfigure your kernel and add multicast support. On most systems you will not need to do this.

Next step is to add 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:

route add -host 255.255.255.255 dev eth0

If you get a message

"255.255.255.255: Unknown host"

You should try adding the following entry to your /etc/hosts file:

255.255.255.255 all-ones

Then, try:

route add -host all-ones dev eth0

or

route add 255.255.255.0 dev eth0

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

4.3 Options for DHCPd

Now you need to configure DHCPd. In order to do this you will have to create or edit /etc/dhcpd.conf.

Most commonly what you want to do is assign IP addresses randomly. This can be done with settings as follows


default-lease-time 600;
max-lease-time 7200;
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 "mydomain.org";

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;
}

This will result in DHCP server giving a client an IP address from the range 192.168.1.10-192.168.1.100 or 192.168.1.150-192.168.1.200. It will lease an IP address for 600 seconds if the client doesn't ask for specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also "advise" the client that it should use 255.255.255.0 as its subnet mask, 192.168.1.255 as its broadcast address, 192.168.1.254 as the router/gateway and 192.168.1.1 and 192.168.1.2 as its DNS servers.

You can also assign specific IP addresses based on clients ethernet 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 address 08:00:2b:4c:59:23.

You can also mix and match e.g. you can have certain clients getting "static" IP addresses (e.g. servers) and others being alloted dynamic IPs (e.g. mobile users with laptops). There are a number of other options e.g. wins server addresses, time server etc., if you need any of those options please read the dhcpd.conf man page.

4.4 Starting the server

There is only one thing to do before starting the server. In most cases DHCP installation doesn't create a dhcp.leases files. This file is used by DHCPd to store information about current leases. It is in the plain text form so you can view it during the operation of DHCPd. To create dhcp.leases type

touch /etc/dhcp.leases

on the command line. This will create an empty file (file size = 0). You do not need to make any changes to it it should be empty. If you get a message saying that file exists simply ignore it and go to the next step.

You can now invoke the DHCP server. Simply type (or include in the bootup scripts)

/usr/sbin/dhcpd

If you want to verify that everything is working fine you should first turn on the debugging mode and put the server in foreground. You can do this by typing

/usr/sbin/dhcpd -d -f

Then boot up one of your clients and check out the console of your server. You will see a number of debugging messages coming up.


Next Previous Contents