http://www.perlmonks.org?node_id=127549

As part of our isp services, we provide dns for our customers. A growing problem as we add more and more zones, is that customers move their domains out of our nameservers, sometimes without informing us, and thus leaves us with obsolete info in our nameservers...

This small script is written to check against another nameserver that you are authorative for the zones in your dns file, I didn't bother to make it nest up all your include statements, if you have separate files change the var and run the script for those as well :)

hope someone finds this useful. Note that it requires Net::DNS from cpan

#!/usr/bin/perl -w #Change this! my $nsconf="/etc/named.conf"; # Your nameserver config file. my $other_ns="193.212.1.10"; # Nameserver to check against. my @names=("ns.songnetworks.no", "ns.tele1europe.no"); # Names of this nameserver. use strict; use Net::DNS; open CONF,"$nsconf"; my $res = new Net::DNS::Resolver; $res->nameservers($other_ns); while (<CONF>) { # match <<zone "perlmonks.org" in {>> if (m/^zone\s+\"([a-z0-9._\-]+)\"\s+in/i) { my $zone=$1; next if ($zone eq "." || $zone =~ /0.0.127.in-addr.arpa/); my $name=0; my $query = $res->query($zone, "NS"); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "NS"; my $nameserver=$rr->nsdname; $name=1 if grep(/$nameserver/i, @names); } print "$zone is out of date!\n" unless $name; } } }

qw(marcus)

Replies are listed 'Best First'.
Re: weedzones - avoid zonerot!
by Anonymous Monk on Dec 19, 2001 at 07:33 UTC
    Wow, I'd just sat down to write the same script, and a search for an example of the Net::DNS::Resolver led me here. I had to make one small change because of a small difference in the formatting of my named.conf...

    # match <<zone "perlmonks.org" {>> if (m/^zone\s+\"([a-z0-9._\-]+)\"\s+/i) {

    I don't say 'zone "perlmonks.org" in {'... I leave out the 'in'. I'm sure there's a way to make it optional in the regex, but I'm no perl wizard - I was just happy to get it working.

    I hope this helps someone!

    Thanks for the cool script.