Quick Freeze / Thaw of Reverse Zones

I had to update several reverse zone files today, so wrote a quick for-loop in bash to freeze and thaw all the zones. The script parsed the zone file names and reversed them into a proper `d.c.b.a.in-addr.arpa` format. Later I tweaked it with sed to make it more flexible (in order to pass it a full or partial IP address), but ended up using `tac` for the reversing part instead – that’s what it’s made for after all. And if you’re wondering what `tac` stand for, just read `cat` backwards. :-)

# Quick Freeze / Thaw of Reverse Zones
# by Jean-Sebastien Morisset (https://surniaulula.com/)
case "$1" in
	f*) action='freeze';;
	t*) action='thaw';;
case "$action" in
		for ip in $@
			# remove path (if any), db filename prefix (if any), and reverse ip address
			addr="`echo $ip. | sed -e 's/^\(.*\/\)//' -e's/^\(db\.\)*//' | tac -s '.'`in-addr.arpa"
			echo -e "$action $ip - \c"
			rndc $action $addr && echo 'done'
		echo "syntax: $0 [f|freeze|t|thaw] [ip|reverse_zone_file] [...]"
		exit 1

Here’s an example of it’s use. You can give it a full or partial IP, and/or one or more zone filenames with or without shell wildcards.

$ rndc-upd-addr.sh
syntax: ./rndc-upd-addr.sh [f|freeze|t|thaw] [ip|reverse_zone_file] [...]

$ rndc-upd-addr.sh f 10.0.1
freeze 10.0.1 - done

$ rndc-upd-addr.sh t /var/named/master/db.10.0.*
thaw /var/named/master/db.10.0.1 - done
Find this content useful? Share it with your friends!