Bind 8 Zone Creation Script

Bill Larson wllarso at swcp.com
Fri Jun 29 15:37:24 UTC 2001


> I want to take a text file such as
> 
> domain1.com
> domain2.com
> 
> and turn it into a named .conf file just inserting the domain names into the
> appropriate places.

Try a simple shell script.  I'm writing this off the top of my head, so
check it out completely before doing anything permanent.  Here goes:

	#/usr/bin/sh
	
	for zone in `cat $1`; do
	  echo "zone \"$zone\" {"
	  echo "\ttype master;"
	  echo "\tfile \"db.$zone\";"
	  echo "};"
	  echo ""
	done

where "\t" is a tab character.

When this script is run given the name of the file that lists the
zones, you would get:

	zone "domain1.com" {
		type master;
		file "db.domain1.com";
	};

	zone "domain2.com" {
		type master;
		file "db.domain2.com";
	};

You can take the output of this script and append it to the end of your
named.conf file.  Remember that you will also have to create 800 zone
files to go with this.  For this task, if everything is identical
(i.e., you are only dealing with 800 zones with the only difference is
the $ORIGIN), you could use one common zone file and replace the 'echo
"\tfile \"db.$zone\";"' with 'echo "\tfile \"db.common\";"'  Or, as
suggested earlier, use the "$INCLUDE" directive in 800 zone files to
keep most of your information in one common file.

I'm sure that there are at least a thousand different ways that this
can be done.  I can easily see using a "sed" script, or "perl", or if
I'm really desperate, even a C program.

By the way, if you want 800 separate zone files, you can also use a
similar script to create these files too.  (But don't ask, this is left
as an exercise for the student.)

Now, after providing this script, which took just a minute to create,
I'd like to make a, hopefully gentle, rebuke to groups that believe
that they are capable of managing 800 domains.

It seems to me that if you cannot write something to generate 800
almost identical zone statements, are you positive that you are capable
of managing 800 different zones?  I'm not trying to be a horses a**,
but considering your apparent capability level, your goal bothers me.

Bill Larson


More information about the bind-users mailing list