ARLIAN
11/11/2014 - 11:56 PM

pfSense DNS Forwarder Batch Host Creation For "dot${lastoctet}" Naming Schemes - Tested on pfSense 2.1.5

pfSense DNS Forwarder Batch Host Creation For "dot${lastoctet}" Naming Schemes - Tested on pfSense 2.1.5

<?php
// pfSense PHP script to generate a range of DNS forwarder hosts based on
// "dot${lastoctet}", eg. 192.0.2.100 == dot100.example.com
// Open terminal, run "php" copy/paste script with the following defines tweaked
// Ctrl-D, wait a moment until you see "Content-type: text/html"
// Open the DNS config in the web UI and click Apply Changes 

define('DOT_DOMAIN', 'example.com');
define('DOT_SUBNET', '192.0.2.'); // Leave off the final octet, include the dot
define('DOT_RANGE_START', 100);
define('DOT_RANGE_STOP', 200);

require_once("functions.inc");

function hostcmp($a, $b) {
  return strcasecmp($a['host'], $b['host']);
}

foreach(range(DOT_RANGE_START, DOT_RANGE_STOP) as $num)
{
  $config['dnsmasq']['hosts'][] = array(
    'host' => 'dot'.$num,
    'domain' => DOT_DOMAIN,
    'ip' => DOT_SUBNET.$num,
    'descr' => '',
    'aliases' => '' );
}
usort($config['dnsmasq']['hosts'], "hostcmp");
mark_subsystem_dirty('hosts');
write_config();
?>