Finding all CNAMEs associated with an A record
Kevin Darcy
kcd at daimlerchrysler.com
Mon Nov 17 23:51:08 UTC 2003
Anshuman Kanwar wrote:
>Hi all,
>
>Given that I created a many to one relation between CNAMEs records and an A
>record, is there a way to get a list of all CNAMEs by querying the A name ?
>
>example :
>
>bird IN A 192.168.0.5
>chicken IN CNAME bird
>hen IN CNAME bird
>rooster IN CNAME bird
>
>Now I want run some commad, which gives me :
>
># some-command bird
>chicken
>hen
>rooster
>
As long as you're limiting yourself to CNAMEs that are in a particular
zone, then this should be a fairly easy Perl script to write. Basic
structure: do a zone transfer of the specified zone, looking for CNAME
records with the specified name in their RDATA. Quick-and-dirty:
#!/usr/bin/perl
use Net::DNS;
($target, $zone) = @ARGV;
$res = new Net::DNS::Resolver;
foreach $rr ($res->axfr($zone)) {
print $rr->name."\n" if (($rr->type eq "CNAME") && ($rr->rdatastr eq
$target."."));
}
But, of course, CNAMEs in one zone can point to a name in a completely
different zone. Without downloading every zone in existence, there's no
way to know for sure whether one of them might contain a CNAME reference
to any given name.
- Kevin
More information about the bind-users
mailing list