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


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DNS

How to re-add all zone entries into the named.confLast Modified: Dec 12, 2013, 3:35 am
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.

2003 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST