Bulk Zone file Serial Number Increment

written by admin on January 18th, 2008 @ 01:25 AM

I have way too many domain names, so that means that when I want to make a change to my zone template files including a search and replace for certain ips or just changing the email in the zone like I do below. (Or whatever you need to do.)

I first backed up my zone files with a basic but effective cp command:

blah@server ~# cp /var/named /var/named-backup

Then I replaced my email with one that would handle the spam and put it in the right mailbox (/dev/null.) :)

blah@server ~# for file in $(ls /var/named/*.db); do sed -i "s/paul.mydomain.com/dns.omniop.com/g" $file; done

Now that all of the zone files are updated, even if I were to restart my named, the files would not update my slave DNS servers because the serial number in the zones have not changed.

...
2008011502    ; serial, todays date+todays
...

So here is a quick little shell script that I wrote that increments all of my BIND zone files for my DNS server.

#!/bin/bash
for file in $(ls /var/named/*.db);
do
  if [ -f $file ];
  then
    OLD=`egrep -ho "2008[0-9]*" $file`
    NEW=$(($OLD + 1))
    sed -i "s/$OLD/$NEW/g" $file
    echo "fixed $file" 
  fi
done

There may be a better way of doing this, but I found this very quick and painless.

Now I will hopefully get less spam now that the DNS email scrapers won’t get my email from my zone files.

Hope this helps someone!

Comments

  • /clodel on 11 Mar 04:37

    Perhaps this one is better.

    !/bin/bash

    serial=`date +%Y%m%d%H` for file in $(ls /var/named/.db); do if [ -f $file ]; then OLD=`egrep -ho “2000-9[0-9]” $file` NEW=$(($serial)) sed -i “s/$OLD/$NEW/g” $file echo “fixed $file” fi done

  • Paul on 21 Mar 01:40

    Good point clodel. updating the serial to the current date is a better idea.

Comments are closed

Options:

Size

Colors