apernet / hysteria

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

客户端dig youtube.com @8.8.8.8提示address已被占用 #569

Open PHCSJC opened 1 year ago

PHCSJC commented 1 year ago

正常配置,测试全部都通,上网都正常,但唯独下面的命令不行,会报address已被占用,看了看文档,是不是因为"resolver": "udp://1.1.1.1:53这个占用了53端口呢?但实际上我的配置文件里并没有加这个

dig youtube.com @8.8.8.8 报错如下: [DEBU] [src:192.168.1.100:48194] [dst:8.8.8.8:53] UDP TProxy request [INFO] [src:192.168.1.100:48194] [dst:8.8.8.8:53] [error:dial: socket bind: address already in use] UDP TProxy error [DEBU] [src:192.168.1.100:48194] [dst:8.8.8.8:53] UDP TProxy request [INFO] [src:192.168.1.100:48194] [dst:8.8.8.8:53] [error:dial: socket bind: address already in use] UDP TProxy error

测试版本:v1.3.3 服务端配置:

{ "listen": ":777", "protocol": "wechat-video", "cert": "wechat.com.crt", "key": "wechat.com.key", "obfs": "123456", "up_mbps": 500, "down_mbps": 500, "disable_mtu_discovery": true, "alpn": "h3" }

客户端配置:

{ "server": "1.2.3.4:777", "protocol": "wechat-video", "retry": -1, "obfs": "123456", "up_mbps": 50, "down_mbps": 300, "tproxy_tcp": { "listen": ":1090" }, "tproxy_udp": { "listen": ":1090" }, "insecure": false, "ca": "wechat.com.ca.crt", "alpn": "h3", "fast_open": true, "disable_mtu_discovery": true, "server_name": "wechat.com" }

PHCSJC commented 1 year ago

简单说就是:tproxy_udp模式下,如果目标是udp53端口就不通,其他端口都可以通 QQ截图20230215082730

PHCSJC commented 1 year ago

我又试了试,确实是目标udp53端口就不通,测试方法:在client用5353端口解析,在server端重定向5353端口至53,这样就避开了53端口,就通了

server端: iptables -t nat -A OUTPUT -d 8.8.8.8 -p udp --dport 5353 -j DNAT --to-destination 8.8.8.8:53

clent端测试: dig youtube.com @8.8.8.8 -p 5353 正常解析!

soffchen commented 4 months ago

我又试了试,确实是目标udp53端口就不通,测试方法:在client用5353端口解析,在server端重定向5353端口至53,这样就避开了53端口,就通了

server端: iptables -t nat -A OUTPUT -d 8.8.8.8 -p udp --dport 5353 -j DNAT --to-destination 8.8.8.8:53

clent端测试: dig youtube.com @8.8.8.8 -p 5353 正常解析!

你服务器上监听 53 端口的 dns 服务,不要用 0.0.0.0,就用 192.168.1.1 这种,就不会出现这个问题,试试看。

PHCSJC commented 4 months ago

@soffchen 就是用的8.8.8.8,不是自建DNS,简单说:

dig youtube.com @8.8.8.8 -p 53       <=====报错
dig youtube.com @8.8.8.8 -p 6666      <=====正常,要配合下面的iptables
server端:
iptables -t nat -A OUTPUT -d 8.8.8.8 -p udp --dport 6666 -j DNAT --to-destination 8.8.8.8:53
soffchen commented 4 months ago

@soffchen 就是用的8.8.8.8,不是自建DNS,简单说:

dig youtube.com @8.8.8.8 -p 53       <=====报错
dig youtube.com @8.8.8.8 -p 6666      <=====正常,要配合下面的iptables
server端:
iptables -t nat -A OUTPUT -d 8.8.8.8 -p udp --dport 6666 -j DNAT --to-destination 8.8.8.8:53

是说你服务器端有程序监听了 53 端口,比如 resolve-systemd 这种,都会,TPROXY 的 on-ip 不要跟那个监听的 ip 同一个,就不会出现这个问题了。

PHCSJC commented 4 months ago

@soffchen 服务器端没有任何监听53端口的程序,即使有,也不影响访问8.8.8.8:53

CCCAUCHY commented 3 weeks ago

确实有莫名奇妙的"被占用问题", 用iperf3进行udp测试, 根本无法测通,, 跟iptables无关, tcp是正常的 客户端:

tcpTProxy:
  listen: :2500
udpTProxy:
  listen: :2500

WARN UDP transparent proxy error {"addr": "127.0.0.1:53367", "reqAddr": "127.0.0.1:2500", "error": "dial: socket bind: address already in use"}

iperf3 -c 127.0.0.1 -p 2500   -u
Connecting to host 127.0.0.1, port 2500
^C- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
iperf3: interrupt - the client has terminated

服务端显示已经收到客户端的接收请求, 说明已经连上, 但是无法进行udp传输:

iperf3 -s -p 2500
-----------------------------------------------------------
Server listening on 2500 (test #1)
-----------------------------------------------------------
Accepted connection from 127.0.0.1, port 56874
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Jitter    Lost/Total Datagrams
iperf3: the client has terminated