containers / netavark

Container network stack
Apache License 2.0
512 stars 81 forks source link

No DNS in internal networks when dns_port is not set to 53 #1051

Open fxthomas opened 1 month ago

fxthomas commented 1 month ago

Observed behavior

When setting dns_bind_port in /etc/containers/containers.conf to anything other than 53, containers in internal networks have no container-to-container name resolution (e.g. you can't ping database from a web container).

Inside containers /etc/resolv.conf is configured properly to the IP of the aardvark-dns resolver, but cannot specify a non-default port: DNS requests try to go to port 53 and fail. The non-default port is however perfectly reachable (using e.g. dig or nslookup).

Expected behavior

The behavior should be the same as with the default DNS port.

In non-internal networks, the following iptables rules are added to remap the non-default DNS port as 53 (YMMV), but these are missing in internal networks:

iptables -I INPUT 1 -s 10.89.0.0/24 -d 10.89.0.0/24 -p udp --dport 
20053 -j ACCEPT
iptables -t nat -I PREROUTING 1 -m addrtype --dst-type LOCAL -p udp 
-d 10.89.0.0/24 --dport 53 -j DNAT --to-destination 10.89.0.1:20053
iptables -t nat -I OUTPUT 1 -m addrtype --dst-type LOCAL -p udp -d 
10.89.0.0/24 --dport 53 -j DNAT --to-destination 10.89.0.1:20053

Versions on the host:

Note: See discussion on the mailing list for more details.

dev-zero commented 2 days ago

I ran into the same issue with netavark 1.12.1-3 on Debian.