Rebuild corrupter & missing *.db Zone files

Rebuild corrupter & missing *.db Zone files

The Zone files contain namespace details. By default, they are stored in the named working directory located in /var / named/, and each zone file is named in the zone statement according to the file option.

Usually in a manner that relates to the domain in question and identifies the file as containing zone data such as sample.com.zone.

The named service zone files

/var/named/ The working directory is for the named service. The nameserver is not allowed to write to this directory  
/var/named/slaves/ The directory for secondary zones and is writable by the named service  
/var/named/dynamic/ This is for other files, such as dynamic DNS (DDNS) zones or managed DNSSEC keys. It is writable by the named service.  
/var/named/data/ This is for statistics and debugging files and is writable by the named service.

named.conf sometimes gets corrupted on server cPanel.

Here’s the way cPanel servers repair that:

First, move the corrupted “named.conf” using the command below

root@shadowserver[~]# mv /etc/named.conf /etc/named.conf.bak

Create even a copy of the latest zone data just in case anything goes wrong. You can do that by simply executing the following command line

root@shadowserver[~]# cp -rf /var/named /var/named.backup

Now run the cPanel script to rebuild the named.conf

root@shadowserver[~]# /usr/local/cpanel/scripts/rebuilddnsconfig

This script will rebuild all your files of /var/named/*.db.

First, it pulls every client from /var/cpanel/user and collects every user domain and IP address.

It then collects the first 2 nameservers from /etc/wwwacct.conf and reconstructs the zones as they would be if you were to set up this account already.

==================================================================================

#!/usr/bin/perl
# cPlicensing.net - scripts        Copyright(c) 2003 cPlicensing.net. 
#                                 All rights Reserved. 
# support@cPlicensing.net      http://cPlicensing.net 
# Unauthorized copying is prohibited 
# Version: 0.01 
$nameddir = '/var/named'; 
$cpanelusers = '/var/cpanel/users'; 
$wwwacct = '/etc/wwwacct.conf'; 
print "Rebuild Named Zones Script from cPlicensing.net\n\n"; 
print "MAKE SURE YOU BACKUP YOUR EXISTING $nameddir directory\n"; 
print "Waiting 5 seconds... press ctrl+c to quit\n"; 
sleep 5; 
print "\n\n"; 
opendir(USERS,"$cpanelusers"); 
@CPUSERS=readdir(USERS); 
closedir(USERS); 
print "Grabbing first 2 NameServers from $wwwacct..."; 
open(CONF,"$wwwacct"); 
while(<CONF>) { 
$_ =~ s/\n//g; 
if ($_ !~ /^;/) { 
if ($_ =~ /^NS /) { 
   (undef,$nameserver) = split(/ /, $_); }
 if ($_ =~ /^NS2 /) { 
   (undef,$nameserver2) = split(/ /, $_); }
}
}
close(CONF); 
print "done.\n"; 
print "Rebuilding Zone Files... (cross your fingers)..."; 
foreach $cpusers (@CPUSERS) { 
chomp; 
open(USERDB,"$cpanelusers/$cpusers"); 
while(<USERDB>) { 
if(/IP=/i) { (undef,$ip) = split(/=/, $_, 2); } 
if(/DNS=/i) { (undef,$dns) = split(/=/, $_, 2); } 
chomp($ip); 
chomp($dns); }
createzone(); 
}
 print "Done.\n"; 
 print "\n\nZones have been rebuild but the named.conf has not.\n"; 
 print "use /scripts/rebuildnamedconf to rebuild the named.conf with\n"; 
 print "the new zones.  Note that running /scripts/rebuildnamedconf will not\n"; 
 print "just rebuild the named.conf, you will need to pipe it into the file but\n"; 
 print "also you need to make sure their are no existing zones in it\n"; 
 sub createzone(){ 
 $time=time(); 
 $nameddata = <<EOM; 
 ; cPanel 5.x 
 ; Zone file for $domain 
 @    14400   IN      SOA     $nameserver. hostmaster.$dns. ( 
                         $time      ; serial, todays date+todays 
                         28800           ; refresh, seconds 
                         7200            ; retry, seconds 
                         3600000         ; expire, seconds 
 86400 )         ; minimum, seconds 
 $dns. 14400 IN NS $nameserver. 
 $dns. 14400 IN NS $nameserver2. 
 $dns. 14400 IN A $ip 
 localhost.$dns.   14400    IN A   127.0.0.1 
 $dns. 14400 IN MX 0 $dns. 
 mail    14400        IN CNAME    $dns. 
 www     14400        IN CNAME    $dns. 
 ftp     14400        IN CNAME    $dns. 
 EOM 
 open(VNAMEDF,">$nameddir/$dns.db"); 
 print VNAMEDF $nameddata; 
 close(VNAMEDF); 
}

==================================================================================

Then restart the service “named”.

root@shadowserver[~]#/etc/init.d/named restart

Now we have rebuild corrupter & missing *.db Zone files. If you find any difficulty in fixing feel free to Contact Us.

For latest updates join us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox
Loading

Written by actsupp-r0cks