You want to create a new zone on a name server programmatically.
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 ns1.foo.example. hostmaster.foo.example. ( 2002051200 3600 900 604800 3600 ) IN NS ns1.foo.example. IN NS ns2.foo.example. IN A 10.0.0.1 IN MX 10 mail.foo.example. 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, addzone.pl, is included in the tar file that accompanies this book (see the Preface for details). To run addzone.pl, specify the domain name of the zone and the name of the minimal zone data file as arguments:
# addzone.pl baz.example db.template
addzone.pl 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.
BIND Name Server Configuration
BIND Name Server Operations
Delegation and Registration
Interoperability and Upgrading
Resolvers and Programming
Logging and Troubleshooting