Automatic DNS with dhcp
By Santiago Garca Mantin
(C) 2000, distributed under GPL 2.0

Well, this is based on Stephen Carville's dhcp-dns scripts to do dynamic DNS
using dhcp 2.0, but this is no dynamic DNS, it is an static DNS wich is
updated automatically. Also, I'm using the patches Craig Sanders did when
packaging it for debian. To both of them, thank you for giving me the job
half done.

What this scripts do, or at least intend to do, is automatically put into
DNS any machine with a well formed name that gets a new lease from the dhcp
server.

Also, once the host is put into DNS, they settle on the dhcp configuration
the IP it was given by the server, so that next time the machine boots it
gets the same IP. As a consequence of this, the time on wich a client can
get more than one lease gets reduced to the time elapsed between two runs of
the scripts (by default 1 minute), and also, the time he can have more than
one IP if it gets more than one IP, is reduced to the lease time. Afterwards
he will be given just one IP and only one, and it will allways be the same.
This is based on machine's MAC address, so... well, you know, if this
address is changed, then all that I have just said are lies.

The contents are more or less the same ones as on the original package:

 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, it also is reponsable
              for settling the name, MAC address and IP on the dhcp conf.

 ndc.cron.pl  a cron script to force named to write all changes to disk and
              reload its databases.

I have not included Stephen's ddnsupdate.pl as I personally think that the
standard nsupdate should be used if someone has to manually touch the dns.


------------------------
Setting up this package.
------------------------

This comes from Graig's patches for the Stephen Carville's scripts:

In what now is /etc/autodns-dhcp.conf, the domain defaults to:
	$DOMAIN='__DOMAIN__'
until changed, the scripts will exit immediately without doing anything.

You need to configure this before autodns-dhcp will work. you also need to
configure dhcp and bind as detailed below.


-------------------------------------------
Setting up DHCP 2 to use with this scripts.
-------------------------------------------

The scripts want the dhcpd to contain a one line range __IP__; line per each
IP that a host can be given. Also they spect this ranges to be sorted
incrementally.

For example, If we want to give away range 192.168.1.15-192.168.1.254 of the
class C network 192.168.1.0 then we write for example:

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.15;
range 192.168.1.16;
range 192.168.1.17;
range 192.168.1.18;
...
range 192.168.1.251;
range 192.168.1.252;
range 192.168.1.253;
range 192.168.1.254;
}

This range lines can be easily generated with something like this:
perl -e 'for ($i=15;$i<255;$i++){print "range 192.168.1.$i;\n"}'


-------------------------------------------
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, at least the machine running the
dhcp-server and this scripts should be listed there.

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)


----------------------------------------------------------------------------

Well, now the story...

I'm a member of the G.P.U.L. (Grupo de Programadores y Usuarios de Linux)
translated to english this is: Group of Programmers and Users of Linux, our
LUG here in A Corua, I'm also a member of A.M.I.G.A. (Asociacin da
Modidade Informtica Galega de A Corua). As a member of AMIGA I like
DemoScene parties, and as a member of GPUL I like Linux, so what I do is,
with the help of the other members, build software and hardware solutions
mainly for our own party, the Arroutada Party, even though now it seems that
we are being called from some others to help with the network or just
organice the Linux contests there. I don't have to tell you that people has
a nice time there.

Well, on last Arroutada I tried dhcp version 3.0 beta with DDNS and it
didn't work as well as I supposed it would do, so when we were contacted to
give a solution for the XuventudeGalicia.Net, I tried the last beta of
version 3 and still didn't work as I wanted it to, mainly because of the new
one lease per client option, so I took a look at Stephen's scripts and saw
that I could get a nice thing done with a few modifications.

The modifications I wanted was to achieve something like the new one lease
per client option, or the closest to this I could get, and also I didn't
want people coming to be able to overwrite other people's machine name or
even organization's machine name, and this was allowed on Stephen's original
scripts. When thinking of all this, I thought that for administrative
purposes it was better if there were no chances at all that one could change
his IP, so I settled all of them.

Well, after changing all this at home and after doing the tests with a
couple of clients, we came to the party, and of course it broke. When you
are organicing a party, you don't sleep too much, if you sleep, that is, so,
your mind is not too clear. That's why after a time I called up Roberto
Suarez Soto, to explain him how it all worked and see if he could help me
debug the scripts, and we found the bug (sort wasn't meant for sorting IP
numbers), so we started fixing the stuff, and it worked on our little script
for testing, but when we took it to the server it failed :-( That's were Rik
van Riel, who was at the party to to give a talk on memory management,
showed up, and after looking at our code without finding the problem, just
when I had found the problem (we were all quite sleepy), he proposed a
diferent aproach wich was correct.

And that's the hole story of how this was rewritten.

Of course I'd like to thank Rik and Roberto, for helping me when I was
totally switched off ;-)
