Bulk edits to your DNS Zones

From Wiki
Jump to navigation Jump to search

1. To back up all zones, run the following command:

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

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

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

3. Run the command a second time, substituting ns1 for ns2.

4. To update the SOA record, run the following command. The SOA record will contain your ns1 nameserver's name, so ensure the variables are updated appropriately.

oldns="ns1.olddomain.tld"; newns="ns1.newdomain.tld" ; find /var/named/*.db -exec perl -pi -e "s/$oldns/$newns/g if /SOA/" '{}' \;

5. 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/;}' '{}' \;

6. Restart the DNS service to apply changes:

/scripts/restartsrv_named

7. Verify that the zones were updated correctly.

8. (Optional) If DNS Clustering is enabled, sync all zones:

/scripts/dnscluster syncall