<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>dnsmasq needs to listen on all IPs on the lo0 interface _except_
      for the one unbound also listens on (in this case, 127.0.0.20), so
      that the jailed processes have dnsmasq to communicate with, and
      then dnsmasq can query unbound for 'outside' DNS resolution on its
      own jail IP. The latter happens via IPv6 only now, as dnsmasq
      refuses to use 127.0.0.20 with its current config, however
      according to sockstat, it listens on the wildcard interface
      despite its log message:</p>
    <p><tt>USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS        
        FOREIGN ADDRESS<br>
        nobody   dnsmasq    99396 4  udp4   *:53                  *:*<br>
        nobody   dnsmasq    99396 5  tcp4   *:53                  *:*<br>
        nobody   dnsmasq    99396 6  udp6   *:53                  *:*<br>
        nobody   dnsmasq    99396 7  tcp6   *:53                  *:*<br>
        nobody   dnsmasq    99396 10 dgram  (not connected)<br>
      </tt></p>
    <p>Unbound listens on 127.0.0.20:</p>
    <p><tt>USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS        
        FOREIGN ADDRESS<br>
        unbound  unbound    29892 3  udp6   2a01:4f8:241:15df::32:53 *:*<br>
        unbound  unbound    29892 4  tcp6   2a01:4f8:241:15df::32:53 *:*<br>
        unbound  unbound    29892 5  udp4   127.0.0.20:53         *:*<br>
        unbound  unbound    29892 6  tcp4   127.0.0.20:53         *:*<br>
      </tt></p>
    <p>When testing, dnsmasq responds to all internal hostname queries
      on 127.0.0.x except for 127.0.0.20, so it seems to listen on all
      interfaces. FreeBSD kernel gives preference to the IP-bound
      (non-wildcard) socket when connecting to that socket for querying,
      see querying an inner jail name, jail-mariadb:</p>
    <p><tt># host jail-mariadb 127.0.0.1</tt><tt><br>
      </tt><tt>Using domain server:</tt><tt><br>
      </tt><tt>Name: 127.0.0.1</tt><tt><br>
      </tt><tt>Address: 127.0.0.1#53</tt><tt><br>
      </tt><tt>Aliases:</tt><tt><br>
      </tt><tt><br>
      </tt><tt>jail-mariadb has address 127.0.0.24</tt><tt><br>
      </tt><tt>jail-mariadb has IPv6 address 2a01:4f8:241:15df::21</tt><tt><br>
      </tt></p>
    <p><tt># host jail-mariadb 127.0.0.5<br>
        Using domain server:<br>
        Name: 127.0.0.5<br>
        Address: 127.0.0.5#53<br>
        Aliases:<br>
        <br>
        jail-mariadb has address 127.0.0.24<br>
        jail-mariadb has IPv6 address 2a01:4f8:241:15df::21<br>
      </tt></p>
    <p><tt># host jail-mariadb 127.0.0.20</tt><tt><br>
      </tt><tt>Using domain server:</tt><tt><br>
      </tt><tt>Name: 127.0.0.20</tt><tt><br>
      </tt><tt>Address: 127.0.0.20#53</tt><tt><br>
      </tt><tt>Aliases:</tt><tt><br>
      </tt><tt><br>
      </tt><tt>Host jail-mariadb not found: 3(NXDOMAIN)</tt><br>
    </p>
    <p>Both 127.0.0.1 and 127.0.0.5 is a response from dnsmasq, but
      127.0.0.20 is a response from unbound. This is desired, in order
      for the jailed processes to be able to use DNS resolution from
      within.<br>
    </p>
    <p>What I'm trying to achieve is to make dnsmasq query 127.0.0.20
      knowing the facts above, as specified in the
      /usr/local/etc/dnsmasq-resolv.conf:</p>
    <p><tt>nameserver 127.0.0.20</tt><tt><br>
      </tt><tt>nameserver 2a01:4f8:241:15df::32</tt></p>
    <p>Basically, the jails talk to their own assigned internal IPs when
      querying (not 127.0.0.1, that won't work because the DNS response
      gets dropped as the response comes from the jail's internal IP and
      not 127.0.0.1), it's why dnsmasq has to listen on them. Then
      dnsmasq will talk to the unbound jail's IP address (127.0.0.20),
      when querying for outside DNS.</p>
    <p>Sounds complicated, but this is what I'd like to get done, so it
      would work with both IPv6 AND IPv4.<br>
    </p>
    <pre class="moz-signature" cols="72">Cheers,
--
László Károlyi
<a class="moz-txt-link-freetext" href="http://linkedin.com/in/karolyi">http://linkedin.com/in/karolyi</a>
</pre>
    <div class="moz-cite-prefix">On 2020-07-21 17:00, Petr Menšík wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:00c3cc9d-111b-6bf6-f5e6-bb6dde5fe961@redhat.com">
      <pre class="moz-quote-pre" wrap="">How should unbound listen on lo0 if dnsmasq is already listening there?
I do not know BSD. Linux would not permit dnsmasq listening on wildcard
socket and unbound listening on the same port.

I think listen-address would listen just on 127.0.0.1. interface=lo0
should not be necessary. At least on Linux kernel, it means listening on
ANY IPv4/IPv6 address assigned to lo0. That would mean unbound needs
different port to listen on or different interface. I think that is not
what you want.

What is contents of /usr/local/etc/dnsmasq-resolv.conf?
I think no-resolv should be used as well to prevent reading
/etc/resolv.conf.
</pre>
    </blockquote>
  </body>
</html>