DekGenius.com
[ Team LiB ] Previous Section Next Section

B.3 Step 3: Change the Zone Datafile Naming Convention

This step is optional. Chances are, your BIND zone datafiles don't follow the same naming convention used by the Microsoft DNS Server. Recall from Chapter 4 that the Microsoft convention is the name of the zone followed by the .dns extension—for example, movie.edu.dns. You can continue to use your current naming convention, but if you add new zones with the DNS console, they'll have the .dns extensions unless you go out of your way to make the names conform to your scheme. If you're not particularly attached to your naming scheme and don't want to fight the DNS console every time you create a new zone, this Perl script will rename your zone datafiles in the .dns style and modify your named.boot file accordingly:

# name-convert.pl--Convert zone datafile naming convention in a BIND
#                    named.boot file to Microsoft *.dns format
#

die "usage: name-convert.pl path-to-named.boot\n" unless $ARGV[0];

open (BOOTIN, $ARGV[0]) || die "Can't open boot file for reading: $!\n";
open (BOOTOUT, ">boot") || die "Can't open boot file for writing: $!\n";

while (<BOOTIN>) {
    $dir="$1/" if /^directory\s+(.+).*$/;
    &changeit (1, $1, $2) if /^primary\s+(.+)\s+(.+)$/;
    &changeit (2, $1, $5, $2) if /^secondary\s+([\w\.]+)\s+(((\d{1,3}\.){3}\
    d{1,3}\s+)+)(.+)$/;
    &changeit (3, "cache", $1) if /^cache\s+\.\s+(.+)$/;
}

sub changeit {
    local ($zonetype, $zonename, $oldfilename, $mastersips) = @_;
    $newfilename="$zonename.dns";
    rename ($dir.$oldfilename, $dir.$newfilename) || print "Error renaming 
    $oldfilename to $newfilename!\n";
    if ($zonetype == 1) {
  print BOOTOUT "primary $zonename $newfilename\n";
    } elsif ($zonetype == 2) {
  print BOOTOUT "secondary $zonename $mastersips $newfilename\n";
    } else {
  print BOOTOUT "cache . $newfilename\n";
    }
}

The script takes one argument, the name of the name server boot file. For example:

name-convert.pl /etc/named.boot

It outputs a file called boot in the current directory, which is a Microsoft DNS Server boot file with the zone datafile names changed. It's probably easiest to run the script on the BIND name server (which is probably running on Unix and therefore has Perl installed), then copy over boot and the newly renamed .dns zone datafiles.

    [ Team LiB ] Previous Section Next Section