romacities

Member
Sep 10, 2010
7
0
51
Denver, CO
cPanel Access Level
Root Administrator
Under:
Main >> DNS Functions >> Reset a DNS Zone
There's a list of domains which I can click and reset to default current DNS settings.

Is there an automated way to reset all domains at once?

thanks.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
This could be done with two commands in command line. One to kill the DNS zones and one to add the DNS zones. I'm only selecting the domains in /etc/trueuserdomains, which are the main domains. The issue here is going to be that subdomains will be yanked when doing this. You might change to grabbing the list from /etc/localdomains instead without the cut portion. Before doing this, a backup must be made of /var/named and /etc/named.conf:

Code:
cp -R /var/named /var/named.bak110826
cp -R /etc/named.conf /etc/named.conf.bak110826
The commands would then be to remove and readd the zones:

Code:
for i in `cat /etc/trueuserdomains | cut -d: -f1` ;do /scripts/killdns $i ;done
for i in `cat /etc/trueuserdomains | cut -d: -f1` ;do /scripts/add_dns --domain=$i ;done
I would highly suggest first running "/scripts/killdns domain.com" for one account, then "/scripts/add_dns --domain=domain.com" for that same account to see the results to ensure they are what you want before proceeding.

Please note that you could load the list from a precompiled list of domains instead also, then use `cat /root/domainlist` instead of reading from /etc/trueuserdomains. This way you can control what domains are being touched.
 

lukapaunovic

Well-Known Member
Jul 29, 2012
51
0
56
Užice, Serbia
cPanel Access Level
Root Administrator
I urge admins/moderators to merge my reply to this thread: DNS Zone Reset ALL


Since solution @cPanelTristan posted doesn't work anymore I found a working one. Because add_dns and adddns script produces this:

Code:
/scripts/adddns --overwrite --ip 192.168.1.1 --domain mydomain.com --owner username
Sorry, you can not add a DNS record for a subdomain of another user’s domain.

Even with all correctly specified arguments. Probably because of absolute use of the API.

So I finally succeeded using command line API like specified here

First, of course, make backup and remove your zones like @cPanelTristan suggested.

Then replace 192.168.1.1 with your main shared IP and run this:

Code:
data=$(cat /etc/trueuserdomains | tr -d ' ')
ip="192.168.1.1"
for i in $data ;do
domain=$(echo $i | awk -F':' '{print $1}')
owner=$(echo $i | awk -F':' '{print $2}')

echo ;
echo Creating zone $domain on $owner;
whmapi1 adddns domain=$domain trueowner=$owner ip=$ip
echo ;
done