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

在我的ac1900p上面有些不稳定,如何排查 #82

Closed momobile closed 5 years ago

momobile commented 5 years ago

每每运行几天会发现翻墙出问题,国内网站都可以上,走ss代理的网站都不行了(主要通过能不能上google和youtube来判断)。

概率:最近一个月出现了4次,每星期都会出现

出现故障时的状态: 1.存在ss-redir进程 2.server的端口是listen状态,没有任何已创建的连接

出现问题做过一下尝试: 1.执行一遍patch_router,有可能会好,但大多数时间无效 2.重启ss-redir进程干掉进程,重启 3.重启路由,100%好使

想问一下,如何排查?遇到不能上网

zw963 commented 5 years ago

看你的描述, 应该是 iptables 规则失效的问题, 这个故障是最后一次重构改动之后引入的, 以前有个循环, 每隔一分钟, 就会执行一次检测, 后来取消了. 见 #72 讨论.

理论上, 重新执行 patch_router 应该总可以解决, 但是脚本可能有 BUG, 或其他非 iptables 问题.

还是需要你确认下, 下次出现问题, 在路由器中, 输入以下几个命令, 并分别贴出所有输出.

# iptables -t nat -nL
# ipset -L CHINAIPS |wc -l
# cat /opt/etc/dnsmasq.d/accelerated-domains.china.conf |wc -l

BTW: 我的路由器每天早上五点重启, 所以没出现过这种情况 ......

momobile commented 5 years ago

ok,多谢支持,问题先别关,下次出现我贴出来

momobile commented 5 years ago

我需要用你的新的脚本重新部署一遍吗?新的脚本有什么改善吗

zw963 commented 5 years ago

我需要用你的新的脚本重新部署一遍吗?新的脚本有什么改善吗

应该不用, 你应该是挺新的版本了吧? 最近没有更新过

momobile commented 5 years ago

我使用的是最早4个脚本的那个版本,还可以选择chinadns的那个时候,不是现在只有2个可选,不太清楚有什么区别?

另外你的脚本是否有版本号?

发自我的 iPhone

在 2019年4月27日,上午12:16,Billy.Zheng notifications@github.com<mailto:notifications@github.com> 写道:

我需要用你的新的脚本重新部署一遍吗?新的脚本有什么改善吗

应该不用, 你应该是挺新的版本了吧? 最近没有更新过

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/zw963/asuswrt-merlin-transparent-proxy/issues/82#issuecomment-487114832, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACC3Y5NBGF6GQN5UQYNP37TPSMTFFANCNFSM4HISYCJQ.

zw963 commented 5 years ago

我使用的是最早4个脚本的那个版本,还可以选择chinadns的那个时候,不是现在只有2个可选,不太清楚有什么区别?

如果是较早的那个, patch_router 有不少 BUG 的, 但是, 那个检测 iptables 的那个 loop 应该还没有移除, 所以, 不应该出现你说的情况.

你贴一下下面命令输出:

# cat /opt/etc/iptables.sh |head -20
# cat /jffs/scripts/services-start
momobile commented 5 years ago

cat /opt/etc/iptables.sh |head -20

#!/bin/sh

# iptables 默认有四个表: raw, nat, mangle, filter, 每个表都有若干个不同的 chain.
# 例如: filter 表包含 INPUT, FORWARD, OUTPUT 三个链, 下面创建了一个自定义 chain.
if ! iptables -t nat -N SHADOWSOCKS_TCP; then
    # 如果不成功, 表示已经执行过了, 直接退出.
    # 经过测试, 梅林还是会经常删除自定义 iptables, 所以, 还是需要反复执行这个文件来确保有效.
    exit
fi

remote_server_ip=$(cat /opt/etc/shadowsocks.json |grep 'server"' |cut -d':' -f2|cut -d'"' -f2)
local_redir_ip=$(cat /opt/etc/shadowsocks.json |grep 'local_address"' |cut -d':' -f2|cut -d'"' -f2)
local_redir_port=$(cat /opt/etc/shadowsocks.json |grep 'local_port' |cut -d':' -f2 |grep -o '[0-9]*')

echo 'Applying ipset rule, it maybe take several minute to finish ...'

# 如果没有备份 iptables rule, 就备份它.
[ -f /tmp/iptables.rules ] || iptables-save > /tmp/iptables.rules

ipset_protocal_version=$(ipset -v |grep -o 'version.*[0-9]' |head -n1 |cut -d' ' -f2)

cat /jffs/scripts/services-start

#!/bin/sh

RC='/opt/etc/init.d/rc.unslung'

i=30
until [ -x "$RC" ] ; do
  i=$(($i-1))
  if [ "$i" -lt 1 ] ; then
    logger "Could not start Entware"
    exit
  fi
  sleep 1
done
$RC start

if [ ! -f /tmp/patch_router_is_run ];then
    /opt/etc/patch_router && touch /tmp/patch_router_is_run
fi

if [ ! -f /tmp/patch_router_is_run ];then
    /opt/etc/patch_router && touch /tmp/patch_router_is_run
fi
zw963 commented 5 years ago

再看一下以下两个命令:

admin@RT-AC5300-5E70:/jffs/scripts# cat /jffs/scripts/wan-start
admin@RT-AC5300-5E70:/jffs/scripts# cru l
momobile commented 5 years ago

cat /jffs/scripts/wan-start

#!/bin/sh
cru a run-services "*/1 * * * *" "/jffs/scripts/services-start"
cru a run-iptables "*/3 * * * *" "/opt/etc/iptables.sh"
cru a update_ip_whitelist "25 3 * * 2" "/opt/etc/update_ip_whitelist"
cru a update_dns_whitelist "25 4 * * 2" "/opt/etc/update_dns_whitelist"

cru l

*/1 * * * * /jffs/scripts/services-start #run-services#
*/3 * * * * /opt/etc/iptables.sh #run-iptables#
25 3 * * 2 /opt/etc/update_ip_whitelist #update_ip_whitelist#
25 4 * * 2 /opt/etc/update_dns_whitelist #update_dns_whitelist#
zw963 commented 5 years ago

/3 * /opt/etc/iptables.sh #run-iptables#

每隔三分钟运行一次 /opt/etc/iptables.sh, 不知道为什么会遇到问题?

等遇到了再决定吧.

momobile commented 5 years ago

iptables -t nat -nL

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
VSERVER    all  --  0.0.0.0/0            192.168.1.2         
SHADOWSOCKS_TCP  tcp  --  0.0.0.0/0            0.0.0.0/0           

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
PUPNP      all  --  0.0.0.0/0            0.0.0.0/0           
MASQUERADE  all  -- !192.168.1.2          0.0.0.0/0           
MASQUERADE  all  --  192.168.50.0/24      192.168.50.0/24     

Chain DNSFILTER (0 references)
target     prot opt source               destination         

Chain LOCALSRV (0 references)
target     prot opt source               destination         

Chain PCREDIRECT (0 references)
target     prot opt source               destination         

Chain PUPNP (1 references)
target     prot opt source               destination         

Chain SHADOWSOCKS_TCP (1 references)
target     prot opt source               destination         

Chain VSERVER (1 references)
target     prot opt source               destination         
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpts:6881:6889 to:192.168.50.9
VUPNP      all  --  0.0.0.0/0            0.0.0.0/0           
TRIGGER    all  --  0.0.0.0/0            0.0.0.0/0            TRIGGER type:dnat match:0 relate:0 

Chain VUPNP (1 references)
target     prot opt source               destination         
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:49169 to:192.168.50.9:49169
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:4433 to:192.168.50.9:4433
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:49169 to:192.168.50.9:49169
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:6882 to:192.168.50.9:6882
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:6882 to:192.168.50.9:6882
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:31072 to:192.168.50.96:31072
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:36185 to:192.168.50.89:36185

ipset -L CHINAIPS |wc -l

ipset v6.32: The set with the given name does not exist
0

cat /opt/etc/dnsmasq.d/accelerated-domains.china.conf |wc -l 59535

zw963 commented 5 years ago

对的, 你的 iptables rule 被清空了, 可能是路由器启动了什么新的服务造成的.

建议升级一下, 以前的脚本有不少 bug, 可能恢复脚本也无效.

momobile commented 5 years ago

用最新的脚本部署了,每天晚上都会出现不能上网的情况(任何),重启才能好。

怎么调查?

zw963 commented 5 years ago

贴一下上面的命令,然后,patch_router 运行一下是否能解决。

momobile notifications@github.com 于 2019年5月9日周四 下午8:45写道:

用最新的脚本部署了,每天晚上都会出现不能上网的情况(任何),重启才能好。

怎么调查?

— 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/82#issuecomment-490888144, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEGCBWIYSELIQKEHQZYN33PUQMGFANCNFSM4HISYCJQ .

momobile commented 5 years ago

现在出现的情况是翻墙看不了,国内网站能上,间歇性的。伴随着https链接会提示,证书错误

另外我使用的脚本是release里面的0.5.4的

iptables -t nat -nL

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
VSERVER    all  --  0.0.0.0/0            192.168.1.2         
SHADOWSOCKS_TCP  tcp  --  0.0.0.0/0            0.0.0.0/0           

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
PUPNP      all  --  0.0.0.0/0            0.0.0.0/0           
MASQUERADE  all  -- !192.168.1.2          0.0.0.0/0           
MASQUERADE  all  --  192.168.50.0/24      192.168.50.0/24     

Chain DNSFILTER (0 references)
target     prot opt source               destination         

Chain LOCALSRV (0 references)
target     prot opt source               destination         

Chain PCREDIRECT (0 references)
target     prot opt source               destination         

Chain PUPNP (1 references)
target     prot opt source               destination         
MASQUERADE  udp  --  192.168.50.9         0.0.0.0/0            udp spt:5353 masq ports: 5354

Chain SHADOWSOCKS_TCP (1 references)
target     prot opt source               destination         
RETURN     tcp  --  0.0.0.0/0            0.0.0.0/0            match-set CHINAIPS dst
RETURN     tcp  --  0.0.0.0/0            0.0.0.0/0            match-set CHINAIP dst
REDIRECT   tcp  --  0.0.0.0/0            0.0.0.0/0            redir ports 1080

Chain VSERVER (1 references)
target     prot opt source               destination         
VUPNP      all  --  0.0.0.0/0            0.0.0.0/0           

Chain VUPNP (1 references)
target     prot opt source               destination         
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:5354 to:192.168.50.9:5353
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:49169 to:192.168.50.9:49169
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:4433 to:192.168.50.9:4433
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:49169 to:192.168.50.9:49169
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:6882 to:192.168.50.9:6882
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:6882 to:192.168.50.9:6882

ipset -L CHINAIPS |wc -l

8391

cat /opt/etc/dnsmasq.d/accelerated-domains.china.conf |wc -l 60088

zw963 commented 5 years ago

看起来没问题,先确定你 ss 配置有没有问题,还有 dnscrypt 配置。

momobile notifications@github.com 于 2019年5月9日周四 下午10:40写道:

现在出现的情况是翻墙看不了,国内网站能上

iptables -t nat -nL

Chain PREROUTING (policy ACCEPT)

target prot opt source destination

VSERVER all -- 0.0.0.0/0 192.168.1.2

SHADOWSOCKS_TCP tcp -- 0.0.0.0/0 0.0.0.0/0

Chain INPUT (policy ACCEPT)

target prot opt source destination

Chain OUTPUT (policy ACCEPT)

target prot opt source destination

Chain POSTROUTING (policy ACCEPT)

target prot opt source destination

PUPNP all -- 0.0.0.0/0 0.0.0.0/0

MASQUERADE all -- !192.168.1.2 0.0.0.0/0

MASQUERADE all -- 192.168.50.0/24 192.168.50.0/24

Chain DNSFILTER (0 references)

target prot opt source destination

Chain LOCALSRV (0 references)

target prot opt source destination

Chain PCREDIRECT (0 references)

target prot opt source destination

Chain PUPNP (1 references)

target prot opt source destination

MASQUERADE udp -- 192.168.50.9 0.0.0.0/0 udp spt:5353 masq ports: 5354

Chain SHADOWSOCKS_TCP (1 references)

target prot opt source destination

RETURN tcp -- 0.0.0.0/0 0.0.0.0/0 match-set CHINAIPS dst

RETURN tcp -- 0.0.0.0/0 0.0.0.0/0 match-set CHINAIP dst

REDIRECT tcp -- 0.0.0.0/0 0.0.0.0/0 redir ports 1080

Chain VSERVER (1 references)

target prot opt source destination

VUPNP all -- 0.0.0.0/0 0.0.0.0/0

Chain VUPNP (1 references)

target prot opt source destination

DNAT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:5354 to:192.168.50.9:5353

DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:49169 to:192.168.50.9:49169

DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:4433 to:192.168.50.9:4433

DNAT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:49169 to:192.168.50.9:49169

DNAT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:6882 to:192.168.50.9:6882

DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:6882 to:192.168.50.9:6882

ipset -L CHINAIPS |wc -l

8391

cat /opt/etc/dnsmasq.d/accelerated-domains.china.conf |wc -l 60088

