Bulk Zone file Serial Number Increment

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 myBIND 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!

Advertisements

Tags: , ,

3 responses to “Bulk Zone file Serial Number Increment”

  1. Jonas says :

    Or use http://blogbackupr.com for blog backup

  2. /clodel says :

    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 “200[0-9][0-9][0-9]*” $file`
    NEW=$(($serial))
    sed -i “s/$OLD/$NEW/g” $file
    echo “fixed $file”
    fi
    done

  3. Paul says :

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: