How To Edit a DNS Zone File Via the CLI

This article provides a guide for how to edit a DNS zone file via CLI. This guide assumes root-equivalent access to cPanel VPS or cPanel dedicated server.

How To Edit a DNS Zone File Via the CLI

Making manual edits to a DNS zone is a multiple-step process, if not done correctly it can result in the changes made not going into effect.

Procedure

  1. First, you should make a backup of any zones you plan on editing, if you need to make a copy of all the zones you can create a backup to /var/named-backup using the following command:
    cp -av /var/named /var/named-backup

  2. Next, open the zone file with your desired command line editor, the zone files are located in /var/named and end with the .db extension. After making the desired change to your zone, the serial must be updated. An increased serial indicates that a DNS zone has been changed. Simply increasing the number by one digit is sufficient. An example of the serial from a DNS zone can be seen here:
    2024101502 ;Serial Number
  3. After making the change you can confirm the zones syntax with named-checkzone, if it returns ok you can proceed to reload the zone, otherwise the errors in the zone must be addressed. With named-checkzone you use the domain name, followed by the full path to the DNS zone:
    [root@host ~]# named-checkzone example.tld /var/named/example.tld.db
    zone example.tld/IN: loaded serial 2023062201
    OK
  4. After updating the serial  your DNS server must reload the zone, depending on the name server used the command will vary:

    PowerDNS:

    pdns_control bind-reload-now example.tld

    Bind:

    rndc reload
  5. Lastly, if using DNS cluster with cPanel initiate a sync for the modified zone:
    /scripts/dnscluster synczone example.tld

Conclusion

You now know how to edit a DNS zone file via CLI.

  • dns, dns zone
  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

Guide to Domain EPP Status Codes

EPP Status Codes are used by the Domain Registry to signify the status of a particular domain...

Addon Domain Vs Alias Domain

The table below lists some key characteristics of Addon Domain and Alias Domain....

Disable Network Manager on CentOS 7

This article will provide the steps to disable Network Manager in CentOS 7. Network Manager is...

Disable Network Manager on CentOS 6

This article will provide the steps to disable Network Manager in CentOS 6. Network Manager is...

Video: How to Setup Domain Redirects in cPanel

This video tutorial provides Step-by-Step instructions how to setup domain redirects in cPanel...