DNS BIND 9 Primary named.conf reformat/convert to Secondary server script

Kevin Darcy kcd at daimlerchrysler.com
Thu Feb 26 23:09:32 UTC 2004


JPrine wrote:

>This script will create a file named "named.conf.gypsy" that is an
>exact copy of named.conf, but reformatted to the way a secondary DNS
>server needs it. How you get it to the secondary is up to you, i use
>crontabs to scp it over every night. Used in combination with "rndc
>reload" and "rndc flush" this should eliminate the need for any DNS
>maintenance on a secondary server. Please let me know how it
>goes...Enjoy!
>
>Here she blows...
>
>***** START *****
>#! /bin/sh
>cd /etc/
>
>#store number of lines in conf file
>lines=`cat named.conf | wc -l`
>
># bc calculates how many lines to tail - header
>modifylines=`echo "$lines-22" | bc`
>
>#write the header to a file (first 22 lines)
>head -22 named.conf > named.conf.head
>
># just modify the zone file lines, the first 22 lines do not need to
>be changed
>tail -$modifylines named.conf > named.conf.tail
>
>sed -e "s/type master/type slave/g" named.conf.tail > named.conf.slave
>sed -e "s/file \"pri\/rev\//file \"sec\/rev\//g" named.conf.slave >
>named.conf.rev
>sed -e "s/file \"pri\/fwd\//file \"sec\/fwd\//g" named.conf.rev >
>named.conf.fwd
>
>awk '{print $0} /\";/ {found=1} /\";/ && found {print "\tmasters { (IP
>Address); };\n\tallow-transfer { none; };"}' named.conf.fwd >
>named.conf.tailnew
>
>cat named.conf.head named.conf.tailnew > named.conf.gypsy
>
>
>rm named.conf.tail;rm named.conf.head;rm named.conf.fwd;rm
>named.conf.slave;rm named.conf.tailnew;rm named.conf.rev
>
>#SCP it over to secondary
>#scp /etc/named.conf.gypsy gypsy.suite224.net:/etc/named.conf
>***** END *****
>
Dude,
           It's 2004.

#!/usr/bin/perl

chdir("/etc");
open(NAMED_CONF, "<named.conf");
@named_conf = <NAMED_CONF>;
close(NAMED_CONF);
for (@named_conf[22..$#named_conf]) {
    s/type master/type slave/g;
    s%file\s"pri/(((rev)|(fwd))/.*)";$
     %file "sec/$1";
\tmasters { (IP Address); };
\tallow-transfer { none; };%gx;
}
open(NAMED_CONF_GYPSY, ">named.conf.gypsy");
print NAMED_CONF_GYPSY @named_conf;
close(NAMED_CONF_GYPSY);

                                                           - Kevin





More information about the bind-users mailing list