Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What to Do with chnroutes #24

Closed
lsylsy2 opened this issue Oct 10, 2014 · 28 comments
Closed

What to Do with chnroutes #24

lsylsy2 opened this issue Oct 10, 2014 · 28 comments

Comments

@lsylsy2
Copy link

lsylsy2 commented Oct 10, 2014

有提到”很痛恨openvpn断了之后,半分钟才能重连“,我目前自用的是openvpn static模式,当网络变化的时候,主要的网络中断是耗在了chnroute上……
我(以及chnroute官网等大多数人)使用的方案是设置国内路由直连,之后将默认路由设置为VPN(通过设置0.0.0.0/1与128.0.0.0/1两条路由)的形式;优点是路由条目比较少,缺点是一旦出现问题VPN断开,国外网络就会直接断掉;
之前曾经想过一个思路,把路由表放到VPN程序内部做;系统级别,VPN连接着的时候所有数据走VPN,VPN断开时所有数据该怎么走怎么走;显然,这样会有性能问题。
@clowwindy 有什么好法子解决这个?

PS:有考虑过client的配置文件里写多个server,随机选择or顺序尝试第一个成功连接的?openvpn是有这个功能的,可以考虑用心跳之类的机制来保持stateless的情况下判断服务器是否连通?

@clowwindy
Copy link
Owner

VPN 不会断,因为它是无状态的。
只有 wan 会断。只要 wan 的路由发生变化时能很快恢复就行了。
我的方案是先改默认路由,再添加国内路由。
我的路由器执行 chnroutes 只需要十秒钟左右,而且执行完之前也不是不能上网,只是全走国外,所以感觉不是问题
多个服务器自动切换感觉挺有用的。

@cj1324
Copy link
Collaborator

cj1324 commented Oct 11, 2014

考虑改用ipset吗?好处是这样可以和tun设备的创建或回收解耦。

也方便用户自定义ipset 列表。

@clowwindy
Copy link
Owner

是一个办法,通用性好一些,不过担心性能不如路由表。

@clowwindy
Copy link
Owner

@aa65535 @cj1324 @linusyang

写了一个反转 IP 段的工具:
https://github.com/clowwindy/ShadowVPN/blob/master/tools/negate_network.py

对 chnroutes + 保留 IP 段反转后,得到国外 IP 段。可以看看生成的结果有没有 bug:
https://github.com/clowwindy/ShadowVPN/blob/master/tools/foreign.txt

结果 6000 多条,比 chnroutes 多 50%,不过应该性能差不多。这样就可以反过来不改默认路由,只写 VPN 的路由了。

@aa65535
Copy link
Collaborator

aa65535 commented Oct 15, 2014

比 chnroutes 多了不到2000条,影响不大,有时间测试一下。

@lsylsy2
Copy link
Author

lsylsy2 commented Oct 15, 2014

看了一下chnroute本身,不太清楚它的IP段是如何获取的……
理论上,应该很大部分都是可以优化的?我自己在教育网,教育网免费地址列表精简之后只有不到1000行

@cj1324
Copy link
Collaborator

cj1324 commented Oct 15, 2014

我对chnroutes依赖不是很大。 我只是少量网站需要翻墙,所以通过dns解析 + ipset 就满足了。

@clowwindy
Copy link
Owner

这一份就是根据 apnic 取得的准确的最新国内 IP 段,简化过的都是不准确的。

要简化可以直接修改代码过滤掉比较小的 IP 段,即把一部分国内 IP 段误判成国外:

     ex_subnet = ip_network(line)
+    if ex_subnet.prefixlen >= 18:
+        continue
     i = bisect.bisect_right(s, ex_subnet) - 1

当然也可以反过来,对生成的结果做过滤,把一部分国外 IP 段误判成国内。

@aa65535
Copy link
Collaborator

aa65535 commented Oct 15, 2014

@clowwindy
今天发现连接不上国外 IP 的问题是在 防火墙基本设置转发 默认是 REJECT 的,
需要改成 ACCEPT 才能正常连接国外地址。

所以 client_up.sh 的 iptables 部分可以改成这个试试。

iptables -t nat -A POSTROUTING -o $intf -j MASQUERADE
iptables -P FORWARD ACCEPT
iptables -D delegate_forward -j reject>/dev/null 2>&1

我只测试了二级路由和 LAN - LAN 连接两种方式,pppoe 拨号没条件测试,有条件的可以测试一下。

至于 client_down, 可以使用 /etc/init.d/firewall restart>/dev/null 2>&1 重启防火墙来清除规则。

