Forked from brycied00d/gist:13483a1d8363e457f963
Last active
September 20, 2016 12:25
-
-
Save kevin39/9902b422e60a909938fb2f94bf2880c4 to your computer and use it in GitHub Desktop.
pfSense DNS Forwarder Batch Host Creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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