DHCP Server
From Debian Clusters
This is the second page of a three-part tutorial on setting up DHCP. The full tutorial includes
- Handing out IPs: DHCP
- DHCP Server
- Troubleshooting DHCP
The DHCP server is responsible for handing IP addresses for all the machines with dynamic IPs on the internal network (which should be all of them, preferably).
Installation
On the machine to be the DHCP server, first,
apt-get install dhcp3-server
It should install successfully, then end with an error like this:
Starting DHCP server: dhcpd3 failed to start - check syslog for diagnostics. invoke-rc.d: initscript dhcp3-server, action "start" failed.
Checking out /var/log/syslog will yield the following:
eyrie:~# tail /var/log/syslog Mar 8 12:52:01 eyrie dhcpd: Wrote 0 leases to leases file. Mar 8 12:52:01 eyrie dhcpd: Mar 8 12:52:01 eyrie dhcpd: No subnet declaration for eth0 (192.168.10.203). Mar 8 12:52:01 eyrie dhcpd: ** Ignoring requests on eth0. If this is not what Mar 8 12:52:01 eyrie dhcpd: you want, please write a subnet declaration Mar 8 12:52:01 eyrie dhcpd: in your dhcpd.conf file for the network segment Mar 8 12:52:01 eyrie dhcpd: to which interface eth0 is attached. ** Mar 8 12:52:01 eyrie dhcpd: Mar 8 12:52:01 eyrie dhcpd: Mar 8 12:52:01 eyrie dhcpd: Not configured to listen on any interfaces!
In other words, the DHCP service won't start because it has not been configured to hand out IP addresses on any of the network interfaces. The file responsible for this is /etc/dhcp3/dhcpd.conf.
/etc/dhcp3/dhcpd.conf
This file has a lot of examples to look through, but that also adds a lot of kruft to the file. I'd recommend making a copy of this file (cp dhcpd.conf backup-dhcpd.conf) and then removing most of the example comments to make the file easier to read.
The first lines to add/change are right below the comment
# option definitions common to all supported networks...
The options specified here will take affect by default for all subnets below this line. (You might have multiple subnets if you're running multiple switches with different IP ranges on different ones. If you just have one switch, you'll probably just have one.) If you don't specify these options here, you'll want to specify these within the individual subnet declarations. Options include
-
option routersare the default gateways. You'll want the internal IP address of your firewall here. -
option domain-name-serversare the nameservers. You should put the IP address of your cluster's own nameserver (Name Service: DNS and BIND) as well as possibly the nameserver your firewall uses outside of the network. They should be comma separated if you specify multiple nameservers. -
default-lease-timeis the amount of time a DHCP lease (which includes the IP address of the machine requesting plus all the other stuff just specified above) should be given out if a specific time isn't requested. The value is in seconds by default. 14400, or four hours, is a typical value. -
max-lease-timeis just what it says - the maximum amount of time the DHCP server will issue a DHCP lease for.
Eyrie will be running the DHCP server for me on its internal interface. Here's the corresponding section on eyrie:
# option definitions common to all supported networks... option routers 192.168.1.254; option domain-name-servers 192.168.1.254, X.X.X.X; default-lease-time 14400; max-lease-time 14400;
Next the individual networks need to be declared. These begin with the IP address and netmask with any directives in { brackets }. The IP range and netmask the subnets are determine which interfaces the DHCP server will give service to. The declaration follows this syntax:
subnet <subnet IP> netmask <subnet mask> {
<any options>
}
The declaration for my internal network is shown below. There's also an example with DHCP Server for Three Subnets.
subnet 192.168.1.0 netmask 255.255.255.0 {
option domain-name "raptor.loc";
deny unknown-clients;
}
-
option domain-nameindicates that this network should be called "raptor.loc"; this will be important later on with Name Service: DNS and BIND -
deny unknown-clientsmeans that IPs and leases will not be handed out to computers not listed in this file; not just anyone should be plugging in and receiving an IP address from my DHCP server!
That of course leads to the next step: declaring the clients that the DHCP knows and should supply DHCP leases to. Each computer that should be issued a DHCP lease (IP address) needs to be listed. The interfaces listed in this file will be the only ones that the DHCP server responds to; any DHCP requests from other computers will be ignored. Further, because it's by interface (MAC address), if different interfaces need IP addresses, each MAC address for each machine needs to be specified individually. Here is a typical one:
host gyrfalcon.raptor.loc {
hardware ethernet 00:e0:81:75:94:30;
fixed-address 192.168.1.200;
option host-name "gyrfalcon";
}
The declaration begins with the host name of the computer with the domain name of this particular internal network appended to it. The MAC address is specified with hardware ethernet. Fixed-address is the IP address that will be given to gyrfalcon when it requests on. Option host-name specified what this particular client should be called. The client will later use this to set its own host name (preventing the host name from having to be set in multiple places). If you're setting up multiple networks for the cluster, again see the dhcp.conf for the DHCP Server for Three Subnets.
Restarting the DHCP Server
After adding information for all of the clients, the DHCP server should be ready to start. Do this with
/etc/init.d/dhcp3-server restart
Errors like the following indicate a syntax problem in /etc/dhcp3/dhcp.conf
eyrie:~# /etc/init.d/dhcp3-server restart dhcpd self-test failed. Please fix the config file. The error was: Internet Systems Consortium DHCP Server V3.0.4 Copyright 2004-2006 Internet Systems Consortium. All rights reserved. For info, please visit http://www.isc.org/sw/dhcp/ /etc/dhcp3/dhcpd.conf line 25: unexpected end of file ^ Configuration file errors encountered -- exiting
whereas a successful restart looks like this
eyrie:~# /etc/init.d/dhcp3-server restart Stopping DHCP server: dhcpd3. Starting DHCP server: dhcpd3.
You can make sure it's really running with
ps aux | grep dhcp
Then, double check for any errors with tail /var/log/syslog. While you're looking here, make sure that the DHCP server is only handing out leases on the proper interface. You want to have a message like this
Jul 2 16:32:39 eyrie dhcpd: No subnet declaration for eth0 (X.X.X.X). Jul 2 16:32:39 eyrie dhcpd: ** Ignoring requests on eth0. If this is not what Jul 2 16:32:39 eyrie dhcpd: you want, please write a subnet declaration Jul 2 16:32:39 eyrie dhcpd: in your dhcpd.conf file for the network segment Jul 2 16:32:39 eyrie dhcpd: to which interface eth0 is attached. **
This is a good thing, because you don't want to be handing out IP addresses to the outside network, just the internal network for the cluster.
Trouble?
For help with other errors than the ones listed here, see Troubleshooting DHCP.

