Dev License: This installation of WHMCS is running under a Development License and is not authorized to be used for production use. Please report any cases of abuse to abuse@whmcs.com

Sometimes the DNS/named service on a cPanel web server will have old residual or "unmanaged" zone files for domains that are no longer on the server. It's a good idea to do a cleanup on a cPanel server from time to time, or before migrating to a new server. The zone files should be removed but it's a big task to do this manually. You can use the cPanel autorepair script to assist with this task.

Important:
-This article is intended as guidance for Linux/cPanel server administrators only. This work should only ever be carried out by an experienced server administrator.
- If you have your own web server with Maxer Host, our server management can carry out this work for you. Please contact our support team before attempting anything yourself.
- Whether you are a client of ours or not, please do not attempt any of this work if you are not sure what each command does!
- It is imperative that the cPanel server is NOT part of a DNS cluster when you do this work. If you have not removed it from the DNS cluster, the zone files will be deleted from all servers on the cluster. If you're not sure what this means, do not proceed! 
- If you have ever manually created any zone files only via WHM interface, and they do not exist on cPanel accounts (as main domain, addon domain, alias) then those zone files will be wiped during this work. Therefore, you should not proceed if you are using the cPanel server as a DNS-only setup.

1) Disable DNS clustering via WHM interface

2) Login to SSH as root user

3) Navigate to the /var directory

cd /var

4) Create a tar backup file of the named directory

tar cvpf named-$(date +"%Y-%m-%d").tar named/*
ls -la named*.tar

5) Run the autorepair script to generate a list of unmanaged zone files

/scripts/autorepair unmanaged_zones

6) Let's do a quick count to compare the number of zone files that could potentially be removed versus the number of zone files in the current /var/named/ directory.

We always find this interesting. For example if there are 10,000 zone files to be removed and the /var/named directory contains 10,500 zone files, then the server will have 500 zone files at the end of this work.

wc -l /etc/unmanaged_zones
ls -la /var/named/*.db | wc -l

6) Open the file located at /etc/unmanaged_zones with your favourite text editor (vi or nano), and review the list of zone files to be removed.

nano /etc/unmanaged_zones

7) Remove the lines for any zones that should be removed from the server.

As cPanel explain: "Zone names listed in that file indicate that the zone should be on the server, even though it is not associated with a local cPanel account, and will be retained. Remove the zone names that you would like to be deleted."

If you are happy to remove ALL the zone names listed in the file, you can null/empty the file using this command:

: > /etc/unmanaged_zones

8) Next run the cPanel script to remove all the old/unmanaged zone files.

It will list the zone files to be removed and ask for your confirmation.

/scripts/unmanaged_zones

9) That's the work done.

You might want to check the number of zone files in the /var/named directory now:

ls -la /var/named/*.db | wc -l

It should be the difference between the two numbers we found in step 6, right?

10) Re-enable DNS clustering via WHM and enjoy the rest of the day.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution