Networking

Set up ISC's dhcpd server


Large and small networks alike can take advantage of DHCP and often do. With the dhcpd server from Internet Systems Consortium (ISC) you can not only provide dynamic IP addresses to hosts on your network, you can also provide static IP addresses based on the host's MAC address. This is extremely useful in the case of servers that should consistently have the same IP address, but the setup of DHCP is easier than static IP addresses. One definite advantage here is in the case of network renumbering or changing; simply changing one configuration file can set up hosts with different IPs or netmasks instead of changing each host individually.

The dhcpd package is available for most Linux distributions, so it's usually a simple urpmi or apt-get away. Once it is installed, the configuration file to edit is /etc/dhcpd.conf. If you also use BIND for DNS, you can link both dhcpd and named (name service daemon) together to provide "linked" DNS and DHCP information for truly transparent network host management. However, in this example, we'll assume that dhcpd is running alone, without corresponding with named.

An example /etc/dhcpd.conf follows:

ddns-update-style none;
subnet 192.168.0.0 netmask 255.255.255.0 {
    authoritative;
    option routers 192.168.0.1;
    option broadcast-address 192.168.0.255;
    option subnet-mask 255.255.255.0;

    option domain-name "mydomain.local";
    option domain-name-servers 192.168.0.2;

    range dynamic-bootp 192.168.0.200 192.168.0.254;
    default-lease-time 21600;
    max-lease-time 43200;

    host server1 {
        hardware ethernet 00:0c:ea:50:dc:fe;
        fixed-address 192.168.0.40;
    }
    host dns {
        hardware ethernet 00:26:cb:c5:37:9f;
        fixed-address 192.168.0.2;
    }
}

This is a fairly simple configuration. What we configure here is a subnet statement, where the configuration indicates we are authoritative for the 192.168.0.0 subnet, with a netmask of 255.255.255.0. In a nutshell, this means you can have a single dhcpd server handling address requests for different networks if the need is there.

In this network, you can see the default options that will be passed to all DHCP clients to which an address will be given: the gateway is 192.168.0.1; the broadcast address is 192.168.0.255; and the subnet mask is 255.255.255.0. The domain for this network is mydomain.local and the DNS server IP address to provide to clients is 192.168.0.2 (assume for a moment this is simply a caching DNS server).

Next, options for the DHCP clients are provided: addresses in the range of 192.168.0.200 to 192.168.0.254 are available, which means that 55 DHCP clients may be obtaining IPs at a time. The default lease time for IPs provided is 21600 seconds, or 6 hours. The maximum lease time for an IP address is 12 hours.

Finally, the host statements allow for the configuration of single hosts, which is where the use of DHCP for servers that require a static IP is exceptionally useful. With the above, the host server1 is provided the static IP address of 192.168.0.40; the determination of the host server1 is the noted MAC, or hardware ethernet, address. If this host ever changes hardware, be it the full system or a new network card, this will need to be updated to reflect the new MAC address for that system.

A second static IP declaration is made for the host dns.

Once /etc/dhcpd.conf is configured and saved, exit the text editor and start the dhcpd server (usually "service dhcpd start"). Also make sure that any other DHCP servers on the network — such as any that may be enabled on a firewall or router — are disabled.

Delivered each Tuesday, TechRepublic's free Linux and Open Source newsletter provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks