Creating a Zone Programmatically

5.27.1 Problem

You want to create a new zone on a name server programmatically.

5.27.2 Solution

Create a minimal zone data file that uses only relative domain names in the owner field of the records. For example:

$TTL 86400
@ IN SOA (
 3600 )



 IN MX 10

www IN CNAME @

Then write a script to add a new zone statement to the name server's named.conf file, referring to the zone data file. Finally, use rndc reconfig or ndc reconfig, as appropriate, to tell the name server to reread named.conf.

An example script,, is included in the tar file that accompanies this book (see the Preface for details). To run, specify the domain name of the zone and the name of the minimal zone data file as arguments:

# baz.example db.template

5.27.3 Discussion is fairly simple-minded: it assumes its working directory is the name server's working directory. And I'm sure some Perl hacker could replace it with a single-line script.

5.27.4 See Also

Section 1.16 for configuring a name server as the primary master for a zone, and Section 5.7 for adding a zone without restarting the name server.

Getting Started

Zone Data

BIND Name Server Configuration

Electronic Mail

BIND Name Server Operations

Delegation and Registration


Interoperability and Upgrading

Resolvers and Programming

Logging and Troubleshooting


DNS & BIND Cookbook
DNS & BIND Cookbook
ISBN: 0596004109
EAN: 2147483647
Year: 2005
Pages: 220
Authors: Cricket Liu © 2008-2020.
If you may any questions please contact us: