Bulk edits to your DNS Zones Print

  • 0

Introduction

You may need to make bulk changes to your DNS zones, which is not currently supported through the DNS Zone Editor. For example, when changing your domains to point to a new set of private nameservers.

If your DNS zones have no customizations, you can edit the DNS Zone Template and then reset the DNS zone to apply the changes. However, this is not practical in all cases because zones may have customizations, and this will remove those customizations.

 

Procedure

Experienced system administrators should explore manually editing all DNS Zones from the command lineFor instance, if you want to update the nameservers in all DNS zones from ns1.example.com and ns2.example.com to ns1.example.net and ns2.example.net, you could do so using customized sed and find Linux commands after backing up all zones in the /var/named/ directory.

SafeAdmin Certified system administration service providers are listed on the SafeAdmin Certified Services page for your convenience. 

The following is an example of the procedure to change nameservers for all domains using the command line.

We strongly recommend backing up all DNS zones prior to making bulk changes. It is the responsibility of the administrator performing these changes to ensure that all commands are run correctly.

  1. To back up all zones, run the following command:
    cp -rfp /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

Was this answer helpful?
Back

Send Message