Bulk updating DNS zone files

DNS zone files are refreshed by increasing the serial number in the format yyyymmddXX
(e.g 2011070501 eg. 5th July, 2011 and serial number is 01).

In case all of the DNS zone files on the server need to be refreshed, we can increment the serial number, lower the TTLs and reloading the zone files, in one shot:

(A one liner for changing the TTLs of all domains in /var/named to 300, updates the serials to yyyyddmmhh, then reloads the zones)

for i in `grep TTL /var/named/* |grep -v minimum |grep -v 'named\.' |grep -v ns |cut -d ":" -f 2 |cut -d " " -f 2 |grep -v TTL`; do sed -i -e 's#$i#300#g' /var/named/*.db ;done; for i in `grep '[0-9]\{6,\}' /var/named/* |grep serial|cut -d ":" -f 2|cut -d ";" -f 1 | awk '{print $1}'`; do sed -i -e "s#$i#`date +%Y%d%m%H`#g" /var/named/*.db; done;for i in `ls /var/named/ |grep .db|cut -d "." -f 1,2`;do rndc reload $i;done


sed -i -e 's/14400/300/g' -e 's/86400/300/g' -e "s/[0-9]\{10\}/`date +%Y%m%d%H`/g" /var/named/*.db
/etc/init.d/named restart

all set…


I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....