Shell Script To Create BIND Zone Files

Posted on in Categories Domain last updated March 24, 2009

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 202.54.1.2 as default www IP:
# ./mkzone.sh cyberciti.com 202.54.1.2 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 202.54.1.2 ns.profile.nixcraft.net > /var/named/chroot/etc/bind/master/c/cyberciti.com

7 comment

  1. Hi,

    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.

  2. 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
    thanks

  3. 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

Leave a Comment