— 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/82#issuecomment-490933097, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEGCBX23FO6FJMCXY6EJ5LPUQZXBANCNFSM4HISYCJQ .

momobile commented 5 years ago

那些东西应该没问题!ss我都会在电脑上安装客户端,路由出现问题我会重试验证。dns的话是自己的vps,路由出现问题我会ssh上去看一下服务。

此外我还体验出一个问题,我最开始接触你的脚本就使用了dnscrypt,是很老的一个版本3.x吧,那段时间除了规则可能会被清楚,还有一个问题,就是家人反馈微博,小红书,百度都有了特别慢!有时候京东都打不开!我用的宽带是联通,宽带里很不错的。没上咱们这个脚本时特别快!

最近我用你的0.5.0的chinadns+ss部署了一次明显发现国内网非常的快!翻墙也行

我想问个问题,用了dnscry是不是全部dns都走这了?是不是慢在这了

gitx6 commented 5 years ago

chinadns在本地把国内外域名分流了

zw963 commented 5 years ago

最近我用你的0.5.0的chinadns+ss部署了一次明显发现国内网非常的快!翻墙也行

竟然 chinadns+ss 还工作? 我好久不维护了 ......

我想问个问题,用了dnscry是不是全部dns都走这了?是不是慢在这了

不是的, 但是我采用的是硬编码的方式加入国内的域名,很大程度依赖于 https://github.com/felixonmars/dnsmasq-china-list, 要经常更新,要经常去那边提 issue, 把你认为是国内的域名提交给他们。

zw963 commented 5 years ago

BTW: 请告知 “0.5.0的chinadns+ss” 的下载链接, 也许可以考虑再把 chinadns 加回来。

momobile commented 5 years ago

https://github.com/zw963/asuswrt-merlin-transparent-proxy/tags 你习惯挺好的,都打tag了,哈哈。

我感觉chinadns稳定速度也好,就算是只是翻墙域名解析打到vps也挺慢的,建议考虑效率。

zw963 commented 5 years ago

我感觉chinadns稳定速度也好,就算是只是翻墙域名解析打到vps也挺慢的,建议考虑效率。

如果的确可以解决 微博,小红书,百度 的问题,我可以考虑把 chinadns 加回来,我个人你说的这些站点几乎从来不上,所以没啥影响,哈。

zw963 commented 5 years ago

你再测试一段时间 chinadns 是否正常,因为我自己已经很久不用这个版本了, 非常感谢你可以确认,这个版本竟然还可以正常工作。

如果 OK, 我会把它加回来,和其他的一些最新的组件集成在一起。

momobile commented 5 years ago

连续运行一周,表现很好,很稳定! 唯一缺点是极少数外国网站不能自动识别,没有走ss代理

zw963 commented 5 years ago

Cool

momobile notifications@github.com 于 2019年5月19日周日 上午12:56写道:

连续运行一周,表现很好,很稳定! 唯一缺点是极少数外国网站不能自动识别,没有走ss代理

— 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/82?email_source=notifications&email_token=AAEGCBSNVTAQEQ3U7PDE343PWAYKHA5CNFSM4HISYCJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVWSDOA#issuecomment-493691320, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEGCBSRWBUX4J32BCKFGQ3PWAYKHANCNFSM4HISYCJQ .

momobile commented 5 years ago

现在还有一个问题就是你脚本中对于chinadns加载的,中国域名白名单,使用了http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest 我调研了一下,这个名单是apnic亚洲的,有些中国域名不在那里面,会有很多ip不准确。我换了一个觉ipip的数据,但是发现即便不在chinadns_chnroute.txt名单里面,但是依然没有走代理这是什么情况?

gitx6 commented 5 years ago

/etc/dnsmasq.d/*.conf 某个文件指定这个域名直连了。

HaoweiCh commented 5 years ago

昨天刚拿到 AC88U 安装包管理器都因为网络问题长时间无反应而导致 session 中断。烦都烦死了

zw963 commented 5 years ago

我调研了一下,这个名单是apnic亚洲的,有些中国域名不在那里面,会有很多ip不准确。我换了一个觉ipip的数据

请提供下你说的 ipip 数据下载链接.

BTW: 确保改完后, 执行 /opt/etc/patch_router 让新的 ip 名单生效, 也可能是 wangxin6 说的那个原因.

zw963 commented 5 years ago

安装包管理器都因为网络问题长时间无反应而导致 session 中断。烦都烦死了

运行那个脚本出现这个问题? 你的网络不是长城吧? 如果是, 无解......