J Cornelius

Bulk Zone File Maker

If you've ever had to create a bunch of zone files for a bunch of domains you know it can be a pain. Should you ever find yourself in that dark hole again use this. It is a quick and simple DNS Zone File creator for BIND. It takes an array of domain names, creates zone files and adds the zones to your master BIND configuration. All you need to do is put the domains in the array and restart Bind when it's done.

<?php /** * makeZones.php * * Creates DNS zone files for multiple domains. This was written for BIND * and uses it's default locations for config and zone files. You could do * this all by hand, but this is faster, especially for a lot of domains. * * You will need to enter the domains that need to be created in BIND, and * change the zone file template below with the correct IP address and * hostname for your BIND server * * @author J. Cornelius * */ //--> create the serial according to RFC1912 2.2 $serial = date("Ymj")."01"; //--> change these domains to the ones you need to create zone files for $domains = array("newdomain.com","anothernewdomain.com"); foreach($domains AS $domain) { $zone = <<<ZONEFILE $ttl 38400 $domain. IN SOA yourdomain.com. admin.yourdomain.com. ( $serial 10800 3600 604800 38400 ) $domain. IN NS yourdomain.com. $domain. IN A 127.0.0.1 www.$domain. IN CNAME $domain. ZONEFILE; $confdata = <<<CONFFILE zone "$domain" { type master; file "/var/named/$domain.hosts"; }; CONFFILE; //--> write the zone file to the server $file = fopen("/var/named/$domain.hosts","w"); fwrite($file,$zone); fclose($file); //--> add the new zone to the BIND config file $conf = fopen("/etc/named.conf","a"); fwrite($conf,$confdata); fclose($conf); } //--> end foreach loop exit; ?>
Published: Short URL: http://jc.cm/34/
Bookmark using Delicious Share on Tumblr Share on Posterous