@clowwindy
Copy link
Owner

@aa65535
我担心直接 iptables -P FORWARD ACCEPT 会有安全性问题,需要确认一下。

@aa65535
Copy link
Collaborator

aa65535 commented Oct 16, 2014

@clowwindy 如果担心安全性问题的话,可以改成这样,昨天忘记测试这个情况了。

iptables -t nat -A POSTROUTING -o $intf -j MASQUERADE
iptables -A FORWARD -i $old_intf -o $intf -j ACCEPT
iptables -A FORWARD -i $intf -o $old_intf -j ACCEPT
iptables -D delegate_forward -j reject>/dev/null 2>&1

就是在原有的后面加一条 iptables -D delegate_forward -j reject

@cj1324
Copy link
Collaborator

cj1324 commented Oct 16, 2014

不建议采用这种方式改iptables 规则, 尽量采用uci

http://wiki.openwrt.org/doc/uci/firewall?s[]=firewall

config include
       option path /etc/shadowVPN.vpn

@clowwindy
Copy link
Owner

涉及到 delegate_forward 这样只有 OpenWRT 才有的表的话 client_up.sh 就不通用了。最好只在打 OpenWRT 包时使用。

@aa65535
Copy link
Collaborator

aa65535 commented Oct 16, 2014

@cj1324
直接使用命令的话可以做到关闭服务后不留下配置痕迹,如果直接写在 uci 的话不是很方便。

@clowwindy
delegate_forward 不存在的话, iptables 会报错,不影响整体。

@clowwindy
Copy link
Owner

最好是用 if 判断一下再执行,不要打个错误出来。从经验上看,哪怕错误没有影响,用户也会被吓到的,然后就会觉得这个软件有问题不稳定。

@aa65535
Copy link
Collaborator

aa65535 commented Oct 16, 2014

后面有加 >/dev/null 2>&1 屏蔽错误。

@clowwindy
Copy link
Owner

这样也行吧。

@yy1984
Copy link

yy1984 commented Nov 8, 2014

autoddvpn有个脚本,从gfwlist获得域名,然后用国外DNS解析获得IP。我在这基础上改进了一下,把所有ip变成/16网段,再在bgp.he.net上根据ASN获得几个重要企业的IP网段如google、facebook、twitter等,进行合并后得到500条记录,然后去除里面的中国IP最终只有880条记录。

@clowwindy
Copy link
Owner

但是这些网站在不同地区和时间解析结果是不一样的,也就是说这些记录不适合打包在项目里,只适合在路由器上定时自动跑更新

@yy1984
Copy link

yy1984 commented Nov 8, 2014

要选择世界各地的DNS解析再合并,可以稍微改善结果,整个脚本运行需要1小时左右,可以在VPS上定时更新。用路由表比较适合低端的路由器。最好的方式当然是iptables+ipset+dnsmasq+ip rule,完全自动,但是比较费CPU

@lsylsy2
Copy link
Author

lsylsy2 commented Nov 8, 2014

查了下,很多人现在shadowsocks+ss_redir用的就是ipset,反馈是采用RC4-MD5之后的性能很不错,可以认为目前主流的openwrt路由器(AR9331之类)可以承受ipset?

@cj1324
Copy link
Collaborator

cj1324 commented Nov 8, 2014

@lsylsy2 我就是采用这种方式, 一般有1500个ip ,性能方面没有测试过,只要服务器连通性够好。看1080P 无压力。

@xtheo
Copy link

xtheo commented Nov 18, 2014

我尝试在国内的服务器上部署shadowvpn+chnroute.
路由表使用的是clowwindy反转的forigen.txt.
其中 208.0.0.0/7 这一条有问题。
通过命令行 route add -net 208.0.0.0/7 gw 10.7.0.1 加入路由表后,
会导致shadowvpn的cpn占用急剧变高。
删掉这行后正常。

@clowwindy
Copy link
Owner

@xtheo 那你的 vps ip 就落在这个 IP 段里咯。

@xtheo
Copy link

xtheo commented Nov 18, 2014

完全不是,我的vps是107.170开头digitalocean的

@clowwindy
Copy link
Owner

那就是某个经常访问的 IP 在这个 IP 段。

@airtheva
Copy link

What about this?
https://github.com/ashi009/bestroutetb

@clowwindy
Copy link
Owner

@airtheva IMO not neccessary. It's only 1% faster, but it will leads to unforeseen routes in countries other than CN, US, UK, JP.

@clowwindy clowwindy changed the title 对chnroute打算如何处理? What to Do with chnroutes Dec 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants