Web Development

Setting up a dynamic DNS service part 2: dhcpd

Vincent Danen follows up his tip on configuring BIND for a dynamic DNS service with part 2 on configuring the DHCPd service, which will serve the DHCP-based IP addresses to clients and update the DNS records.

Last week, we looked at the beginnings of setting up a dynamic DNS service where one could connect any system to the network, have it provide a DHCP-delivered IP address, and automatically set up the forward and reverse DNS names for the system. In particular, the previous tip concentrated on configuring BIND, the DNS server.

In this final tip, we configure ISC's DHCPd service, which will serve the DHCP-based IP addresses to clients and update the DNS records accordingly. Again, this setup is based on a CentOS 5.3 configuration, but with perhaps minor path changes, it will work on any Linux distribution. As well, in our previous example, we used the home network domain name "home.lan" and the IP address network 192.168.10.0.

The dhcpd configuration file is typically /etc/dhcpd.conf. This file provides all the runtime options to dhcpd, allows you to configure different options for different subnets, and allows you to assign static IP addresses based on the requesting system's MAC address. Configuring dhcpd fully is beyond the scope of this tip, so we will concentrate primarily on the dynamic DNS related pieces.

At the top of /etc/dhcpd.conf, ensure the following keywords are defined:

ddns-update-style interim;
ddns-updates on;
ddns-domainname "home.lan.";
ddns-rev-domainname "in-addr.arpa";
use-host-decl-names on;
allow client-updates;
allow unknown-clients;
include "/etc/rndc.key";
zone home.lan. {
        primary 192.168.10.2;
        key rndckey;
}
zone 168.192.in-addr.arpa. {
        primary 192.168.10.2;
        key rndckey;
}

What the above does is define a variety of options to enable dynamic DNS updates. It also defines our two DNS zones: the 192.168.0.0 reverse lookup zone and the home.lan domain name. Finally, it indicates to use the "rndckey" as defined in /etc/rndc.key (see part 1 for more details on the RNDC key), and indicates that the primary DNS server is 192.168.10.2 -- the IP our named server is listening on. If the DHCP server is on the same system as the DNS server, you can use 127.0.0.1 instead; however, ensure that named is configured to listen on the IP address 127.0.0.1, port 53.

If you also configure static IPs to systems based on their MAC address, you can write host stanzas with hostname information. This ensures that regardless of what the connecting system reports as a hostname, it will use a specific pre-determined hostname. There are two ways this can be done, actually; the first is to define the host statement with the additional dynamic DNS options, such as:

host tyr {
        hardware ethernet 00:0c:eb:20:dc:fe;
        fixed-address 192.168.10.1;
        option host-name "tyr";
        DDNS-hostname "tyr";
}

This tells dhcpd to map the hostname tyr.home.lan to the system with the specified MAC address. It will also statically assign the IP 192.168.10.1 every time, and also tells dhcpd to report the hostname as tyr to named when the system connects.

The other option is to define the above without the option host-name and DDNS-hostname keywords. Instead you can provide A and PTR records in your named zone files for this host.

Once both named and dhcpd are configured, restart both services. At this point you will be able to connect any system to the network, and if you watch the logs (such as /var/log/messages), you will see the "conversation" between named and dhcpd as dhcpd hands out IP addresses to client systems.

Get the PDF version here. (PDF version part1)

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.

0 comments

Editor's Picks