Project

General

Profile

« Previous | Next » 

Revision b4323f39

Added by Jim Pingle about 12 years ago

Add the ability for dnsmasq to selectively respond to queries only on certain IPs and bind to specific interfaces.

View differences:

etc/inc/services.inc
1577 1577
		if (is_port($config['dnsmasq']['port']))
1578 1578
			$args .= " --port={$config['dnsmasq']['port']} ";
1579 1579

  
1580
		$listen_addresses = "";
1581
		if(isset($config['dnsmasq']['interface'])) {
1582
			$interfaces = explode(",", $config['dnsmasq']['interface']);
1583
			foreach ($interfaces as $interface) {
1584
				if (is_ipaddr($interface)) {
1585
					$listen_addresses .= " --listen-address={$interface} ";
1586
				} else {
1587
					$if = get_real_interface($interface);
1588
					if (does_interface_exist($if)) {
1589
						$laddr = find_interface_ip($if);
1590
						if (is_ipaddrv4($laddr))
1591
							$listen_addresses .= " --listen-address={$laddr} ";
1592
						$laddr6 = find_interface_ipv6($if);
1593
						if (is_ipaddrv6($laddr6) && !isset($config['dnsmasq']['strictbind']))
1594
							$listen_addresses .= " --listen-address={$laddr6} ";
1595
					}
1596
				}
1597
			}
1598
			if (!empty($listen_addresses)) {
1599
				$args .= " {$listen_addresses} ";
1600
				if (isset($config['dnsmasq']['strictbind']))
1601
					$args .= " --bind-interfaces ";
1602
			}
1603
		}
1604

  
1580 1605
		/* Setup forwarded domains */
1581 1606
		if (isset($config['dnsmasq']['domainoverrides']) && is_array($config['dnsmasq']['domainoverrides'])) {
1582 1607
			foreach($config['dnsmasq']['domainoverrides'] as $override) {
......
1625 1650
		}
1626 1651

  
1627 1652
		/* run dnsmasq */
1628
		mwexec_bg("/usr/local/sbin/dnsmasq --local-ttl 1 --all-servers {$dns_rebind} --dns-forward-max=5000 --cache-size=10000 {$args}");
1653
		$cmd = "/usr/local/sbin/dnsmasq --local-ttl 1 --all-servers {$dns_rebind} --dns-forward-max=5000 --cache-size=10000 {$args}";
1654
		//log_error("dnsmasq command: {$cmd}");
1655
		mwexec_bg($cmd);
1629 1656
		unset($args);
1630 1657

  
1631 1658
		if ($g['booting'])
usr/local/www/services_dnsmasq.php
54 54
$pconfig['port'] = $config['dnsmasq']['port'];
55 55
$pconfig['custom_options'] = $config['dnsmasq']['custom_options'];
56 56

  
57
$pconfig['strictbind'] = isset($config['dnsmasq']['strictbind']);
58
$pconfig['interface'] = explode(",", $config['dnsmasq']['interface']);
59

  
57 60
if (!is_array($config['dnsmasq']['hosts']))
58 61
	$config['dnsmasq']['hosts'] = array();
59 62

  
......
77 80
	$config['dnsmasq']['domain_needed'] = ($_POST['domain_needed']) ? true : false;
78 81
	$config['dnsmasq']['no_private_reverse'] = ($_POST['no_private_reverse']) ? true : false;
79 82
	$config['dnsmasq']['custom_options'] = str_replace("\r\n", "\n", $_POST['custom_options']);
83
	$config['dnsmasq']['strictbind'] = ($_POST['strictbind']) ? true : false;
80 84

  
81 85
	if ($_POST['port'])
82 86
		if(is_port($_POST['port']))
......
86 90
	else if (isset($config['dnsmasq']['port']))
87 91
		unset($config['dnsmasq']['port']);
88 92

  
89
	if ($_POST['port'])
90
		if(!is_port($_POST['port']))
91
			$input_errors[] = gettext("You must specify a valid port number");
93
	if (is_array($_POST['interface']))
94
		$config['dnsmasq']['interface'] = implode(",", $_POST['interface']);
95
	elseif (isset($config['dnsmasq']['interface']))
96
		unset($config['dnsmasq']['interface']);
92 97

  
93 98
	if ($config['dnsmasq']['custom_options']) {
94 99
		$args = '';
......
250 255
			<?=gettext("The port used for responding to DNS queries. It should normally be left blank unless another service needs to bind to TCP/UDP port 53.");?></p>
251 256
		</td>
252 257
	</tr>
258
	<tr>
259
		<td width="22%" valign="top" rowspan="2" class="vncellreq"><?=gettext("Interfaces"); ?></td>
260
		<td width="78%" class="vtable">
261
		<?php
262
			$interface_addresses = get_possible_listen_ips(true);
263
			$size=count($interface_addresses)+1;
264
		?>
265
			<?=gettext("Interface IPs used to respond to queries from the DNS Forwarder. In an interface has both IPv4 and IPv6 IPs, both are used. Queries to other interface IPs not selected below are discarded. The default behavior is to respond to queries on every available IPv4 and IPv6 address.");?>
266
			<br /><br />
267
			<select id="interface" name="interface[]" multiple="true" class="formselect" size="<?php echo $size; ?>">
268
				<option value="">All</option>
269
			<?php  foreach ($interface_addresses as $laddr):
270
					$selected = "";
271
					if (in_array($laddr['value'], $pconfig['interface']))
272
						$selected = 'selected="selected"';
273
			?>
274
				<option value="<?=$laddr['value'];?>" <?=$selected;?>>
275
					<?=htmlspecialchars($laddr['name']);?>
276
				</option>
277
			<?php endforeach; ?>
278
			</select>
279
			<br />
280
		</td>
281
	</tr>
282
	<tr>
283
		<td width="78%" class="vtable"><p>
284
			<input name="strictbind" type="checkbox" id="strictbind" value="yes" <?php if ($pconfig['strictbind'] == "yes") echo "checked";?>>
285
			<strong><?=gettext("Strict Interface Binding");?></strong>
286
			<br />
287
			<?= gettext("If this option is set, the DNS forwarder will only bind to the interfaces selected above, rather than binding to all interfaces and discarding queries to other addresses."); ?>
288
			<br /><br />
289
			<?= gettext("NOTE: This option does NOT work with IPv6. If set, dnsmasq will not bind to IPv6 addresses."); ?>
290
			</p>
291
		</td>
292
	</tr>
253 293
	<tr>
254 294
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Advanced");?></td>
255 295
		<td width="78%" class="vtable"><p>

Also available in: Unified diff