These instructions also assume a recent version 8 bind (as of this writing, you shouldn't be running anything but 8.2.3 anyway, or your machine will be 0wn3d by a script-kiddie with too much time on his hands in short order.)
zone "dynamic.yourdomain.com." { type master; file "yourdomain.dynamic"; allow-update {localhost; }; };The file name is, of course, entirely a matter of personal preference, and you should follow whatever convention you are currently using. The allow-update line controls which machines can make updates - in the example above, only local connections from the nameserver itself are allowed (we'll cover allowing remote connections later).
Then, you'll need to create the file yourdomain.dynamic. It should look something like this:
dynamic.yourdomain.com 900 IN SOA yourdomain.com. root.yourdomain.com. ( 1 ;serial 900 ;refresh 1800 ;retry 691200 ;expire 900 ;fail ) 900 IN NS nameserver.yourdomain.com.Note, particularly, the low refresh time. This is presumably what you want, because by nature of the fact that updates are being made dynamically, you don't want answers cached for long. 900 seconds is 15 minutes; you can use a lower value (perhaps one or two minutes) if you consider it more appropriate.
Also note that the serial number doesn't obey the common YYYYMMDDRR convention. This is because it will be automatically incremented by BIND every time there's an update, and trying to follow the usual convention would be nothing but an exercise in futility. (This is one of the reasons it's desireable to have a separate dynamic subdomain.)
Remember to kill -HUP named after making these changes. You might also want to look in your syslogs after doing so to make sure there were no errors with the new configuration and/or domain.
nsupdate > update add foo.dynamic.yourdomain.com 900 A 1.2.3.4 > ^D
Note that the explicit TTL for the record must be specified; nsupdate exits with an error if you leave it out.
To confirm what you've done, nslookup the entry you just added, and confirm that it's present. If it's not, look in the syslogs for potential errors from named.
When named exits, the current state of the dynamic domain is written to the original file ("yourdomain.dynamic", in this example), overwriting the version which you manually created. This is a significant departure from named's normal behaviour, which never writes anything to the zone files for master domains. It is important to keep this in mind in selecting the location of the dynamic zone file.
There is, happily, a solution, and this solution is to use keys for authentication. First, you'll need to generate the keys:
dnskeygen -H 128 -h -n testkeyThis will create two files in the current directory containing information about the key in question; you can see the dnskeygen manpage for more details about this step.
Once you've generated the key, you'll need to alter named.conf to use it. This would cause your named.conf to look something like this:
key testkey { algorithm HMAC-MD5; secret "xxxxxxxx=="; }; zone "dynamic.yourdomain.com." { type master; file "yourdomain.dynamic"; allow-update {key testkey; }; };The "xxxxxxxx==" in the example above should be replaced by the actual key, which can be taken from either of the files generated by dnskeygen. Note that if there are any people with logins on the nameserver who should not have the ability to update the zone, it is necessary to remove read permissions from named.conf and the files generated by dnskeygen.
nsupdate -k /var/named/keys:testkey.The first part of the argument to the -k option is the directory in which the key is stored; the second is the key name. Note the trailing period; this is essential for nsupdate to find the key. (also note that it is the *.key file, and not the *.private file, which is used by nsupdate).
You can then proceed to use nsupdate normally. Obviously, a copy of the key must be transferred to any machine which should be able to perform dynamic updates to the name server.
nsupdate also has some quirks and peculiarities which might trip you up, however, and those I will mention. The syntax is rigidly fixed; as mentioned above, the TTL field cannot be left out of an addition. Also, nsupdate provides no information about whether or not your operation has succeeded - you must simply check afterwards and see. It is possible to feed input to nsupdate from stdin, and you might want to do this if you're using it in a script. Be warned, however, that there must be a blank line at the end of nsupdate's input - if it is absent, nsupdate will exit without even attempting to contact the nameserver.
nsupdate is a young program, and presumably its robustness will increase with time. (it may no longer have the aforementioned limitations by the time you read this). For now, though, keeping these things in mind may save you some aggravation.