shadowsocks / shadowsocks-libev

Bug-fix-only libev port of shadowsocks. Future development moved to shadowsocks-rust
https://github.com/shadowsocks/shadowsocks-rust
GNU General Public License v3.0
15.79k stars 5.69k forks source link

服务器与客户端ss-redir 启用 UDP,但无法查询DNS #1675

Closed AxIauk closed 6 years ago

AxIauk commented 6 years ago

What version of shadowsocks-libev are you using?

server=shadowsocks-libev 3.0.8 client=shadowsocks-libev 3.0.6

What operating system are you using?

server=centos7 client=Linux AC88U 2.6.36.4brcmarm armv7l ASUSWRT-Merlin

What did you do?

路由器加载TPROXY 模块使用ss-redir 全局查询 DNS

What did you expect to see?

ss-redir 全局查询 DNS

What did you see instead?

DNS 查询失败

What is your config in detail (with all sensitive info masked)?

!/bin/sh

modprobe ip_set modprobe ip_set_hash_net modprobe ip_set_hash_ip modprobe xt_set modprobe xt_TPROXY.ko

iptables -t nat -N SHADOWSOCKS iptables -t mangle -N SHADOWSOCKS

iptables -t nat -A SHADOWSOCKS -d X.X.X.X -j RETURN

iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN

iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 1080

ip rule add fwmark 0x01/0x01 table 100 ip route add local 0.0.0.0/0 dev lo table 100 iptables -t mangle -A SHADOWSOCKS -p udp --dport 53 -j TPROXY --on-port 1080 --tproxy-mark 0x01

iptables -t nat -A PREROUTING -p tcp -j SHADOWSOCKS iptables -t mangle -A PREROUTING -j SHADOWSOCKS iptables -t nat -A OUTPUT -p tcp -j SHADOWSOCKS

debiansid commented 6 years ago

ss-tunnel启动一个

AxIauk commented 6 years ago

现在发现,上面的ss-redir配置,默认dnsmasq 127.0.0.1 导致路由器可以正确查询DNS但客户端却无法查询DNS,客户端改成8.8.8.8 可以正常查询了。 我是一名新手,在从全局代理一步一步学习。 另外询您提到的这种方法,ss-redir 中转 TCP 和 UDP除53外 另启动了ss-tunnel ss-redir ARGS="-c /opt/etc/shadowsocks.json -u -b 0.0.0.0 -l 1080" ss-tunnel ARGS="-c /opt/etc/shadowsocks.json -u -b 0.0.0.0 -l 1081 -L 8.8.8.8:53"(需要更改为1081吗?) 上面的iptables 应该怎么改写?感谢。

debiansid commented 6 years ago

dnsmasq把需要翻的域名指到127.0.0.1#1081

或者dig twitter.com @127.0.0.1 -p1081 看看结果

debiansid commented 6 years ago

不需要转发53端口的udp

AxIauk commented 6 years ago

非常感谢,全局没问题了。 刚才又研究了一下不带 ipset的分流,目前测试着好像是没问题了。 dnsmasq(127.0.0.1#5354) -> ChinaDNS(-p 5354 -s 114.114.114.114,127.0.0.1:1081 -d -v) -> ss-tunnel(1081) 其中DNS如上端口配置是否正确? 感觉很舒服。LOL,再次拜谢。