This article provides a guide for how to update multiple DNS zones with find and replace (sed). This guide is intended for WHM cPanel VPS and dedicated server administrators.
How to Update Multiple DNS Zones with Find and Replace (sed)
We can use sed (a find and replace command line tool) to quickly replace all instances of a specific string in DNS zones with another string.
For example, if several DNS zones are using the NS value 'ns1.servername.us' but you want to replace it with 'ns1.serverprovider.net', then this would be a perfect application of this tool.
To update multiple DNS zones with find and replace using sed, follow the steps below:
- Login via SSH as root.
- Run the following commands:
cd /var cp -R named named.backup060924 sed -i 's/ns1.servername.us/ns1.serverprovider.net/g' /var/named/*.db sed -i 's/ns2.servername.us/ns2.serverprovider.net/g' /var/named/*.db sed -i 's/2024060601/2024060921/g' /var/named/*.db systemctl restart named systemctl status named
These commands will take a full backup of the 'named' directory, replace every instance of 'ns1.servername.us' with 'ns1.serverprovider.net' and every instance of 'ns2.servername.us' with 'ns2.serverprovider.net', update the zone serial numbers, and restart named.
Conclusion
You now know how to update multiple DNS zones with find and replace, using sed.