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.
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. |
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. |
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
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.
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.