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. :-)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#!/bin/sh # Quick Freeze / Thaw of Reverse Zones # by Jean-Sebastien Morisset (https://surniaulula.com/) case "$1" in f*) action='freeze';; t*) action='thaw';; esac shift case "$action" in freeze|thaw) for ip in $@ do # 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' done ;; *) echo "syntax: $0 [f|freeze|t|thaw] [ip|reverse_zone_file] [...]" exit 1 ;; esac |
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.
1 2 3 4 5 6 7 8 9 10 |
$ 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 |