Christophe Casalegno

How to quickly remove a lot of dns zones from bind ?

When you work for a MSP, a hosting company or a cloud operator, sometimes you need to delete a lot of dns zone in one time. If you need to delete 1500 zones with your hand and you keyboard, you ‘ll need week to do the job. So let me show you how you can do this with less efforts 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 on the name for your choice, for example : removezone.sh
Make it executable : chmod +x removezone.sh

It is very simple :

  • rootdir is where are your configuration files
  • conf is your configuration file (example : named.conf or *.conf
  • zonedir is just where your dns zones files are stored (/var/lib/named/master, etc.)

So to delete 1000 zones just put all your zones in a text file like this :

toto.com
tata.com
titi.com

When you have you file, just do a

 cat yourfile.txt |xargs -l ./removezone.sh 
and it will remove all zones in the file. If you just want to delete one zone you can do
./removezone.sh yourdomain.com

Christophe Casalegno
​Vous pouvez me suivre sur : Twitter | Facebook | Linkedin | Telegram | Youtube

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *