docker-easyconnect icon indicating copy to clipboard operation
docker-easyconnect copied to clipboard

增加暴露DNS的iptables规则

Open PaleNeutron opened this issue 2 years ago • 4 comments

假设我需要在全局访问 internal.com, 这时候如果使用clash-premium的tun模式进行代理则无法实现。

因为我访问internal.com的时候会首先在clash的dns中查询ip,因为是内网域名,要么查不到,要么返回的不正确,然后才会到tun层,这时候tun层只可能应用ip规则,域名规则不会触发,导致流量不能正确的进容器里。

因此希望能把容器内的dns,127.0.0.1:5373 给映射出来。

PaleNeutron avatar Dec 27 '22 10:12 PaleNeutron

如果用 iptables 的话,因为那个 5373 端口 bind 在 127.0.0.1:5373,所以得启动容器时加上 --sysctl net.ipv4.conf.all.route_localnet=1 参数才能(至少我只想到)用 iptables 来做这个转发:

iptables -t nat -A PREROUTING -p udp --dport 53 -m addrtype --dst-type LOCAL -j DNAT --to-destination 127.0.0.1:5373

如果不加 --sysctl net.ipv4.conf.all.route_localnet=1 大概只能在用户空间做这个事情:

socat udp4-listen:53,reuseaddr,fork udp4:127.0.0.1:5373

Hagb avatar Jan 18 '23 07:01 Hagb

我知道TCP的可以这样,不过好像UDP的话回包会有点问题,等我晚上回家试试看

PaleNeutron avatar Jan 18 '23 07:01 PaleNeutron

我也有这样的需求,希望内网域名能用代理服务器DNS来解析,请问这个问题现在有解了吗?

aiyogg avatar Jan 15 '24 12:01 aiyogg