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
- 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
- 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
- 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 - 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
- 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.