[conspire] Butt-ugly shell script: glue records
Rick Moen
rick at linuxmafia.com
Fri Mar 1 18:35:31 PST 2013
People at $ORK were monitoring DNS by doing queries of the domains'
in-zone NS records. So, for example, they were finding out whether NS
lines for linuxmafia.com. exist by doing:
/usr/bin/dig -t ns linuxmafia.com. 2>&1 | grep NS
Problem: That ends up asking linuxmafia.com. what _its_ NS lines are,
which aren't what the public uses. The public uses the _authoritative_
records, which exist in the parent zone, in this case the com. domain's
own DNS zone. You therefore have to query com.'s nameservers for the
DNS records, not linuxmafia.com.'s. (The former are called 'glue
records', and are what make DNS work at all. Otherwise, if you had to
ask linuxmafia.com. what its nameservers are, you'd have an insoluable
chicken-and-egg problem. Think about it.)
So, they asked me how I'd recommend they do it.
This is the sort of thing that cries out for Perl or Python, or Ruby, or
damned near anything but shell... but I reached for awk and sed. The
results are asstastic for legibility, but I offer them here for
amusement value:
$ bin/gluerecord.sh linuxmafia.com.
linuxmafia.com. 172800 IN NS ns1.linuxmafia.com.
linuxmafia.com. 172800 IN NS ns.primate.net.
linuxmafia.com. 172800 IN NS ns1.thecoop.net.
linuxmafia.com. 172800 IN NS ns.tx.primate.net.
linuxmafia.com. 172800 IN NS ns3.linuxmafia.com.
$ cat bin/gluerecord.sh
#!/bin/bash
/usr/bin/dig -t ns $1 @$(/usr/bin/dig -t ns $(echo "$1" | sed 's/^[^.]*\.//') \
+nocmd +nocomments +nostats +noquestion | head -n 1 \
| awk '{print ($5)}') +nocmd +nocomments +nostats +noquestion 2>&1 | grep NS
$
More information about the conspire
mailing list