DHCP and Dynamic DNS -- v0.70

All of the attempts I have seen to tie DHCP and DNS together have ignored the dynamic update capacity of Bind 8. I wrote these Perl scripts to remedy that situation.

Contents

ddns.cron.pl a cron script to check for changes to the dhcp.leases file.
ddns.pl the script that does the actual work of creating the update instructions for nsupdate and BIND 8.
ndc.cron.pl a cron script to force named to write all changes to disk and reload its databases.
dnsupdate.pl perl script to make it easier to add and delete entries manually to DNS.

Instructions

  1. Copy the scripts to a directory. I suggest using a directory dedicated to the dhcp-dns function but that is not necessary. I use /root/DHCP-DNS.
  2. Change the following in the scripts:
    In ddns.cron.pl:
    my $DDNSHOME="/root/DHCP-DNS"; # Wherever you copied the scripts to.
    my $DHCPD="/etc/dhcpd.leases"; # the location of your dhcpd leases file
    my $DOMAIN="cyp.ugsolutions.com"; # The domain the dhcp addresses belong to.
    my $NSUPDATE="/usr/bin/nsupdate"; # The location of nsupdate on your system.
    In ndc.cron.pl:
    my $DDNSHOME="/root/DHCP-DNS"; # same place as $DDNSHOME above
    my $NDC="/usr/sbin/ndc restart"; # the command to force named to flush its buffers and reread the zone information.
  3. Assuming you already have dhcpd and Bind 8 running, use crontab to call the programs at appropriate intervals. I call ddns.cron.pl every five minutes and ndc.cron.pl every four hours.
5,10,15,20,25,30,35,40,45,50,55 * * * * /root/DHCP-DNS/ddns.cron.pl
* 4,8,12,16,20 * * * /root/DHCP-DNS/ndc.cron.pl

ddnsupdate.pl

This is a very basic perl script to aid in making dynamic changes to a running named. Right now it allows new A and PTR records to be added and deleted. Syntax is:

dnsupdate.pl add <name.domain> <ip address>
Adds a an A and a PTR record for <name.domain>

dnsupdate.pl delete <name.domain>
Deletes any A or PTR records for <name.domain>

It is very important to include the domain name.

Setting up BIND 8 to allow dynamic updates.

To use dynamic DNS, you must have your named.conf set up to allow it. This is accomplished by using the allow-update directive in your named.conf file. For example:

zone "high-g.prv" {
        type master;
        file "local.db";
        allow-update {192.168.1.10;};
};

zone "1.168.192.in-addr.arpa" {
        type master;
        file "192.168.1.db";
        allow-update {192.168.1.10;};
};

The address in the braces is the address of the computer that is allowed to update the running named dynamically. Some used report that they need to add 127.0.0.1 to this list as well.

It is very important that every zone you want to update dynamically have the allow-update directive. A common mistake is to allow updates in the forward lookup zone (A records) but forget to add the allow-update directive to the reverse lookup zone (PTR records)

The record files in /var/named (or wherever you put them) must be writable by whatever user named is runnig as if named is to be able to update them.

Known Bugs

One user reports that nsupdate.pl does not work correctly with bind 8.2: The reverse record (PTR) will be created but the forward record (A) will not. I have been unable to duplicate the problem but this release may fix it. OTOH, it may not.
Stephen Carville
Last modified: Wed Nov 15 12:21:39 PST 2000