6.6. DHCP Configuration

DHCP stands for dynamic host configuration protocol. It is very simple to configure and it is useful because, instead of having to configure each node in a network individually, this can be done in a centralised manner and administering it is therefore easier. The configuration of a client is very easy, as we only have to install one of the following packages: dhcp3-client (version 3, Internet Software Consortium), dhcpcd (Yoichi Hariguchi and Sergei Viznyuk), pump (Red Hat); we then add the word dhcp in the section corresponding to the interface that we wish to work under this dhcp client (e.g./etc/network/interfaces must have iface eth0 inet dhcp...).

Configuring the server requires more care, but it is not especially complicated. First, for the server to serve all the DHCP clients (including Windows), we must address some questions concerning the broadcast addresses. In order to do this, first the server must be able to send messages to the 255.255.255.255 address, which is not valid in GNU/Linux. In order to try this, execute:

route add -host 255.255.255.255 dev eth0

If the following message appears: 255.255.255.255: Unknown host, then the following entry must be added in /etc/hosts: 255.255.255.255 dhcp and try again:

route add -host dhcp dev eth0

The configuration of dhcpd can be carried out with the graphic interface of linuxconf (not advisable) or by editing /etc/dhcpd.conf. An example of this file is:

# Example of /etc/dhcpd.conf: 
default-lease-time 1200; 
max-lease-time 9200; 
option domain-name "remix.com"; 
deny unknown-clients; 
deny bootp; 
option broadcast-address 192.168.11.255; 
option routers 192.168.11.254; 
option domain-name-servers 192.168.11.1,192.168.168.11.2; 
subnet 192.168.11.0 netmask 255.255.255.0
{ not authoritative; 
          range 192.168.11.1 192.168.11.254
          host marte { 
                    hardware ethernet 00:00:95:C7:06:4C; 
                    fixed address 192.168.11.146; 
                    option host-name "marte";
                    }
          host saturno { 
                    hardware ethernet 00:00:95:C7:06:44; 
                    fixed address 192.168.11.147; 
                    option host-name "saturno";
              }
  }

This will allow the server to assign the address range from 192.168.11.1 to 192.168.11.254, as described for each node. If the corresponding host { ... } segment does not exist, they will be assigned randomly. The IPs are assigned for a minimum time of 1,200 seconds and a maximum of 9,200 (if these parameters do not exist, they will be assigned indefinitely).

Before executing the server, we must verify if the file /var/state/dhcp/dhcpd.leases exists (otherwise, it will have to be created with touch /var/state/dhcp/dhcpd.leases). To execute the server: /usr/sbin/dhcpd (or we can put it in the startup scripts). With /usr/sbin/dhcpd -d-f, we can see the activity in the server within the system's console. [Mou01, Rid00, KD00, Dra99]

It is important not to forget the not authoritative phrase, as, otherwise, this server may leave other dhcp servers that serve IP for other segments inactive.