Skip to content

Instantly share code, notes, and snippets.

@kevin39
Forked from brycied00d/gist:13483a1d8363e457f963
Last active September 20, 2016 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevin39/9902b422e60a909938fb2f94bf2880c4 to your computer and use it in GitHub Desktop.
Save kevin39/9902b422e60a909938fb2f94bf2880c4 to your computer and use it in GitHub Desktop.
pfSense DNS Forwarder Batch Host Creation
<?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();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment