How to re-add all zone entries into the named.conf

If your system already has all of the domain.com.db zone files, but the named.conf is missing zone entries for those db files, you can use the following script to re-add them to the named.conf.

This assumes that DA is already installs, as it grabs the named.conf and db file paths from the directadmin binaries.

Create a fix.sh script somewhere, and fill it with the following code:

#!/bin/sh

NAMED_PATH=`/usr/local/directadmin/directadmin c | grep nameddir | cut -d= -f2`
NAMED_CONF=`/usr/local/directadmin/directadmin c | grep namedconfig | cut -d= -f2`

if [ ! -s $NAMED_CONF ]; then
echo "Cannot find $NAMED_CONF. Aborting";
exit 1;
fi

if [ ! -d $NAMED_PATH ]; then
echo "Cannot find directory $NAMED_PATH. Aborting";
exit 2;
fi

for i in `cat /etc/virtual/domains`; do
{
echo -n "Checking $i ... ";

COUNT=`grep -c "zone \"$i\"" $NAMED_CONF`
if [ "$COUNT" -gt 0 ]; then
echo "Already exists. Skipping";
continue;
fi

echo "";
echo "*** Adding $i to ${NAMED_CONF}";
echo "zone \"${i}\" { type master; file \"${NAMED_PATH}/${i}.db\"; };" >> ${NAMED_CONF}

DBFILE=${NAMED_PATH}/${i}.db
if [ ! -s ${DBFILE} ]; then
echo "Warning: Cannot find ${DBFILE}";
fi

};
done;
exit 0;

chmod the script to 755, and run it.
It can be run multiple times. It checks the named.conf to ensure the domain doesn't already exists.

The domain values are taken from the local /etc/virtual/domains file.


Was this article helpful?

mood_bad Dislike 1
mood Like 1
visibility Views: 43525