wangyu- / tinyfecVPN

A VPN Designed for Lossy Links, with Build-in Forward Error Correction(FEC) Support. Improves your Network Quality on a High-latency Lossy Link.
MIT License
2.28k stars 457 forks source link

请教tinyfecVPN的NAT设置,现在 "No route to host" #45

Closed ghost closed 6 years ago

ghost commented 6 years ago

你好, 作者

我的服务端和客户端都是centos7,客户端是本地虚拟机。 我去除代码中限制后,自己编译后使用,能正常连接。 ping 10.22.22.1 正常。
根据你在另一处的wiki提示,我打开ipforward,然后添加了这条: iptables -t nat -A POSTROUTING -s 10.22.0.0/16 ! -d 10.22.0.0/16 -j MASQUERADE 再在客户端机器上加了route:

[root@localhost ~]# ip route show
0.0.0.0/1 via 10.22.22.1 dev tun100 metric 99 
default via 192.168.227.2 dev ens33 proto static metric 100 
10.22.22.1 dev tun100 proto kernel scope link src 10.22.22.2 
45.xx.xx.xx via 192.168.227.2 dev ens33 proto static metric 88 
128.0.0.0/1 via 10.22.22.1 dev tun100 metric 99 
192.168.227.0/24 dev ens33 proto kernel scope link src 192.168.227.128 metric 100 

然后网络访问就会一直No route to host:

[root@localhost ~]# curl -v china.com
* About to connect() to china.com port 80 (#0)
*   Trying 222.186.130.58...
* No route to host
*   Trying 101.254.216.10...
* No route to host
*   Trying 101.64.239.158...
* No route to host
* Failed connect to china.com:80; No route to host
* Closing connection 0
curl: (7) Failed connect to china.com:80; No route to host

但ping对应ip均正常。 用nc来尝试连接三方外网机器时,也显示 no route to host,没加路由时则正常。 在服务端和客户端之间尝试,则似乎udp包都没接收到,无反应无错误(是被nat转发到空气了么?)

请问我这种情况是NAT规则在服务端没加好的原因吗? 可否简单指下路啊,谢谢 :)

ghost commented 6 years ago

这些尝试也无效:

# Masquerade outgoing traffic
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

# Allow return traffic
iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT

# Forward everything
iptables -A FORWARD -j ACCEPT

(服务端加了--tun-dev tun0 的)

wangyu- commented 6 years ago

假设你看的是这个教程:

https://github.com/wangyu-/tinyfecVPN/wiki/redirect-all-traffic-through-tinyfecVPN

看你的描述,nc和curl不正常,ping正常。也就是icmp正常tcp不正常。 我在教程里说的命令是针对全流量的,并没有tcp和icmp分开对待。

有可能你机器上原有的iptables命令和教程里讲的有冲突。照这个连接把两边的所有iptables清空后重新操作:

https://github.com/wangyu-/tinyfecVPN/wiki/how-to-fully-clear-iptables

类似问题:

https://unix.stackexchange.com/questions/353452/no-route-to-host-with-nc-but-can-ping

ghost commented 6 years ago

感谢!
这下通了。
看来确实是iptables冲突了,乱了。 centos默认安装后,iptables条目都太多了……
不像debian,默认条目比较少。