When you work for an MSP, a hosting company or a cloud operator, sometimes you need to delete a lot of DNS zones at once. If you need to delete 1,500 zones by hand, with your hands and your keyboard, you’ll need a week to do the job. So let me show you how to do this with less effort on a Linux Bind server with the power of the shell :
!/bin/sh
rootdir="/var/bind9/chroot/etc/bind"
zonedir="/var/bind9/chroot/etc/bind/master"
conf="*.conf"
zone=$1
sed -e "/^zone \"$zone\" {/,/^};$/ d" -i $rootdir/$conf
rm $zonedir/$zone.hosts
You can save this file under a name of your choice, for example: removezone.sh
Make it executable : chmod +x removezone.sh
It is very simple:
- rootdir is the directory containing your configuration files
- conf is your configuration file (for example, named.conf or *.conf)
- zonedir is where your DNS zone files are stored (/var/lib/named/master, etc.)
So, to delete 1,000 zones, just put all your zones in a text file like this:
toto.com
tata.com
titi.com
When you have your file, just run
cat yourfile.txt |xargs -l ./removezone.sh ./removezone.sh yourdomain.comChristophe Casalegno
You can follow me on: Twitter | Facebook | Linkedin | Telegram | Youtube

Leave a comment
Add a comment