How to Reset DNS Zones for All Domains on a cPanel Server

There is a regular way to reset the DNS zone of each domain name from the WHM interface. However, it can be difficult and time-consuming to reset DNS zones one by one for all domains on the server through WHM.

Therefore, we recommend using the following command-line method to reset all DNS zones easily.

Before proceeding, make sure that screen is installed on your server. Running the process inside a screen session helps prevent interruption if your SSH session disconnects.

Install Screen

On CentOS/CloudLinux/RHEL:

yum install screen -y

Or on newer AlmaLinux/RockyLinux systems:

dnf install screen -y

Start a Screen Session

screen -S dnsreset

Reset DNS Zones for All Domains

Run the following command:

for i in $(cat /etc/trueuserdomains | cut -d: -f1); do
    echo "Resetting DNS zone for: $i"
    whmapi1 resetzone domain=$i
done

This command will automatically reset the DNS zone for all primary domains hosted on the server.


Reset DNS Zones Including Addon, Parked, and Subdomains

If you also want to reset DNS zones for addon domains, parked domains, and subdomains, use the following method.

Install jq

The command below requires jq for JSON parsing.

yum install jq -y

Or:

dnf install jq -y

Run the Advanced DNS Reset Command

for user in $(ls /var/cpanel/users); do
    domains=$(uapi --user="$user" --output=json DomainInfo list_domains 2>/dev/null | \
    jq -r '
        .result.data.main_domain,
        .result.data.addon_domains[],
        .result.data.parked_domains[],
        .result.data.sub_domains[]
    ' 2>/dev/null | sort -u)

    for domain in $domains; do
        [ -n "$domain" ] || continue
        echo "Resetting DNS zone for: $domain"
        whmapi1 resetzone domain="$domain"
    done
done

This method retrieves all domains associated with each cPanel account and resets their DNS zones automatically.


Rebuild and Restart DNS Services

After resetting DNS zones, it is recommended to rebuild the DNS configuration and restart the DNS service.

/scripts/rebuilddnsconfig
/scripts/restartsrv_named

Verify Domains Before Resetting

To preview all primary domains before running the reset:

for user in $(ls /var/cpanel/users); do
    grep '^DNS=' /var/cpanel/users/$user | cut -d= -f2
done

To inspect domains for a specific user:

uapi --user=username --output=json DomainInfo list_domains | jq
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Domain names are not showing in WHM

We were unable to see any domains listed under WHM -> List Accounts. However, we can see the...

How to Start/Stop or Restart Apache server

Apache is the HTTP server that is freely available over the internet. It is a kind of software or...

How to install Attracta SEO Tools plugin

RequirementscPanel/WHM needs to be installed on your server. Step 1: SSH into your server and go...

How to Install CpCleaner in cPanel through SSH?

Installation Run the following shell commands as root via SSH: wget -O cpc-1.0.3.tar...

How to Secure a cPanel/WHM Web Server

Here are a few basic steps that you should keep in mind for keeping a server secure. 1) Strong...