zw963 / asuswrt-merlin-transparent-proxy

transparent proxy base on ss, v2ray, xray, ipset, iptables, chinadns on asuswrt merlin or side router.
MIT License
380 stars 80 forks source link

手动编译部署ss+chinadns+dnscrypt只能访问部分网站 #39

Closed lniwn closed 6 years ago

lniwn commented 6 years ago

首先,感谢作者的无私奉献,由于家里使用的windows系统,无法一键使用部署脚本,并且本着学习的精神,所以按照脚本里的步骤进行了手动部署,但是遇到点问题,特来请教。


现象

我采用ss+chinadns+dnscrypt 的方式搭建环境,但是墙外网站部分可以访问,墙内网站正常。

排查

1) dig可以正确找到ip地址 dig

2) 通过ipip.net和whatismyipaddress.com也能正确区分墙内墙外 ip

3) twitter可以访问但是Google、Youtube等不能访问 twitter and google

4) 路由器日志 router log

5) VPS日志 vps log

6) 本机运行SS客户端可以正常访问所有网站,排除运营商问题

问题

这种情况一般可能是哪方面的原因?我应该提供其他什么信息帮助排查?

zw963 commented 6 years ago

我觉得是你的 DNS 的查询因为使用 udp 协议,被污染了,你得到的可能还是假 IP,得用 TCP 才协议行。客户端 dnscrypt-proxy 要加 -T 参数。或者 ss+dnsmasq+dnscrypt 方案,需要自建 dnscrypt 服务器。

2017年9月22日 上午10:42,"lniwn" notifications@github.com写道:

首先,感谢作者的无私奉献,由于家里使用的windows系统,无法一键使用部署脚本,并且本着学习的精神, 所以按照脚本里的步骤进行了手动部署,但是遇到点问题,特来请教。

现象

我采用ss+chinadns+dnscrypt https://github.com/zw963/asuswrt-merlin-transparent-proxy/blob/master/ss%2Bchinadns%2Bdnscrypt 的方式搭建环境,但是墙外网站部分可以访问,墙内网站正常。 排查

1.

dig可以正确找到ip地址 [image: dig] https://user-images.githubusercontent.com/3256188/30727204-66b8e54a-9f82-11e7-93cb-4d0fad33d1de.png 2.

通过ipip.net和whatismyipaddress.com也能正确区分墙内墙外 [image: ip] https://user-images.githubusercontent.com/3256188/30727195-5708f0ea-9f82-11e7-88f7-1119a4bf12ff.png 3.

twitter可以访问但是Google、Youtube等不能访问 [image: twitter and google] https://user-images.githubusercontent.com/3256188/30727207-6cbb6b34-9f82-11e7-93b6-307a187af17e.png 4.

路由器日志 [image: router log] https://user-images.githubusercontent.com/3256188/30727218-79ba479c-9f82-11e7-82e5-6b27bc404bf1.png 5.

VPS日志 [image: vps log] https://user-images.githubusercontent.com/3256188/30727220-7f6ad850-9f82-11e7-9966-d2ee447862bb.png 6.

本机运行SS客户端可以正常访问所有网站,排除运营商问题

问题

这种情况一般可能是哪方面的原因?我应该提供其他什么信息帮助排查?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zw963/asuswrt-merlin-transparent-proxy/issues/39, or mute the thread https://github.com/notifications/unsubscribe-auth/AAhhBhjc9qnSDldy6JGN3jbIG30iU_qSks5skx6NgaJpZM4PgJ_M .

lniwn commented 6 years ago

我是自建的dnscrypt_wrapper服务器,虽然在启动参数加了-V参数,但是看不到客户端访问信息,很奇怪。

zw963 commented 6 years ago

多加几个 -V 参数试试,如果自建服务器,那就不要用 chinadns 了,因为它好像不支持 TCP 的上游服务器

2017年9月22日 上午11:36,"lniwn" notifications@github.com写道:

我是自建的dnscrypt_wrapper服务器,虽然在启动参数加了-V参数,但是看不到客户端访问信息,很奇怪。

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zw963/asuswrt-merlin-transparent-proxy/issues/39#issuecomment-331341653, or mute the thread https://github.com/notifications/unsubscribe-auth/AAhhBi1AGW2Goyj17xYbZrXxaStrPzcmks5skytOgaJpZM4PgJ_M .

lniwn commented 6 years ago

如果不用chinadns点的话,那全部依靠本地iptables配置,中国ip直接return,国外ip丢给dnscrypt,这样的逻辑?

lniwn commented 6 years ago

