Mass removal of an NS record from all zones, using perl


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DNS

Mass removal of an NS record from all zones, using perlLast Modified: Oct 22, 2015, 11:57 pm
If you need to remove an NS record from all zones quickly, perl can be useful.
Let's assume you want to remove all NS records with the value ns1.domain.com. from all zones.

  1. First, make a backup of all of your zones, just in case something goes wrong:

    cd /var/named
    tar cvzf /root/dns_backup.tar.gz *

  2. Next run the following code:

    perl -pi -e 's#^.*NS\s+ns2\.domain\.com\.\n##' *.db

    taking note of the  character before all literal period characters in the NS value.
  3. Lastly, you'll need to update the serial on all zones:

    echo "action=rewrite&value=named" >> /usr/local/directadmin/data/task.queue
    /usr/local/directadmin/dataskq d400

NOTE A zone must have at least one NS record, or it will not be loaded.

Be sure to check inside a few random zones to ensure it worked.
Check /var/log/messages for any named errors after it gets reloaded.

2003 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST