A Better Nsupdate

Over the holidays I was monkeying around with dnspython, a seriously cool Python module created by the fine folks at Nominum. This toolkit implements almost all of the DNS protocol and comes with many convenient helper methods to get DNS stuff done. I actually wrote a few different tools over the holiday for various purposes but one stands out in its usefullness, dnsupdate.

I wrote dnsupdate with the idea of replacing nsupdate, the standard DDNS update tool created by BIND authors ISC. I’ve never been fond of nsupdate, it does the job and is functional but it is awkward to wrap in scripts and its usage in general is just not very intuitive. I wrote dnsupdate to work well from the comamnd line or from scripts and to be easy to use. It also does some nice things like automatically create PTRs for a given A or AAAA record.

Usage of dnsupdate differs quite a lot from nsupdate. Where nsupdate usage looks something like:

1
2
3
4
5
nsupdate -k ./Kexample.com.+157+41416.key
> server ns.example.com
> zone example.com
> update add foo.example.com 300 A 1.2.3.4
> send

The usage for dnsupdate looks like this:

1
dnsupdate -s ns.example.com -k Kexample.com.+157+41416.key add foo.example.com 300 A 1.2.3.4

Dnsupdate currently supports the adding, deleting and updating of A, AAAA, PTR, TXT, NS, SRV and MX records. It will also automatically add/delete/update a PTR for a given A or AAAA record, though the forward and reverse zones have to exist on the same server. There is quite a lot of input validation for the various record types making it more difficult (though probably not impossible) to add bad records to your zones.

usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
usage: dnsupdate [-h] {-s} {-k} {-o} [-x] {add|delete|update} {Name} {TTL} [IN] {Type} {Target}

Add, Delete, Replace DNS records using DDNS.

positional arguments:
  add|delete|update  {hostname} {TTL} [IN] {Type} {Target}.

optional arguments:
  -h, --help         show this help message and exit
  -s SERVER          DNS server to update (Required)
  -k KEY             TSIG key. The TSIG key file should be in DNS KEY record
                     format. (Required)
  -o ORIGIN          Specify the origin. Optional, if not provided origin will
                     be determined
  -x                 Also modify the PTR for a given A or AAAA record. Forward
                     and reverse zones must be on the same server.
  -v                 Print the rcode returned with for each update

dnsupdate requires the dnspython and argparse python modules, both of which are common in most Linux distros. Questions? Comments? Let me know…