Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to export DNS Reverse lookup entries from a Windows Server 2003 box running dnsmgmt into a reverse zone file that can be used by a Unix server running Bind?

If not, is there a way to automate the exportation of the reverse DNS information into text files so I can hack something up in Perl?

share|improve this question
up vote 1 down vote accepted

You could use the DNSCMD utility from the Windows Support Tools to export the zones using the /ZoneExport parameter. The export is a little quirky, because it exports to the %windir%\system32\dns directory on the server hosting the zones.

I'm not certain the format is exactly BIND format, but it's close. You could get it the rest of the way with a script fairly easily.

share|improve this answer
I found the zone files are automatically added to %SystemRoot%\System32\dns so now I have some text files to work with. – John Scipione Nov 2 '09 at 19:51
You must be using "Standard Primary" zones, then. If you were using Active Directory integrated zones there wouldn't be any zone files there. – Evan Anderson Nov 2 '09 at 19:52
Yes, I am not using Active Directory, just plain ol' DNS – John Scipione Nov 3 '09 at 0:32

Why not set up a secondary DNS zone on the *nix box, authorise Zone Transfers on the 2003 server to that nix box, and then have a nice relaxing coffee?

share|improve this answer
Or just authorize transfers and use dig/host/nslookup and request a transfer. – Zoredache Nov 2 '09 at 20:04
Yup - that too! – Izzy Nov 2 '09 at 20:05
I am actually changing the authoritative Name Server of a bunch of domains over from one name server to another, so the above lazy solution will not work. – John Scipione Nov 3 '09 at 0:33

Here is a Perl Script that I wrote to convert reverse DNS Zone Files from Windows to something that can be used by Bind on Unix. It creates a new Unix zone file for each Windows dns file and a file (to put into your named.conf file on Unix) and a file (to put into or named.slave.conf file on Unix).

#!/usr/bin/perl -w

# Author: John Scipione @ Netsville (
# This script converts reverse zone files found in 
# %SystemRoot%\System32\dns on a Windows server to ones that can 
# be used by Bind on a Unix server.

use strict;

my $primarydns = ''; # Hostname of your primary DNS server (w/o trailing .)
my $primarydnsip = ''; # IP of your primary DNS server
my $rootname = ''; # Domain Contact Root Name
my $secondarydns = ''; # Hostname of your secondary DNS server (w/o trailing .)
my $refresh = '3600';
my $retry = '600';
my $expire = '604800';
my $ttl = '3600'; # Minimum TTL

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$year += 1900; # Perl uses years since 1900 by default
$mon = sprintf("%02d", $mon + 1); # Perl uses month [0..11] by default
$mday = sprintf("%02d", $mday);

open(MASTER, '>', ''); # blank file out

open(SLAVE, '>', ''); # blank file out

my @files = <*>;
foreach my $file (@files) {
    if (substr($file, -3) ne 'dns') {
    	next; # skip if file does not end in .dns
    my $outfilename = substr($file, 0, -3) . 'zone';
    my @pieces = split(/\./, $file);
    my $third_octet = $pieces[0];
    my $classB = $pieces[1] . '.' . $pieces[2];
    my $classC = $pieces[0] . '.' . $pieces[1] . '.' . $pieces[2];
    open(INFH, '<', $file);
    open(OUTFH, '>', $outfilename);
    print OUTFH "\$TTL $ttl\n";
    print OUTFH "\$ORIGIN $\n";
    print OUTFH "$third_octet\tIN\tSOA $primarydns. $rootname. (\n";
    print OUTFH "\t\t\t\t\t\t" . $year . $mon . $mday . "00\t; serial number\n";
    print OUTFH "\t\t\t\t\t\t$refresh\t\t; refresh\n";
    print OUTFH "\t\t\t\t\t\t$retry\t\t\t; retry\n";
    print OUTFH "\t\t\t\t\t\t$expire\t\t; expire\n";
    print OUTFH "\t\t\t\t\t\t$ttl )\t\t; default ttl\n\n";
    print OUTFH "\tIN\tNS\t$primarydns.\n";
    print OUTFH "\tIN\tNS\t$secondarydns.\n\n";
    print OUTFH "\$ORIGIN $\n";
    while (<INFH>) {
    	if (substr($_, 0, 1) eq ';') {
    		next; # skip comment lines
    	$_ =~ s/\r//g; # trim off \r

    	if ($_ =~ /(\d+)\s+PTR\s+(\S+\.\S+\.\S+\.)/) {
    		print OUTFH "$1\tIN\tPTR\t$2\n";
    	} elsif ($_ =~ /\s+PTR\s+(\S+\.\S+\.\S+\.)/) {
    		print OUTFH "\tIN\tPTR\t$1\n";


    open(MASTER, '>>', "");
    print MASTER "zone \"$\" {\n";
    print MASTER "  type master;\n";
    print MASTER "  file \"$\";\n";
    print MASTER "};\n";

    open(SLAVE, '>>', "");
    print SLAVE "zone \"$\" {\n";
    print SLAVE "  type slave;\n";
    print SLAVE "  file \"$\";\n";
    print SLAVE "  masters { $primarydnsip; };\n";
    print SLAVE "};\n";
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.