Skip to content

Instantly share code, notes, and snippets.

@brycied00d
Last active July 26, 2016 13:35
Show Gist options
  • Save brycied00d/13483a1d8363e457f963 to your computer and use it in GitHub Desktop.
Save brycied00d/13483a1d8363e457f963 to your computer and use it in GitHub Desktop.
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();
?>
@brycied00d
Copy link
Author

No it's not as "optimised" as it could be - it's a quick and dirty script. I spent more time documenting it and cleaning up the "configurability" than I did writing it in the first place. But I wanted to store this and share it publicly, so there you go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment