transferring named.conf to a slave server

Michael Reynolds michael at spinweb.net
Thu Oct 26 14:57:38 UTC 2000


Alexander,

Thanks... after I sent this I whipped up one of my own:

=
--------------------------------------------------------------------------=

#!/usr/bin/perl
use Net::FTP;

# set defaults
$master_file =3D "named.conf";
$slave_file =3D "named.conf";
$master_dir =3D "/etc";
$slave_dir =3D "/etc";
$temp =3D "tempfile";
$master_address =3D "x.x.x.x";

# ftp user on master
$username =3D "<username>";
$password =3D "<password>";

# today
$day =3D `/bin/date "+%d"`;


# backup current conf file
system("cp -rf $slave_file $slave_file.$day");

# ftp aliases file to mozart
chdir($slave_dir);
$ftp =3D Net::FTP->new("$master_address") or die "Can't connect: $@\n";
$ftp->login($username, $password) or die "Coudn't login\n";
$ftp->cwd($master_dir);
$ftp->get($master_file, $temp) or die "Couldn't get $master_file\n";
$ftp->quit();


open(MASTERCONF, "<$slave_dir/$temp");
open(SLAVECONF, ">$slave_dir/$slave_file");

while(<MASTERCONF>)
{
   if($_ =3D~ /type master/)
   {
      $_ =3D~ s/type master/type slave/;
   }

   print SLAVECONF $_;

   if($_ =3D~ /file "zones/ && $_ !~ /file "zones\/127.0.0"/)
   {
      print SLAVECONF "        masters { $master_address; };\n";
   }
}

close(MASTERCONF);
close(SLAVECONF);

# restart named
system("/usr/sbin/ndc restart");
------------------------------------------------------------------------

But I might try yours, too ;-)

THanks!
	---Mike


On Wednesday, October 25, 2000, at 08:32 PM, Alexander Ottl wrote:

> =20
> Michael Reynolds wrote:=20
> > =20
> > I saw this exchange on Mr. DNS's web site:=20
> > =20
> > =
-----------------------------------------------------------------------=3D=
0D=3D=20
> > At 03:24 PM 10/30/97 -0500, you wrote:=3D0D>Hello, I appreciate your =
=3D=20
> > service - but I didn't see anywhere (including=3D0D>the BIND pages) =
how to =3D=20
> > setup a slave DNS that's completely dumb. By this=3D0D>I mean is =
there =3D=20
> > some way in BIND (8.1) to have one DNS machine replicate=3D0D>it's =3D=
=20
> > information off of a master and grab everything? I would like to =
do=3D0D=3D=20
> > >this rather then have each zone and setup them up as slaves. I =
suppose=3D0D=3D=20
> > >on a time bases (crond?) I could get the named files off of the =
other =3D0D=3D=20
> > >machine but I would much rather do it within the protocol is there =
is=3D0D=3D=20
> > >allocation for it? I appreciate you time - and look forward to =
hearing =3D0D=3D=20
> > >from you.=3D0D=3D0DYou can't do what you want to do with BIND =
alone.  =3D=20
> > There's nothing in the=3D0DDNS protocol that allows one name server =
to ask =3D=20
> > another, "Hey, what zones=3D0Dare you authoritative (master or =
slave) =3D=20
> > for?"  You must tell a name server=3D0Dwhat zones it should be =
master or =3D=20
> > slave for.=3D0D=3D0DYour suggestion of copying the zone database =
files from =3D=20
> > the master would=3D0Dwork, but Mr. DNS thinks that's unnecessarily =3D=
=20
> > complicated.  Why not set up=3D0Da script that transforms the =
named.conf =3D=20
> > on the master to a suitable=3D0Dnamed.conf for the slave?  =
(Basically =3D=20
> > transform the zone statements from=3D0D"master" to "slave")  After =3D=
=20
> > changing the named.conf, the script could=3D0Dautomatically copy it =
to the =3D=20
> > destination host and kill and restart the =
name=3D0Dserver.=3D0D=3D0DRegards,=3D0D=3D=20
> > =3D0DMr. DNS=3D0D=3D=20
> > =
--------------------------------------------------------------------------=
=3D=20
> > -=20
> > =20
> > My question is: does anyone already have a script to do this? If so, =
=3D=20
> > would you share it with me?=20
> > =20
> > Thanks!=20
> >         ---Mike=3D=20
> =20
> Ok, I bite.=20
> =20
> Here's what I use:=20
> -------------------------------------------------------------=20
> #!/usr/bin/perl=20
>  =20
> $MASTER =3D 'x.x.x.x'; # insert IP of primary master here=20
> $DOMPAT =3D '([\w-]+\.)*[\w-]+';=20
> $LOCALDOMAIN =3D 'localhost|0\.0\.127\.in-addr.arpa';=20
>  =20
> while (<>) {=20
>         next if /^\s*query-source\b/;=20
>         if ( /^zone\s+"($DOMPAT)"/ ) { $domain =3D $1; $type =3D '';}=20=

>         if ( /^zone\s+"($DOMPAT)"/ ... /^\};/ ) {=20
>                 if ( /\btype\s+(master|slave);/ ) { $type =3D $1; }=20
>                 if ( $type eq 'master' && $domain !~ /$LOCALDOMAIN/ ) =
{=20
>                         next if /^\s*also-notify\b/;=20
>                         s/type\s+master/type slave/;=20
>                         s|file\s+"master/|file "slave/|;=20
>                         print "\tmasters { $MASTER; };\n" if /^\};/;=20=

>                 }=20
>         }=20
>         print;=20
> }=20
> -------------------------------------------------------------=20
> =20
> This perl script basically does what was suggested, that is =
substituting=20
> "master" by "slave".=20
> One word of caution though. This is not a named.conf parser. It's only =
a=20
> quick-and-dirty solution.=20
> If your formatting is slightly off it will fail.=20
> Also some configuration options should not be copied to the slave: =
like=20
> listen-on, query-source, and maybe others.=20
> =20
> There a makefile called by cron, that does the automatic update:=20
> named.conf.slave: /etc/named.conf=20
>         /root/bin/master2slave $< >$@.tmp=20
>         mv $@.tmp $@=20
>         rdist -P /usr/bin/ssh -l stdout=3Dchange:notify=3Dall=20
> And a distfile for rdist=15that will also reconfig the slave server=20
> ns2:=20
> /var/named/named.conf.slave -> ns2=20
>         install -osavetargets /etc/named.conf;=20
>         special /var/named/named.conf.slave "ndc reconfig";=20
>         notify <hostmaster-email-address>;=20
> =20
> Regards,=20
> =20
> Alexander Ottl=20
> Media Professionals AG           Tel.: +49 (89) 51554-169=20
> Bayerstrasse 21                  Fax : +49 (89) 51554-199=20
> D-80335 Muenchen - Germany       http://www.media-professionals.de=20
> =20
> =20



More information about the bind-users mailing list