Add to Favourites Add to Favourites    Print this Article Print this Article

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 u in `ls /usr/local/directadmin/data/users`; do
{
   for i in `cat /usr/local/directadmin/data/users/$u/domains.list; cat /usr/local/directadmin/data/users/$u/domains/*.pointers 2>/dev/null | cut -d= -f1`; 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;
};
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 User domain.list files.

Was this answer helpful?

Also Read