≡ Menu

Shell Script To Create BIND Zone Files

First, you need to customize configuration file as follows.

Sample ns.profile.nixcraft.net configuration file

Define your default TTL, EMAIL ID and other stuff. Also, set your mail server and nameserver IPs using bash array. Save file as follows ns.profile.nixcraft.net:

Add additional records using LoadCutomeARecords(). You can create multiple nameserver configuration file and call it from mkzone.sh.

mkzone.sh: Shell script to create BIND zone file

How do I use this script?

Simply type the command as follows to create a zone file for cyberciti.com domain with as default www IP:
# ./mkzone.sh cyberciti.com ns.profile.nixcraft.net
Sample output:

To save output to a zone file called /var/named/chroot/etc/bind/master/c/cyberciti.com, type:
# ./mkzone.sh cyberciti.com ns.profile.nixcraft.net > /var/named/chroot/etc/bind/master/c/cyberciti.com

{ 7 comments… add one }
  • rodel@lsca.edu.ph April 27, 2012, 12:37 am

    I am receiving error when i type the command
    [root@lsca /]# ./mkzone.sh cyberciti.com ns.profile.lsca.edu.ph
    bash: ./mkzone.sh: Permission denied

    • Germano Pires Ferreira May 4, 2013, 12:22 am

      sorry but… you try …
      # chmod 755 mkzone.sh before execute this script?

  • Rob April 20, 2012, 11:42 am

    I’ve been working on a few scripts to enable adding and removal of records.
    Don’t suppose anything exists already?

  • Pat August 15, 2011, 10:39 pm


    I realize this post is several years old now, but I came across it looking to simplify my life. This script worked perfectly. In an effort to further simply my life however, I added your script to a simple launcher to make the db file, add the zone to named.conf.local, restart bind and run an nslookup on the newly created domain. If you or anyone else that finds this page are interested, I am pasting it below.

    echo -n "==> Enter a new domain name (domain.com): "
    read DOMAIN
    echo -n "==> Enter the IP Address ( "
    read WWWIP
    echo "Setting up files for $DOMAIN at $WWWIP"
    ./mkzone.sh $DOMAIN $WWWIP > /etc/bind/zones/$DOMAIN.db
    echo "Adding zone to named.conf.local"
    echo -e "#Zone for $DOMAIN
    zone 42$DOMAIN42 {
         type master;
         file 42/etc/bind/zones/$DOMAIN.db42;
    " >> /etc/bind/named.conf.local
    echo "Restarting Bind"
    /etc/init.d/bind9 restart
    echo "Running nslookup"
    nslookup $DOMAIN
  • Hello KIng SABRI February 14, 2011, 5:30 pm

    I’m working on a same script i’m onthe satrt i got eveything copied but the editing part is where ibe stuck but i figure it out any way when i need help i ask youhere guys thanks

    nice script any way

    i migh use some of your ideas mr vivek

  • Xenwater October 13, 2010, 5:21 am

    Hi very nice script,

    thank you

  • KING SABRI May 31, 2009, 6:40 am

    Great Mr.Vivek

    I trying to make complete Bind Script (From A-Z)
    – asking to Adding Static IP
    – asking Adding Hostname of server
    – Installing bind
    – configure /etc/named.conf
    – configure /var/named/myZone.zone
    – configure /var/named/myZone.rr.zone

    % I’m still beginner , but I’ll better %

    thank you sir

Security: Are you a robot or human?

Leave a Comment