apernet / hysteria

Hysteria is a powerful, lightning fast and censorship resistant proxy.
https://v2.hysteria.network/
MIT License
13.83k stars 1.56k forks source link

[请求帮助] TUN 模式无法连接特定主机 #402

Open wizd opened 1 year ago

wizd commented 1 year ago

问题详情

客户端 TUN 模式,无法访问同机房的另外一台VPS,Log 显示连接被拒绝。

[INFO] forward tcp request 10.3.3.1:49013->50.116.9.x:443: connection was refused

50.116.9.x 是另外一个跟Hysteria服务器同一机房内的VPS。在服务器上netcat测试连接正常。

root@localhost:~/hysteria_server# nc 50.116.9.x 443 -vv Connection to 50.116.9.x 443 port [tcp/https] succeeded!

服务端安装信息或者一键脚本信息

hysteria version v1.2.0 2022-08-14T01:56:17.587Z 944c0ecf646324c0151b026a55752c23378b909c

VPS 信息

Linode Fremont $5

服务端配置

{ "listen": ":4912", "protocol": "faketcp", "cert": "/root/hysteria_server/example.crt", "key": "/root/hysteria_server/example.key", "obfs": "fuck me till the daylight", "up_mbps": 100, "down_mbps": 100 }

服务端日志

2022-08-14T16:36:21Z [DEBU] [src:124.240.55.x:15434] [dst:50.116.9.x:80] [action:Direct] TCP request 2022-08-14T16:36:21Z [INFO] [src:124.240.55.x:15434] [dst:50.116.9.x:80] [error:dial tcp 50.116.9.x:80: connect: connection refused] TCP error

客户端安装信息

hysteria version v1.2.0 2022-08-14T01:56:17.587Z 944c0ecf646324c0151b026a55752c23378b909c

客户端配置

{ "server": "104.237.153.x:4912", "protocol": "faketcp", "obfs": "fuck me till the daylight", "up_mbps": 100, "down_mbps": 100, "insecure": true, "socks5": { "listen": "0.0.0.0:1080" }, "http": { "listen": "0.0.0.0:8080" }, "tun": { "name": "tun0", "timeout": 300, "mtu": 1500 } }

客户端运行环境(操作系统)

Ubuntu 22.04

客户端日志

2022-08-14T16:50:01Z [INFO] forward tcp request 10.3.3.1:42619->50.116.9.x:443: connection was refused

wizd commented 1 year ago

可能是跟MPTCP有关?无法连接的主机是一个聚合节点。普通连接是没问题的。猜想MPTCP的链路添加了某些TCP头字段?

2022-08-14T19:33:31Z [DEBU] [src:10.3.3.1:57725] [dst:104.244.36.20:443] TUN TCP request 2022-08-14T19:33:37Z [DEBU] [src:10.3.3.1:57600] [dst:54.159.69.114:443] TUN TCP EOF 2022-08-14T19:33:38Z [DEBU] [src:10.3.3.1:57703] [dst:68.67.160.114:443] TUN TCP EOF 2022-08-14T19:33:38Z [DEBU] [src:10.3.3.1:57704] [dst:68.67.160.114:443] TUN TCP EOF 2022-08-14T19:33:38Z [DEBU] [src:10.3.3.1:57583] [dst:35.171.147.18:443] TUN TCP EOF 2022-08-14T19:33:41Z [INFO] forward tcp request 10.3.3.1:51389->50.116.9.x:443: connection was refused 2022-08-14T19:33:42Z [DEBU] [src:10.3.3.1:57725] [dst:104.244.36.20:443] TUN TCP EOF 2022-08-14T19:33:42Z [DEBU] [src:10.3.3.1:57708] [dst:108.128.66.39:443] TUN TCP EOF 2022-08-14T19:33:43Z [DEBU] [src:10.3.3.1:57661] [dst:34.197.60.25:443] TUN TCP EOF 2022-08-14T19:33:44Z [DEBU] [src:10.3.3.1:57700] [dst:34.195.242.155:443] TUN TCP EOF 2022-08-14T19:33:45Z [DEBU] [src:10.3.3.1:57586] [dst:3.92.156.8:443] TUN TCP EOF 2022-08-14T19:33:46Z [DEBU] [src:10.3.3.1:57726] [dst:104.244.36.20:443] TUN TCP request 2022-08-14T19:33:47Z [INFO] forward tcp request 10.3.3.1:60219->50.116.9.x:443: connection was refused 2022-08-14T19:33:47Z [DEBU] [src:10.3.3.1:57715] [dst:34.232.108.172:443] TUN TCP EOF 2022-08-14T19:33:53Z [DEBU] [src:10.3.3.1:57616] [dst:74.6.138.192:443] TUN TCP EOF 2022-08-14T19:33:54Z [DEBU] [src:10.3.3.1:57636] [dst:69.147.92.12:443] TUN TCP EOF

haruue commented 1 year ago

要转发魔改的 TCP 协议, 建议使用提供 L3 (网络层)服务的 VPN, Hysteria 的 TUN 只转发连接状态和数据, 不保留魔改协议添加的自定义 TCP 选项。

haruue commented 1 year ago

考虑了下其实不太对。。 既然 nc 都能建立连接的话, hysteria server 作为 MPTCP 一端去建立连接应该也没问题(?)。 能不能说一下 50.116.9.x:443 50.116.9.x:443 上的 MPTCP 服务是如何配置的? 我想试试重现这个问题。

wizd commented 1 year ago

好的。该MPTCP节点是老的版本,所谓v0,(现在最新的内核是v1)。老版本的MPTCP聚合端不需要配置什么,只需要更新内核就可以了。客户端除更新内核之外,还需要配置几个路由规则。 https://multipath-tcp.org/pmwiki.php/Users/ConfigureRouting

我现在的配置是几个宽带上配置IPSEC,在其上由MPTCP聚合数据流,应用包括OpenVPN,SS,FPR之类的。尝试Hysteria代替IPSEC是想看看在高峰时段是否效率更高。

haruue commented 1 year ago

直接用 Hysteria 代替 IPSEC 肯定是不行的。 Hysteria 不会原样转发你的网络层数据包, TUN 模式只认识简单的 TCP 流和 UDP 数据报。

要实现你的目的, 我的建议是找个能把大量的 UDP 流量负载均衡到多条线路上的软件, 然后把 Hysteria 跑在它的上面。

另外 Hysteria 对非 TCP 流量不会有加速效果, 同时不建议通过 OpenVPN TCP 这样的做法强行把 L3 协议跑在 TCP 上(参考 Why TCP Over TCP Is A Bad Idea 以及 OpenVPN 官方对 TCP Meltdown 的解释)。

wizd commented 1 year ago

MPTCP 对 TCP 包增加了一个Option Header, 参考RFC6824第12页 https://www.rfc-editor.org/rfc/rfc6824.html

如果Hysteria不转发这个额外的Option Header的话,我想链接是建立不了的。因为这个字段包含了协议协商参数。

wizd commented 1 year ago

简单研究了一下tun2socks发现该库不会发送TCP option header出来,所以很遗憾理论上是无法支持mptcp的。

wizd commented 1 year ago

我们要不要创造一个协议Socks 6 Proxy以支持TCP Option Header 🤣🤣🤣

wizd commented 1 year ago

Socks6 有人已经设计好了: https://datatracker.ietf.org/meeting/99/materials/slides-99-intarea-socks6-00

Error996 commented 1 year ago

首先hysteria不是全状态的转发,即不是传统意义的L3 VPN 要想实现无额外附加的tcp/udp请求, 只需要给hysteria的tun增加ip,然后使用 route add -net x.x.x.x/24 tun_ip 给hysteria的tun增加路由表,即可访问,目前用来异地组网效率还是不错的

v-zza commented 1 year ago

I've ran into a similar issue on a different setup that uses shadowsocks + tun2socks. Apart from the socks6 proposal implementation (which in fact exactly solves this issue), is there any other way of forwarding TCP over a shadowsocks connection that would keep the option header?

E.g., I can route using ss-redir with netfilter redirect (example setup). But I'm not sure how to setup the MPTCP endpoint without using a tun device.