How to Bulk edits to your DNS Zones for vps?

There might be situation when you want to bulk edit your dns zone on direcadmin, cpanel or any other control panel but don’t know where to or how to start. Here are a simple step by step guide for you to bulk modify your dns zone.

Step 1:Backup your DNS ZONES

 cp -rf /var/named{,.backup}

This will create directory named.backup inside /var directory which contains backup of your dnsĀ 

Step 2:Edit DNS ZONE

  oldns="ns1.olddomain.tld"; newns="ns1.newdomain.tld" ; find /var/named/*.db -exec perl -pi -e "s/(?<=IN\s\NS\s)$oldns/$newns/g" '{}' \; 

Replace the nameservers used. In the following examples, we will use ns1.olddomain.tld and ns2.olddomain.tldas the current nameservers, and ns1/2.newddomain.tldfor the updated records, be sure to update the oldns and newns variables.

Run the command a second time for nameserver 2 (ns2)

Step 3:Update the serial records for all modified DNS zones:

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

Step 4:Restart the DNS service

For cPanel command

  /scripts/restartsrv_named 

For Directadmin command

  service named restart 

That’s all

Share

You may also like...

Leave a Reply

Your email address will not be published.