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:

USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
nobody   dnsmasq    99396 4  udp4   *:53                  *:*
nobody   dnsmasq    99396 5  tcp4   *:53                  *:*
nobody   dnsmasq    99396 6  udp6   *:53                  *:*
nobody   dnsmasq    99396 7  tcp6   *:53                  *:*
nobody   dnsmasq    99396 10 dgram  (not connected)

Unbound listens on 127.0.0.20:

USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
unbound  unbound    29892 3  udp6   2a01:4f8:241:15df::32:53 *:*
unbound  unbound    29892 4  tcp6   2a01:4f8:241:15df::32:53 *:*
unbound  unbound    29892 5  udp4   127.0.0.20:53         *:*
unbound  unbound    29892 6  tcp4   127.0.0.20:53         *:*

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:

# host jail-mariadb 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

jail-mariadb has address 127.0.0.24
jail-mariadb has IPv6 address 2a01:4f8:241:15df::21

# host jail-mariadb 127.0.0.5
Using domain server:
Name: 127.0.0.5
Address: 127.0.0.5#53
Aliases:

jail-mariadb has address 127.0.0.24
jail-mariadb has IPv6 address 2a01:4f8:241:15df::21

# host jail-mariadb 127.0.0.20
Using domain server:
Name: 127.0.0.20
Address: 127.0.0.20#53
Aliases:

Host jail-mariadb not found: 3(NXDOMAIN)

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.

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:

nameserver 127.0.0.20
nameserver 2a01:4f8:241:15df::32

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.

Sounds complicated, but this is what I'd like to get done, so it would
work with both IPv6 AND IPv4.

Cheers,
--
László Károlyi
http://linkedin.com/in/karolyi

On 2020-07-21 17:00, Petr Menšík wrote:
> 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.

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

Reply via email to