[BlueOnyx:07253] Re: DNS Script ?
Ken - Precision Web Hosting, Inc
kenlists at precisionweb.net
Sat May 7 15:44:13 -05 2011
----- Original Message -----
From: Dan Porter
To: BlueOnyx General Mailing List
Sent: Saturday, May 07, 2011 10:15 AM
Subject: [BlueOnyx:07251] Re: DNS Script ?
LOL, its not difficult. The hosting customer does not have access to the
second box and it's one of those petty little maintenance tasks that could
be automated and eliminated. I thought perhaps someone on this list had
already done so but maybe I am the first to consider it. We have also had
the case of someone mistyping the domain name on the secondary DNS service.
Thanks Jeff !! Dan.
---------- Original Message -----------
From: Jeff Folk <jfolk at qzoneinc.com>
To: BlueOnyx General Mailing List <blueonyx at mail.blueonyx.it>
Sent: Sat, 7 May 2011 11:36:18 -0500
Subject: [BlueOnyx:07250] Re: DNS Script ?
> On May 7, 2011, at 11:06 AM, Dan Porter wrote:
> >
> > So the question was, is there such a script available that someone has
> > already created to automate the creation of the secondary records based
> > on those from the primary - OR - what are the ramifications of simply
> > running two primary DNS servers by just FTP'ing over the zone files when
> > a change is detected on the first primary DNS server?
>
> What is so difficult about adding a domain name and IP into the secondary
> dns service on the second box? It isn't like you have to recreate all the
> dns records... The complete zone file is transferred to the secondary dns
> server (as long as you have given permission to the IP address in the
> primary server).
>
> _______________________________________________
Dan
What I do is on the server hosting the sites and the dns is :
set up a cron
22 10 * * * /root/domainlist.sh
That script contains:
#!/bin/sh
rm /home/sites/somesite.onyourserver.com/web/secondaryrecords.txt
ls -1 /home/sites | grep www. >>
/home/sites/somesite.onyourserver.com/web/secondaryrecords.txt
chmod 766 /home/sites/somesite.onyourserver.com/web/secondaryrecords.txt
perl -p -i -e 's/www\./secondary - /g'
/home/sites/somesite.onyourserver.com/web/secondaryrecords.txt
perl -p -i -e 's/\n/ 123.456.78.90 - \n/g'
/home/sites/somesite.onyourserver.com/web/secondaryrecords.txt
That file contains records like the ones below, where 123.456.78.90 is the
IP of your primary nameserver.
secondary - oneofyourdomains.com 123.456.78.90 -
secondary - anotherofyourdomains.com 123.456.78.90 -
Then on the secondary server, I get those records and inject them into the
named.conf
35 21,7 * * * /root/getrecs.pl
That file contains:
#!/usr/bin/perl
$aproblem = "nothing";
system ("rm secondaryrecords.txt secondaryrecords.txt.* ");
$filetoget = "http://123.456.78.90/possiblysomedir/secondaryrecords.txt";
$wgetinfo = `wget $filetoget 2>&1`;
if ($wgetinfo !~ /200 OK/i) { print "We have a problem with $filetoget ,
will exit. Info is $wgetinfo"; exit; }
$filetoget = "http://123.456.78.99/possiblysomedir/secondaryrecords.txt";
$wgetinfo = `wget $filetoget 2>&1`;
if ($wgetinfo !~ /200 OK/i) { print "We have a problem with $filetoget ,
will exit. Info is $wgetinfo"; exit; }
$filetoget = "http://223.456.99.101/secondaryrecords.txt";
$wgetinfo = `wget $filetoget 2>&1`;
if ($wgetinfo !~ /200 OK/i) { print "We have a problem with $filetoget ,
will exit. Info is $wgetinfo"; exit; }
system ("cat secondaryrecords.txt secondaryrecords.txt.* > allrecords");
open (IN, "<allrecords") or die "Couldn't open input CSV file: $!";
my @allsortedrecords = sort <IN>;
system (" cp /root/orignamed.conf /root/named.conf");
open(NAMEDCONF," >> /root/named.conf");
$lastline = '';
foreach $thisline (@allsortedrecords) {
($prev0, $nothing, $domain, $ipaddress, $prev4) = split(/\s+/,$thisline);
#print "prev0 $prev0, nothing $nothing, domain $domain, ip $ipaddress,
nada $prev4";
#print "The domain is $domain \n";
if ($domain eq $lastdomain) {
print "$domain eq $lastdomain ----------------------------- \n\n";
$aproblem = $lastline;
#exit;
next;
} else {
if (($domain =~ /\s/) or ($ipaddress !~ /\d+\.\d+\.\d+\.\d+/) or
($domain =~ /in-addr.arpa/) or ($thisline eq
$lastline) ) {
print "domain $domain then ip is $ipaddress or thisline eq last
$thisline eq $lastline next\n";
next;
}
print NAMEDCONF "zone \"$domain\" \{\n";
print NAMEDCONF " type slave;\n";
print NAMEDCONF " file \"db.$domain\";\n";
print NAMEDCONF " masters \{ $ipaddress; \};\n";
print NAMEDCONF "\};\n\n";
#if ($lastline eq "precisionweb.net") {
# print "This line is $thisline";
# print "Last line is $lastline";
# exit;
#}
$lastdomain = $domain;
}
}
close(NAMEDCONF);
system ('rm -f /var/named/chroot/etc/named.conf');
system ('cp /root/named.conf /var/named/chroot/etc/named.conf');
#system ('/etc/rc.d/init.d/named restart');
$restart =`/etc/rc.d/init.d/named restart`;
print "The restart is $restart";
if ($restart =~ /FAILED/) {
print "We have a problem with restart. It was $restart \n\n";
#copy the old file in and try again
#email me
} else {
print "All is fine\n The restart was $restart";
}
if ($aproblem ne "$aproblem" ) {
print "A problem line was $aproblem\n";
}
So, it gets secondary lists from multiple servers, sorts them, checks for
duplicates, injects them into a template file, then copies that to the
named.conf I'm sure there are better ways to do it, but that is what I use
for customer dedicated VPS
----
Ken M
Precision Web Hosting, Inc.
http://www.precisionweb.net
More information about the Blueonyx
mailing list