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.

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

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!


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.

    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`
    sed -i “s/$OLD/$NEW/g” $file
    echo “fixed $file”

  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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: