1. Home
  2. Domains & DNS
  3. How do I export a zone file for my domain?

How do I export a zone file for my domain?

A zone file for a domain contains all DNS entries for said domain (i.e. information about where the domain and its subdomains point, whereto incoming email should be delivered, and so on).

There are cases where you need to get your hands on a zone file for a domain, e.g. if you’re about to change DNS provider. To download a zone file requires using SSH or the cPanel terminal, since there is no graphic interface for this.

You have to logged in on the web hosting account where the domain resides to follow these instructions.

So, log in via SSH through a client on your computer or via the terminal which you find through cPanel (if you do not know how, please refer to this guide). Then, copy the command below, swapping out domain_name for the correct domain name, and run it (you shouldn’t be required to do any changes to the command except entering the correct domain name). Once the command is run you will get a text file named domainname_zonefile.txt (where “domainname” will be replaced by the domain name you entered in the command). The file will end up in the document root for your account.

DOMAIN=domain_name; cpapi2 ZoneEdit fetchzones --output=json | jq --arg domain "$DOMAIN" -r '.cpanelresult.data[].zones[$domain][]' > ~/${DOMAIN}_zonefile.txt

If you enter a domain name which isn’t set up on your web hosting account, you will get an error message:
jq: error (at :1): Cannot iterate over null (null)

When you’ve run the command (and haven’t got any error messages) you may download the file domainname_zonefile.txt and hand it over to the new DNS provider. You can download it via cPanel’s File Manager or via FTP.

Was this article helpful?

Related Articles