Linux Home Server HOWTO
Previous
Home Next

Chapter 10 - DHCP Server

Version: - dhcpd 3.0.3

Basic Configuration
Setting Fixed Addresses
Setting Daemon Options
Starting DHCP
Testing The Server

Dynamic Host Configuration Protocol (DHCP) is defined in RFC2131 and is basically an automated means of managing and assigning Internet IP addresses to client workstations on the network. This protocol saves the system administrator much time having to manually configure each host workstation manually, and to maintain large databases storing IP assignment details. When any of the network settings change (like allocating a new default gateway or new DNS server), then the details can be configured at the DHCP server as opposed to manually changing the settings of many client systems.

This chapter will provide the means to configure the DHCPd package to provide IP assignment to your internal network. The DHCP server is installed on most Linux distributions, and is also available from the Internet Systems Consortium site.

Basic Configuration

The main DHCP configuration file should be located at /etc/dhcpd.conf, however it is sometimes missing. This is a configuration safeguard to stop users from accidentally starting a DHCP server without fully configuring its details. Having any unplanned DHCP servers operating on a network can result in major network problems. Therefore the administrator must create the configuration before implementing its services, a physical task to reduce error (some distributions may have the file available).

[bash]# vi /etc/dhcpd.conf

The following configuration file is an example for a typical home / small office network.

Note !! Be sure to change parameters to suit your network and domain name.

#
#   DHCP Server Config File
#
ddns-update-style none;
ignore client-updates;

lease-file-name "/var/lib/dhcpd/dhcpd.leases";
authoritative;

option domain-name                      "example.com";
default-lease-time                      86400;   # 24 hours
max-lease-time                          172800;  # 48 hours

subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers                  192.168.1.1;
        option subnet-mask              255.255.255.0;
        option broadcast-address        192.168.1.255;
        option domain-name-servers      192.168.1.1;
        option ntp-servers              192.168.1.1;
        option netbios-name-servers     192.168.1.1;
        option netbios-node-type        8;
        range   192.168.1.101   192.168.1.200;
}

A DHCP server can be configured with more than one range (subnet) of IP addresses. The parameters specified above the "subnet" declaration are global parameters which are applied to all subnet declarations, while the parameters inside each subnet override the global parameters.

The parameters specified in the above sample file are explained below. For more detailed information about the configuration options available, type "man dhcpd.conf" or "man dhcp-options" at the command prompt.

Parameter
Definition
ddns-update-style
Type of DDNS update to use with local DNS Server
ignore client-updates
Ignore all client requests for DDNS update
lease-file-name
Filename that stores list of active IP lease allocations
authoritative
Set as master server, protects against rogue DHCP servers and misconfigured clients
option domain-name
Specifies the Internet Domain Name to append to a client's hostname
option domain-name-servers
The DNS servers the clients should use for name resolution
default-lease-time
The default time in seconds that the IP is leased
max-lease-time
The max time in seconds that the IP is leased
option routers
Specifies the Gateway for the client to use
option subnet-mask
The subnet mask specific to the lease range
option broadcast-address
The broadcast address specific to the lease range
option ntp-servers
Network Time Protocol servers available to the clients
option netbios-name-server
The NetBIOS name server (WINS)
option netbios-node-type
The NetBIOS name resolution method (8=hybrid)
range
The range of valid IP addresses available for client offer

The DHCP server can be quite tricky to configure and normally does not provide any error messages when it fails to start as a service. Ensure your configuration file is formatted similar to the example above, and that semicolons complete all the parameter lines.

If the network on which the DHCP server is broadcasting does not have a WINS server, then the netbios-name-server and netbios-node-type options should be removed.

Setting Fixed Addresses

There may be a time when it is necessary for a workstation to be assigned a fixed address, this can be easily achieved by setting the following details in the bottom of the /etc/dhcpd.conf file.

host wkstn1 {
        hardware ethernet 00:0d:62:d7:a0:12;
        fixed-address 192.168.1.5;
}

Setting fixed addresses saves the operator time by avoiding the manual adjustments needed at each workstation. Be sure to remove the fixed address when it is no longer required, this is particularly important on larger networks where IP allocation needs careful management.

Setting Daemon Options

The DHCP daemon can be configured with command line options by using the /etc/sysconfig/dhcpd file. For security, DHCP can be bound to an interface so the allocation of addresses are only available to the private internal network.