我自己更倾向于使用加密的udp来查询,所以昨天花了几个钟把dnscrypt-wrapper搭建好了,就想依靠chinadns的智能分流,按照你的描述,你怀疑是dnscrypt-proxy与dnscrypt-wrapper之间通信问题?

zw963 commented 6 years ago

如果不用chinadns点的话,那全部依靠本地iptables配置,中国ip直接return,国外ip丢给dnscrypt,这样的逻辑?

你参考下 ss+dnsmasq+dnscrypt 那个脚本, 我感觉效果还可以. 看国内 v.qq.com 和 youtube 完全不卡. 我那个脚本用了 dnsmasq 域名白名单iptables 国内 ip 白名单 两套策略, 前者是为 dnscrypt 做的白名单, 后者是为 ss-server 做的白名单, 只要是白名单就丢给运营商, 其余的分别走 dnscrypt-proxy 和 ss-redir.

zw963 commented 6 years ago

我自己更倾向于使用加密的udp来查询,所以昨天花了几个钟把dnscrypt-wrapper搭建好了,就想依靠chinadns的智能分流,按照你的描述,你怀疑是dnscrypt-proxy与dnscrypt-wrapper之间通信问题?

对, 我使用 udp 查询 dns, 网页常常会卡死, 就算你 dig 有结果, 网页也不成, 应该是墙的原因, 换 TCP 就好了, 国外网页都是秒开.

lniwn commented 6 years ago

好的,我先对照那个脚本改下看看,感谢你的热心帮助 @zw963

lniwn commented 6 years ago
  1. 修改/opt/etc/dnsmasq.d/foreign_domains.conf端口号为65053
  2. 修改/opt/etc/init.d/S56chinadnsENABLED=no
  3. 重启服务/jffs/scripts/service-stop && /jffs/script/service-start 这样就可以正常访问外网了,所以现在的方案是ss+dnsmasq+dnscrypt-proxy+dnscrypt-wrapper,采用的加密udp查询dns。

但是有个很尴尬的问题,虽然链接路由器的机器可以访问外网,但是路由器本身无法FQ image

zw963 commented 6 years ago

采用的加密udp查询dns。

我自己测试的结果, 感觉 udp 不太靠谱, 是不是域名解析被重置, 当然, 这可能和我本地的运营商线路有关, 无论如何, 换成 tcp 效果好多了.

虽然链接路由器的机器可以访问外网,但是路由器本身无法FQ

你先搞清楚是域名无法解析, 还是 iptables 规则问题, 或者是 ss 连接问题?

至少应该先 dig 一下域名. dig -p 65053 www.google.com, 多 dig 几次. 然后查看 iptables, iptables -t nat -vL, 是否有规则. 最后看 ss 日志, 是否工作.

lniwn commented 6 years ago

多谢耐心解答,昨天排查之后,发现dns查询ok,但是访问页面超时,所以最终定位到了iptables问题,我添加iptables的代码放在了wan-start脚本里,但是不知何故,我的路由器启动时这个脚本没有调用,后续还得再调查下,另外,我这里dnscrypt查询超级慢,udp一直丢包,换成tcp一直超时,现在用ss-tunnel替代了dnscrypt-proxy,总算是能正常使用了,后续还得再调查下遗留问题:①wan-start没有被调用;②dnscrypt-proxy查询失败。 查询流程: ss-redir ss-tunnel dnsmasq 路由表初始化脚本:

#!/bin/sh
modprobe xt_set.ko
iptables -t nat -N SHADOWSOCKS

#Bypass LAN IP

#Bypass SS and Intranet IP
#iptables -t nat -A SHADOWSOCKS -d x.x.x.x-j RETURN # SS Server IP
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 OUTPUT -d x.x.x.x-j RETURN # SS Server IP
iptables -t nat -A OUTPUT -d 0.0.0.0/8 -j RETURN
iptables -t nat -A OUTPUT -d 10.0.0.0/8 -j RETURN
iptables -t nat -A OUTPUT -d 127.0.0.0/8 -j RETURN
iptables -t nat -A OUTPUT -d 169.254.0.0/16 -j RETURN
iptables -t nat -A OUTPUT -d 172.16.0.0/12 -j RETURN
iptables -t nat -A OUTPUT -d 192.168.0.0/16 -j RETURN
iptables -t nat -A OUTPUT -d 224.0.0.0/4 -j RETURN
iptables -t nat -A OUTPUT -d 240.0.0.0/4 -j RETURN

#CN IP load and bypass
ipset restore </jffs/configs/china_ipset.conf
iptables -t nat -A SHADOWSOCKS -m set --match-set china_ipset dst -j RETURN
iptables -t nat -A OUTPUT -m set --match-set china_ipset dst -j RETURN

