Repository: opnsense/core (language: php)

Issue:
dnsmasq: Checkbox to ignore entries in /etc/hosts 
**Important notices**

Before you add a new report, we ask you kindly to acknowledge the following:

- [X] I have read the contributing guide lines at https://github.com/opnsense/core/blob/master/CONTRIBUTING.md
- [X] I am convinced that my issue is new after having checked both open and closed issues at https://github.com/opnsense/core/issues?q=is%3Aissue

**Describe the bug**

I use a remote BIND server to configure DNS entries in my networks and the local OPNsense dnsmasq to use for the clients. The management IP for the OPNsense is configured in the remote BIND server for the correct interface.

Unfortunately a /etc/hosts entry is generated from the available interfaces - in my case it is using the IP from the  ipsec1000 interface, which is not the management IP/interface.

Therefore I would like the dnsmasq service to ignore the entries in /etc/hosts and only use the DNS entries from the upstream remote BIND server.

My previous work around was to configure "no-hosts" in the custom_options field, which was removed with https://github.com/opnsense/core/commit/5c58dd08c31c68725fe0d8ec454b01982d365573.

Now my work around is to add a config file in /usr/local/etc/dnsmasq.conf.d - which then is not synched to the backup firewall and might be forgotten with a new install.

**To Reproduce**

1.  Install bind DNS service on a remote machine
2. Configure hostname of OPNsense in that bind to a specific IP
3. Activate DNSmasq on OPNsense
4. Do a nslookup from a client using the OPNsense as DNS server and check the returned IP address.

**Expected behavior**

I want to get the IP address configured in bind returned instead of a random interfaces IP address of the OPNsense for the OPNsenses DNS name.

**Describe alternatives you considered**

Change the /etc/hosts generation code to only use the IP from the LAN interface to generate the entry for the OPNsense hostname.




Discussion / hints:

Fix patch:
diff --git a/src/etc/inc/plugins.inc.d/dnsmasq.inc b/src/etc/inc/plugins.inc.d/dnsmasq.inc
index 30c14a3bb99..30267efe8a1 100644
--- a/src/etc/inc/plugins.inc.d/dnsmasq.inc
+++ b/src/etc/inc/plugins.inc.d/dnsmasq.inc
@@ -184,6 +184,10 @@ function dnsmasq_configure_do($verbose = false)
         $args .= ' --log-queries=extra ';
     }
 
+    if (isset($config['dnsmasq']['no_hosts'])) {
+        $args .= ' --no-hosts ';
+    }
+
     $args .= ' --dns-forward-max=5000 ';
     $args .= ' --cache-size=10000 ';
     $args .= ' --local-ttl=1 ';
diff --git a/src/www/services_dnsmasq.php b/src/www/services_dnsmasq.php
index 86ce5a131e8..dd44bcf665b 100644
--- a/src/www/services_dnsmasq.php
+++ b/src/www/services_dnsmasq.php
@@ -49,6 +49,7 @@
     $pconfig['strictbind'] = isset($a_dnsmasq['strictbind']);
     $pconfig['dnssec'] = isset($a_dnsmasq['dnssec']);
     $pconfig['log_queries'] = isset($a_dnsmasq['log_queries']);
+    $pconfig['no_hosts'] = isset($a_dnsmasq['no_hosts']);
     // simple text types
     $pconfig['port'] = !empty($a_dnsmasq['port']) ? $a_dnsmasq['port'] : "";
     // arrays
@@ -81,6 +82,7 @@
             $a_dnsmasq['domain_needed'] = !empty($pconfig['domain_needed']);
             $a_dnsmasq['no_private_reverse'] = !empty($pconfig['no_private_reverse']);
             $a_dnsmasq['log_queries'] = !empty($pconfig['log_queries']);
+            $a_dnsmasq['no_hosts'] = !empty($pconfig['no_hosts']);
             $a_dnsmasq['strictbind'] = !empty($pconfig['strictbind']);
             $a_dnsmasq['dnssec'] = !empty($pconfig['dnssec']);
             if (!empty($pconfig['regdhcpdomain'])) {
@@ -355,6 +357,13 @@
                     </div>
                   </td>
                 </tr>
+                <tr>
+                  <td><i class="fa fa-info-circle text-muted"></i> <?=gettext('No Hosts Lookup') ?></td>
+                  <td>
+                    <input name="no_hosts" type="checkbox" id="no_hosts" value="yes" <?= !empty($pconfig['no_hosts']) ? 'checked="checked"' : '' ?> />
+                    <?= gettext('Don\'t read the hostnames in /etc/hosts.') ?>
+                  </td>
+                </tr>
                 <tr>
                   <td><i class="fa fa-info-circle text-muted"></i> <?=gettext('Log Queries') ?></td>
                   <td>


Test patch: