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.33k stars 459 forks source link

仅能ping通tinyFecVPN的server #35

Closed hughgr closed 6 years ago

hughgr commented 6 years ago

首先非常感谢作者的无私分享

描述:

使用已经去掉限制,重新编译过的tinyFevVPN建立链接后,仅能ping通过server,不能访问其他页面.

步骤:

server

 iptables -t nat -A POSTROUTING -s 10.222.0.0/16 -j SNAT --to-source VPS_SERVER_ADDR(vps外网ip)
 sudo nohup ./tinyvpn_amd64 -s -l 0.0.0.0:8855 --sub-net 10.222.2.0 --tun-dev tun100 --report 10 -k 1234 --mode 0 -f2:4 -q1 &

route -n

0.0.0.0         10.146.0.1      0.0.0.0         UG    0      0        0 eth0
10.146.0.1      0.0.0.0         255.255.255.255 UH    0      0        0 eth0
10.222.2.2      0.0.0.0         255.255.255.255 UH    0      0        0 tun100

iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

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
SNAT       all  --  10.222.0.0/16        anywhere             to: VPS_SERVER_ADDR

client(已经清空iptables的虚拟机,本来准备搞好以后做为windows的网关)

nohup ./tinyvpn_x86 -c -r  VPS_SERVER_ADDR:8855 --sub-net 10.222.2.0 --tun-dev tun100 --keep-reconnect --report 10 -k 1234 --mode 0 -f2:4 -q1 &

iptables -t nat -A POSTROUTING -s 192.168.31.0/24 -o tun100 -j MASQUERADE 
ip route add  VPS_SERVER_ADDR/32 via 192.168.31.1(路由器ip) dev eth0
ip route add 0.0.0.0/1 via 10.222.2.1 dev tun100
ip route add 128.0.0.0/1 via 10.222.2.1 dev tun100

route -n

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.222.2.1      128.0.0.0       UG    0      0        0 tun100
0.0.0.0         192.168.31.1    0.0.0.0         UG    0      0        0 eth0 (不重要)
10.222.2.1      0.0.0.0         255.255.255.255 UH    0      0        0 tun100
128.0.0.0       10.222.2.1      128.0.0.0       UG    0      0        0 tun100
192.168.31.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0(不重要)
192.168.31.1    0.0.0.0         255.255.255.255 UH    0      0        0 eth0(不重要)

iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

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
MASQUERADE  all  --  192.168.31.0/24      anywhere

Chain postrouting_rule (0 references)
target     prot opt source               destination

Chain prerouting_rule (0 references)
target     prot opt source               destination

问题

应该说是按照文档一步步来的,不知道哪里出了问题,另外在client上为什么还要做ip route add 128.0.0.0/1 via 10.222.2.1 dev tun100这一步?

使用是GCP的机器,入站规则啥的全都允许了

求大神解答

wangyu- commented 6 years ago

贴出ip routeiptable-save的输出。你贴的命令显示的信息不全,iptables只显示了nat表的内容。

贴出tinyfecvpn server端的log。

另外在client上为什么还要做ip route add 128.0.0.0/1 via 10.222.2.1 dev tun100这一步?

ip route add 0.0.0.0/1 via 10.222.2.1 dev tun100
ip route add 128.0.0.0/1 via 10.222.2.1 dev tun100

这两个规则是一组,分别负责一半的地址空间。

threekidney commented 6 years ago

iptables -t nat -A POSTROUTING -s 10.222.0.0/16 -j SNAT --to-source IP(如果服务器是单内网网卡,IP地址不要写外网IP,而是内网网卡IP)

hughgr commented 6 years ago

@threekidney 非常感谢三腰子兄 这样就说的通了 之前SNAT过去直接写的外网ip 难怪ip包出去的时候是能出去,回来的时候应该直接就被丢掉了

hughgr commented 6 years ago

@wangyu- mangle,filter,raw表没什么具体的内容 所以就没贴了

ip route add 0.0.0.0/1 via 10.222.2.1 dev tun100

我理解这句话就直接把所有流量通过tun100转发了啊?

wangyu- commented 6 years ago

注意0.0.0.0/1不是0.0.0.0/0