cPanel :: Change nameservers for all zone files using command line

Sometimes in cases like migration its needed to change the nameservers for all sites / zones to newer ones. Here the cPanel does not provide any option to do so.

Here is way we can do it by command line :

First and most important backup the Zone files :

cp -r /var/named /var/named.backup

Using below you can replace the nameservers under all zone files :

sed -i 's/ns1.old.com/ns1.new.com/g' /var/named/*.db

OR

replace   "ns1.old.com"  "ns1.new.com" -- /var/named/*.db

Now its necessary to update the serials under each zone files to make the changes take effect.

find /var/named/*.db -mtime -1 -exec perl -pi -e 'if (/^\s+(\d{10})\s+;\s+serial/i) { my $i = $1+1; s/$1/$i/;}' '{}' \;

Check the DNS service first :

systemctl status pdns

Now restart the service to load the changes :

systemctl restart pdns

Make sure to update the new nameservers under Basic Settings too.

Finally you need to update nameserver IP’s under cpanel using below command :

/scripts/updatenameserverips

Leave a Comment