Configuring a DHCP Server for Linux

A target board uses the Dynamic Host Configuration Protocol (DHCP) to obtain its network configuration from an IA-32 host system. DHCP software serves much the same purpose as the older BOOTP software, and includes the BOOTP functionality as a subset.

Using DHCP requires that your host system be configured as a DHCP server. On most modern Linux systems, DHCP is installed as part of a network server-capable installation. This section explains how to configure your IA-32 Linux host to provide DHCP information for your target board.

Do not confuse the DHCP server daemon, dhcpd, with the DHCP client daemon, dhcpcd. In this document, you are concerned with configuring the server daemon. No changes are necessary for the client daemon.

Note

If a DHCP server is not available on your Linux distribution or installed system, you can download a binary version for most RPM-based Linux distributions by searching for the string dhcpd on the http://www.rpmfind.net/linux/rpm2html/ web site.

Setting the IP Address

Use the ifconfig command to make sure that the address referenced by dhcpd.conf is the same one that will be used by the DHCP server. To do this, type a line like the following one as root:

# ifconfig eth1 10.0.0.2

This document uses the following non-routable IP addresses:

  • For the host system: 10.0.0.2
  • For the target board: 10.0.0.10

These might be different for your particular setup.

The previous example associates the IP address 10.0.0.2 with the eth1 Ethernet port on your host machine. When DHCP is started on the host, it will send the information in the configuration file to that port.

Note

Remember that the eth1 parameter must match the port used when starting the DHCP server, as described in the next section. Also remember that the IP address parameter must match the server-name value, if any, used in the dhcpd.conf file.

Restarting the DHCP Server

After making these changes, you need to start (or restart) the DHCP server. If the DHCP server is running, stop it by issuing the following command:

# /etc/rc.d/init.d/dhcpd stop

Note

The command shown in the previous listing is valid for a Red Hat Linux system. If you are using another Linux distribution, such as Mandrake or Debian, the commands to stop and to start the DHCP server might be different.

If your DHCP server does not stop, you can force it to exit by sending a termination signal, SIGTERM, to it, as shown by the following command:

# killall -v -TERM dhcpd
Killed dhcpd(27483) with signal 15

Restart the server using a command like dhcpd -d eth1, which assumes that the interface on which the subnet specified in /etc/dhcpd.conf is accessible via the second Ethernet interface, eth1. Modify the command you use appropriately.

# dhcpd -d eth1 
Internet Software Consortium DHCP Server V3.0pl1 Copyright 1995-2001 Internet Software Consortium. All rights reserved. For info, please visit http://www.isc.org/dhcp-contrib.html Listening on LPF/eth1/10.0.0.0/24
Sending on LPF/eth1/10.0.0.0/24

The -d option causes the DHCP server daemon to run in debug mode, causing the server’s error messages, if any, to be sent to stderr (standard error), which is the console on most Linux systems. Using this option allows you to see any error output when you first boot the board.

Note

Debug mode might also be useful for ascertaining the MAC address of your board. If you don’t know the address, simply start the DHCP daemon in debug mode when you attempt to boot the board. When the board sends out BOOTP requests, the DHCP server will report messages like these, which contain the board’s MAC address:

Listening on Socket/eth1/10.0.0.0
Sending on Socket/eth1/10.0.0.0
BOOTREQUEST from 00:01:af:00:72:2b via eth1
No applicable record for BOOTP host 00:01:af:00:72:2b via eth1

You can then insert the correct MAC address into the stanza for the board and restart the DHCP server.

If you want the server to run in the background as a normal system daemon, omit the -d option:

# dhcpd eth1

 

Note

If your system is running a desktop Linux distribution such as Red Hat Linux, which starts and stops system processes by using run configuration (rc) scripts, you can simply restart the dhcpd daemon by invoking these scripts in the following way:

# /sbin/service dhcpd restart

This command will stop and then restart the DHCP service on your Linux system. In addition to the restart command, you can also issue stop and start commands this way.