#Redirect Other IP
iptables -t nat -A PREROUTING ! -p icmp -j SHADOWSOCKS
iptables -t nat -A OUTPUT ! -p icmp -j SHADOWSOCKS
iptables -t nat -A SHADOWSOCKS ! -p icmp -j REDIRECT --to-ports 1080
lniwn commented 6 years ago

看来我这边运营商线路抽风,昨晚尝试了下换成dnscrypt-wrapper的tcp模式又可以了。 总结了下流水账,万一有人需要可以参考下 https://www.zybuluo.com/lniwn/note/889385

zw963 commented 6 years ago

现在用ss-tunnel替代了dnscrypt-proxy,总算是能正常使用了

我 ss-tunnel 貌似效果不咋地, 换个说法, 只要是 UDP 就不咋地, TCP 速度很爽.

①wan-start没有被调用

这个我试过, 应该调用了的. 只不过, iptables 应用好像早了点, 我怀疑稍后被路由器重置了.

zw963 commented 6 years ago

昨晚尝试了下换成dnscrypt-wrapper的tcp模式又可以了

这个我试了蛮久了, 可以的, 问题解决了就好.

zw963 commented 6 years ago

@lniwn , 下面这些针对 OUTPUT 的 rules, 你确定需要吗? 我觉得不需要.

iptables -t nat -A OUTPUT -d 0.0.0.0/8 -j RETURN
iptables -t nat -A OUTPUT -d 10.0.0.0/8 -j RETURN
iptables -t nat -A OUTPUT -d 127.0.0.0/8 -j RETURN
iptables -t nat -A OUTPUT -d 169.254.0.0/16 -j RETURN
iptables -t nat -A OUTPUT -d 172.16.0.0/12 -j RETURN
iptables -t nat -A OUTPUT -d 192.168.0.0/16 -j RETURN
iptables -t nat -A OUTPUT -d 224.0.0.0/4 -j RETURN
iptables -t nat -A OUTPUT -d 240.0.0.0/4 -j RETURN
iptables -t nat -A OUTPUT -m set --match-set china_ipset dst -j RETURN

下面这行应该需要才对.

#iptables -t nat -A SHADOWSOCKS -d x.x.x.x-j RETURN # SS Server IP
zw963 commented 6 years ago

刚刚试了下梅林下的 dnscrypt-proxy, 貌似不支持 LocalCache on 选项.

lniwn commented 6 years ago

iptables -t nat -A OUTPUT -d 0.0.0.0/8 -j RETURN iptables -t nat -A OUTPUT -d 10.0.0.0/8 -j RETURN iptables -t nat -A OUTPUT -d 127.0.0.0/8 -j RETURN iptables -t nat -A OUTPUT -d 169.254.0.0/16 -j RETURN iptables -t nat -A OUTPUT -d 172.16.0.0/12 -j RETURN iptables -t nat -A OUTPUT -d 192.168.0.0/16 -j RETURN iptables -t nat -A OUTPUT -d 224.0.0.0/4 -j RETURN iptables -t nat -A OUTPUT -d 240.0.0.0/4 -j RETURN iptables -t nat -A OUTPUT -m set --match-set china_ipset dst -j RETURN

@zw963 我的路由器处于二级路由器环境,所以觉得应该还是需要的

LocalCache on是从官方配置中来的,博客里只是记录,还没来得及实际验证,昨晚试了下,确实不支持,但是openwrt的软件仓库里的版本是支持的[1],opkg的仓库里的版本已经1.9.5-7了,还是不支持ldns,不知道是bug还是什么原因。

最后,多谢耐心解答。

zw963 commented 6 years ago

@zw963 我的路由器处于二级路由器环境,所以觉得应该还是需要的

我的理解, 下面这行代码已经做了所有的事情, 你不需要重复.

iptables -t nat -A OUTPUT ! -p icmp -j SHADOWSOCKS
zw963 commented 6 years ago

昨晚试了下,确实不支持,但是openwrt的软件仓库里的版本是支持的

有没有可能拷贝 openwrt 的版本过来直接用? 估计梅林系统有点老, 用不了.

lniwn commented 6 years ago

不确定直接拷贝过来能不能用,说不定要重新编译。我现在打算先研究下能不能直接用dnsmasq的缓存,如果dnsmasq缓存能达到效果,就不用折腾dnscrypt-proxy了。 我的AC1900P上,dnsmasq只能缓存直接走国内DNS的网站,对于走上游DNS(127.0.0.1:65053)的网站,没法缓存,还在找原因。

lniwn commented 6 years ago

我的理解, 下面这行代码已经做了所有的事情, 你不需要重复.

ok,我删掉试试。