/var/named empty recreate .db files

RackSystems

Verified User
Joined
Oct 4, 2004
Messages
50
Location
Deventer, The Netherlands
One of my clients erased al the .db files in /var/named on his server. DA still shows this domains in the list but you can't view or edit them. Is it possible to recreate all the .db files?

I already did:
echo "action=rewrite&value=named" >> /usr/local/directadmin/data/task.queue

but that didn't help
 
Hello,

There isn't an easy way to do this.
If I had to do it, I would create a script to do it for me.

eg, fix.sh:
Code:
#!/bin/sh
DIR=/var/named
IP=[b]1.2.3.4[/b]
for i in `cat /etc/virtual/domains`; do
{
     FILE=$DIR/${domain}.db

     echo "Creating DB file for ${domain} in ${FILE}";

     echo "\$TTL 14400" > $FILE;
     echo "@       IN      SOA     ns1.${domain}.      root.${domain}. (" >> $FILE;
     echo "                      2007051103" >> $FILE;
     echo "                      14400" >> $FILE;
     echo "                      3600" >> $FILE;
     echo "                      1209600" >> $FILE;
     echo "                      1209600" >> $FILE;
     echo "                      86400 )" >> $FILE;
     echo "${domain}. 14400 IN NS ns1.${domain}." >> $FILE;
     echo "${domain}. 14400 IN NS ns2.${domain}." >> $FILE;
     echo "* 14400 IN A $IP" >> $FILE;
     echo "${domain}. 14400 IN MX 10 mail.${domain}." >> $FILE;

};
done;
Put that into a file, save the file, chmod the file to 755, then run it.

It will create all zones from scratch.
If you've already fixed some manually, back them up and restore them after, because.. it will overwrite them.
This is a very basic zone that uses a wildcard for A records, so will get things going quicker, but you may want to swap the records back to normal ones. (eg, remove the * and replace with www, pop, ftp, mail, smtp, subdomains, etc)

Replace 1.2.3.4 with the IP of your domains.
If you have domains on different IPs, then you'll have to tweak them manually.

John
 
since we don't know what the actual nameservers are perhaps,
any script needs to:

1. get each domain's nameservers by using (taking yahoo.com as an example)

dig yahoo.com ns +short

2 for each line returned above, if the nameserver is based on the
domains, get the A record, so assuming this is ns1.yahoo.com

dig ns1.yahoo.com a +short

obviously in a script we'd rewrite all of these using variables,
i.e. ${domain} etc.

3. find the domain's own IP:

dig ${domain} a +short


i.e. if a.com has nameservers ns1.a.com and ns2.a.com
we need to ultimately write the 4 ns-related records:

a.com. 14400 IN NS ns1.a.com.
a.com. 14400 IN NS ns2.a.com.
ns1 14400 IN A 111.222.333.444
ns2 14400 IN A 111.222.333.555

using dummy IP addresses etc.

if a.com has nameservers ns1.b.com and ns2.b.com we only need to write the 2 ns-related records:

a.com. 14400 IN NS ns1.b.com.
a.com. 14400 IN NS ns2.b.com.

If there aren't many domains, you can do as in the previous post,
then edit them by hand. If you've many domains, that'd take
too much time.

any zone files created by hand (i.e. for parking) would have to be re-created by hand, assuming you've a list of them somewhere ...
 
I'd use what John calls the long version.

For example, unless I'm reading something wrong, Johns example creates ns1 and ns2 for the domain in question... and if that's so, then those nameservers need to be registered at the domain registrars to avoid errors for anyone who looks up the domains in for example, dnsreport.com.

And you won't get an A record answer for ns1.example.com, ns2.example.com, or mail.example.com.

Why?

Because a host/domain listed with ANY type of record in a zone file is NOT covered by an overall wildcard record in that zone.

If you don't fully understand the ramifications of wildcards in DNS then you probably shouldn't use them.

Jeff
 
That script is very minimal. You can make changes as needed. The bulk of the extra data would be in /usr/local/directadmin/data/users/username/user.conf .. and you'd have to grab the user by doing a lookup in /etc/virtual/domainowners with the domain.

Might even be easier to go (pseudo code)
for each user in /usr/local/directadmin/data/users
for each domain in ./domains.list
use the user.conf and the domain to create the zone.

John
 
No issues, John. I've just seen so many people shoot themselves in the foot (sometimes both feet ;) ) with wildcards, that I like to bring out the issues.

The best place to get the nameservers is probably to look them up this way:
Code:
dig +trace example.com ns | tail -4| grep NS
That's worked for the few examples I've just tried.

Jeff
 
Code:
#!/bin/sh
DIR=/var/named
IP=1.2.3.4
for [B][COLOR="Red"]domain[/COLOR][/B] in `cat /etc/virtual/domains`; do
{
FILE=$DIR/${domain}.db

echo "Creating DB file for ${domain} in ${FILE}";

echo "\$TTL 14400" > $FILE;
echo "@ IN SOA ns1.${domain}. root.${domain}. (" >> $FILE;
echo " 2007051103" >> $FILE;
echo " 14400" >> $FILE;
echo " 3600" >> $FILE;
echo " 1209600" >> $FILE;
echo " 1209600" >> $FILE;
echo " 86400 )" >> $FILE;
echo "${domain}. 14400 IN NS ns1.${domain}." >> $FILE;
echo "${domain}. 14400 IN NS ns2.${domain}." >> $FILE;
echo "* 14400 IN A $IP" >> $FILE;
echo "${domain}. 14400 IN MX 10 mail.${domain}." >> $FILE;

};
done;
 
Back
Top