[bash]# vi /etc/sysconfig/dhcpd

Setting this option provides queries and assignment only through this interface.

# Command line options here
DHCPDARGS=eth1

Starting DHCP

There was no initial DHCP configuration file when we started to set up the server. Now that the file has been created and the configurations are defined, it would be a good time to make a backup of the file.

[bash]# cp /etc/dhcpd.conf /etc/dhcpd.conf.original

When the server provides a leased IP address to a client, the details of the transaction are stored in the dhcpd.leases file. In some distributions this file has not been provided and may need to be created before the server will function. The following command prepares the dhcpd.leases file for use.

[bash]# touch /var/lib/dhcpd/dhcpd.leases

The server is now fully configured and its time to determine the runlevels and start the service.

[bash]# chkconfig --level 2345 dhcpd on
[bash]# /etc/init.d/dhcpd restart

You should always check the runlevels after they have been adjusted to confirm they will function as required.

[bash]# chkconfig --list dhcpd

Once the service has been started the system log should be checked to see if there are any errors. Most important is the security options we viewed earlier, which was to make sure the daemon was bound to the internal interface. The following example shows a binding to eth0.

[bash]# grep dhcpd /var/log/messages

galaxy dhcpd: Listening on LPF/eth1/00:40:05:51:20:e7/192.168.1.0/24
galaxy dhcpd: Sending on   LPF/eth1/00:40:05:51:20:e7/192.168.1.0/24
galaxy dhcpd: Sending on   Socket/fallback/fallback-net
galaxy dhcpd: dhcpd startup succeeded

Testing The Server

Now that the server is configured and running successfully, its time to test the server by requesting an IP lease from a Linux or Windows client. The DHCP protocol uses UDP on port 67 to broadcast for and reply to DHCP requests, ensure that the clients have access through any firewall system to successfully obtain an IP address.

Linux Client

If the Linux client distribution you are testing uses the dhclient package from the Internet Systems Consortium, then use the following command to obtain a lease for the eth0 network device.

[bash]# dhclient eth0           (EXECUTED ON CLIENT WORKSTATION)

Internet Systems Consortium DHCP Client V3.0.1
Copyright 2004 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/products/DHCP

Listening on LPF/eth0/00:0d:62:d7:a0:12
Sending on   LPF/eth0/00:0d:62:d7:a0:12
Sending on   Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
DHCPOFFER from 192.168.1.1
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.1
bound to 192.168.1.5 -- renewal in 20509 seconds.

By viewing the system log after renewing a DHCP client's lease, the transaction between client and server can be viewed. The following transaction records the fixed address 192.168.1.5 that was covered earlier being assigned to the reserved MAC address.

[bash]# grep dhcpd /var/log/messages            (EXECUTED ON DHCP SERVER)

galaxy dhcpd: DHCPDISCOVER from 00:0d:62:d7:a0:12 via eth0
galaxy dhcpd: DHCPOFFER on 192.168.1.5 to 00:0d:62:d7:a0:12 via eth0
galaxy dhcpd: DHCPREQUEST for 192.168.1.5 (192.168.1.1) from 00:0d:62:d7:a0:12 via eth0
galaxy dhcpd: DHCPACK on 192.168.1.5 to 00:0d:62:d7:a0:12 via eth0

If your Linux client is using the pump dhcpclient, then the following commands can be used to release, obtain, or view the status of the client.

[bash]# pump -i eth0
[bash]# pump -i eth0 --release
[bash]# pump -i eth0 --status

Windows Client

Testing a Windows based DHCP client is best done from a command prompt in the DOS shell, as more information is returned to the user than the standard graphical tools.

To release and renew your windows based IP address, follow these examples (expected results are provided).

C:\>ipconfig /release
Windows IP Configuration

Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 0.0.0.0
        Subnet Mask . . . . . . . . . . . : 0.0.0.0
        Default Gateway . . . . . . . . . :

C:\>ipconfig /renew

Windows IP Configuration

Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . : example.com
        IP Address. . . . . . . . . . . . : 192.168.1.5
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.1.1

The following command will provide more detailed information about the leased IP address and associated network resources.

C:\>ipconfig /all

Note !! Some Windows based antivirus and firewall applications restrict the local workstation from broadcasting for an IP address, and may need to be configured to allow such requests.



Previous
Home Next