This guide will show you how to setup a very simple, useful and straightforward dynamic DNS udpate system using only a small php script (and a nameserver, of course).
What is it?
This is a very simple approach into building a very simple dynamic update system, in a similar fashion to those provided by dyndns.org and similar sites.
Basically, what a client needs to do in order to update its IP is to fetch a webpage which, in this case, it would be;
http://dyn.domain.com/dns/update.php?host=client&pass=secret
It's a simple method because the client only has to fetch a web page to update its DNS IP address (client.dyn.domain.com in this case).
What is it not?
This is not a secure way to install a dynamic DNS update infrastructure. If you need that, take a look at the GnuDIP project.
Requirements
This requirement for this approach are quite basic indeed (that's why it's called "simple").
- a DNS server, which resolves DNS requests for your dynamic zone (in this case, dyn.domain.com)
- a HTTP server with PHP support (could be the same DNS server)
In this scenario the script would be run in the HTTP server which, in turn, will update the DNS zone (in the DNS server)
How it works
- the (dynamic IP) client makes a HTTP request to the HTTP server, eg: http://dyn.domain.com/dns/update.php?host=client&pass=secret
- the PHP script process the request, validates the user/password, and fires the DNS update request through the
nsupdate
utility - the DNS server receives the update request from the HTTP server and performs the update into the DNS zone leaving the hostname (client.dyn.domain.com in this case) with the new IP address
Receipt
This is a receipt to setup the dynamic DNS update system, as specified above. I assume you have already registered the domain and created the zone in your named configuration (this is not a BIND nor a registrar guide).
Install and configure the PHP update script
Download the PHP script (by clicking on the link below), log into the HTTP server and install the PHP script into a public accesible location, ie. http://dyn.domain.com/dns/update.php.
For simplification purposes, the configuration options are located inside the same script. Those are:
-
$hosts
- an array which contains the available hosts and their passwords -
$zone
- the DNS zone to hold the dynamic hosts -
$dnsserver
- the authorative server for the zone specified above (must allow updates from this host)
Configure the DNS server to allow updates
You must also configure the DNS server to allow update from the HTTP server (which could be the same machine). To do that you use the allow-update
directive. The zone configuration (in your named.conf file) would be something like this:
zone "dyn.domain.com" {
type master;
file "dyn.domain.com";
allow-update { 127.0.0.1; };
};
In this case update requests will come from the same machine. If your HTTP server is located in another machine just replace 127.0.0.1 with its IP address.
For better security you should use key authentication. See man named.conf
for more information.
Configure the clients
The only thing left to do is configure your clients to update the information by running wget (or a similar web fetch program) on the update. In order to do that, you have to add the following lines to your /etc/crontab
file:
/5 * * * root wget -q -O /dev/null "http://dny.domain.com/dns/update.php?host=client&pass=secret"
If anything goes wrong during an update, the system will try again in five minutes. The PHP have protection so that it won't issue a DNS update if the IP hasn't changed. That would alleviate the load on the DNS server thus reducing the zone journaling file size.
Like any other guides on this site, this is a quick and dirty one. "A simple solution for a simple problem". So don't blame me if any of this things doesn't work for you. I only wanted to give you hand. If you have any problems write a comment and I'll do my best, but keep in mind that I'm not a full-time computer guide blogger.