Repository navigation
Description
完整性要求
- 我读完了 issue 模板中的所有注释,确保填写符合要求。
- 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
- 我提供了完整的配置文件和日志,而不是出于自己的判断只给出截取的部分。
- 我搜索了 issues, 没有发现已提出的类似问题。
- 问题在 Release 最新的版本上可以成功复现
描述
Xray 26.9.9 (Xray, Penetrates Everything.) 52a412d (go1.27.1 windows/amd64)
TUN入站,并配置 sniffing+routeOnly,出站 freedom+domainStrategy: AsIs
Xray 程序启动后,前几秒直连 IPv6 可以正常连接。过了几秒后,直连 IPv6 流量无法连接。
测试命令:
curl -v -I https://www.baidu.com --resolve 'www.baidu.com:443:[2408:871a:2100:186c:0:ff:b07e:3fbc]' --max-time 3
附上的 log 里面有两次测试连接,第一次 [17:13:46] 是前几秒能够连接的,第二次 [17:13:56] 是后面开始不能连接的。
可以看到第二次连接缺少了后面的proxy/freedom: connection opened to tcp:[2408:871a:2100:186c:0:ff:b07e:3fbc]:443, local endpoint [my00:home:ipv6:addr::]:10658, remote endpoint [2408:871a:2100:186c:0:ff:b07e:3fbc]:443
与 #6281 问题相同,但前面的 issue 最终无反馈,因此新开一个 issue
重现方式
见描述和配置
客户端配置
Details
{
"log": {
"access": "access.log",
"error": "error.log",
"dnsLog": true,
"loglevel": "debug"
},
"inbounds": [
{
"tag": "in-tun",
"protocol": "tun",
"settings": {
"name": "tun0",
"mtu": 1400,
"gateway": ["10.0.0.1/16", "fdfe::1/64"],
"userLevel": 0,
"autoSystemRoutingTable": ["0.0.0.0/0", "::/0"],
"autoOutboundsInterface": "auto"
},
"sniffing": {
"enabled": true,
"routeOnly": true,
"destOverride": [
"http",
"tls",
"quic"
]
}
}
],
"outbounds": [
{
"tag": "out-direct",
"protocol": "freedom",
"settings": {
"domainStrategy": "AsIs"
}
}
]
}
服务端配置
NONE
客户端日志
Xray access.log:
access.log
Xray error.log:
error.log
curl log:
PS C:\Users\homepc> curl -v -I https://www.baidu.com --resolve 'www.baidu.com:443:[2408:871a:2100:186c:0:ff:b07e:3fbc]' --max-time 3
* Added www.baidu.com:443:[2408:871a:2100:186c:0:ff:b07e:3fbc] to DNS cache
* Hostname www.baidu.com was found in DNS cache
* Host www.baidu.com:443 was resolved.
* IPv6: 2408:871a:2100:186c:0:ff:b07e:3fbc
* IPv4: (none)
* Trying [2408:871a:2100:186c:0:ff:b07e:3fbc]:443...
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* ALPN: server accepted http/1.1
* Established connection to www.baidu.com (2408:871a:2100:186c:0:ff:b07e:3fbc port 443) from fdfe::1 port 10657
* using HTTP/1.x
> HEAD / HTTP/1.1
> Host: www.baidu.com
> User-Agent: curl/8.21.0
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
< Content-Length: 0
Content-Length: 0
< Content-Type: text/html
Content-Type: text/html
< Pragma: no-cache
Pragma: no-cache
< Server: bfe
Server: bfe
< Set-Cookie: BAIDUID=90D90D3CFC9D59C03F226F0B72628458:FG=1; Path=/; Domain=baidu.com; Max-Age=31536000
Set-Cookie: BAIDUID=90D90D3CFC9D59C03F226F0B72628458:FG=1; Path=/; Domain=baidu.com; Max-Age=31536000
< Set-Cookie: BAIDUID_BFESS=90D90D3CFC9D59C03F226F0B72628458:FG=1; Path=/; Domain=baidu.com; Max-Age=31536000; Secure; SameSite=None
Set-Cookie: BAIDUID_BFESS=90D90D3CFC9D59C03F226F0B72628458:FG=1; Path=/; Domain=baidu.com; Max-Age=31536000; Secure; SameSite=None
< Date: Thu, 17 Sep 2026 09:13:45 GMT
Date: Thu, 17 Sep 2026 09:13:45 GMT
<
* Connection #0 to host www.baidu.com:443 left intact
PS C:\Users\homepc> curl -v -I https://www.baidu.com --resolve 'www.baidu.com:443:[2408:871a:2100:186c:0:ff:b07e:3fbc]' --max-time 3
* Added www.baidu.com:443:[2408:871a:2100:186c:0:ff:b07e:3fbc] to DNS cache
* Hostname www.baidu.com was found in DNS cache
* Host www.baidu.com:443 was resolved.
* IPv6: 2408:871a:2100:186c:0:ff:b07e:3fbc
* IPv4: (none)
* Trying [2408:871a:2100:186c:0:ff:b07e:3fbc]:443...
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* Connection timed out after 3013 milliseconds
* closing connection #0
curl: (28) Connection timed out after 3013 milliseconds
服务端日志
NONE
Activity
Fangliding commentedon Sep 18, 2026
#6281 (comment)
不是你自己无视?
simplerick-simplefun commentedon Oct 2, 2026
破案了,具体情况见下面的回复:#6776 (comment)
我测试了下。
用抓包看,可以看到测试流量进入了 xray tun 网卡,但是没有被转发到 Ethernet 网卡。对于“Xray tun 启动后,前几秒直连 IPv6 可以正常连接”的情况,是正常转发的,但“过了几秒后,直连 IPv6 流量无法连接”的情况,就不再转发到 Ethernet 网卡了。抓包图中可以看到 4秒时 测试连接成功,23秒时 测试连接失败。
仔细看这个抓包的图,似乎能看到问题:curl 从 [fdfe::1] 经过 xray tun 网卡发送流量给 公网ipv6,下一步应该是 xray 程序从本地 ipv6 经过 绑定的 Ethernet 网卡 转发流量给 公网ipv6,但是 经过的网卡变成了 xray tun,于是流量发不出去。
手动配置 autoOutboundsInterface 或 streamSettings.sockopt.interface 为网卡名后,没有变化。
没有手动配置 autoSystemRoutingTable,因为看起来xray对路由表的变更也很正常:
原始路由表:
改变后的表:
simplerick-simplefun commentedon Oct 3, 2026
又研究了一下,破案了。windows 11 的网卡有个属性:-WeakHostSend 和 -WeakHostReceive
可以通过命令查看:
Get-NetIPInterface | Select-Object InterfaceIndex, InterfaceAlias, AddressFamily, WeakHostSend, WeakHostReceive我的有线和无线网卡,默认的属性是,ipv4 两个属性都是 Disabled,而 ipv6 默认是
WeakHostSend: Enabled, WeakHostReceive: Disabled问题就出在这个
WeakHostSend: Enabled上面:此时,即便程序将 socket 绑定了某个特定的网卡/gateway/network interface,Windows也会无视并根据路由表选择网卡。所以实际情况是:xray 为直连出站绑定了 Ethernet 网卡,但是 Ethernet 网卡默认配置是 ipv6 WeakHostSend: Enabled,于是这个直连出站的连接被windows无视了绑定网卡,而是通过路由表检查发现应该通过 xray tun 网卡发送,最终被系统分配给 xray tun 网卡。
手动修复:
Set-NetIPInterface -InterfaceIndex nn -WeakHostSend Disabled -WeakHostReceive Disabled。改好后,重启系统不会重置配置,不需要每次重启系统都手动修改一次。这个太坑了,不知道别的vpn tun怎么处理的,sing-box tun怎么处理的。虽然可以手动命令修复,但是这显然不是个大众的解决方案。
附:https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/netsh-interface
描述:
weakhostsend - Enables weak host send behavior, allowing the interface to send packets even if the source IP doesn't belong to the interface.RPRX commentedon Oct 5, 2026
这个属于回环问题,我觉得
autoOutboundsInterface在 Windows 上自动执行一下上面的命令吧,毕竟这选项就是确保不回环@patternihaRPRX commentedon Oct 5, 2026
又一个因 Windows 系统自作聪明所导致的问题patterniha commentedon Oct 5, 2026
I checked this issue when it was first reported, but I couldn’t reproduce it.
No, both WeakHostSend and WeakHostReceive are disabled by default, for IPv4 and IPv6, so something on your device has enabled it. Anyway, we can add a check for them.
RPRX commentedon Oct 5, 2026
原来不是 Windows 的锅吗,不过这个要么 core 自动改要么报错退出吧,不然跑起来后回环 100% CPU 也废了啊RPRX commentedon Oct 5, 2026
或者可能很快耗尽临时端口,歇几秒后 handshake 超时释放一大批,这样不断循环patterniha commentedon Oct 5, 2026
We can temporarily disable WeakHostSend on the outbound interface and restore it to its original state after the TUN stops. WeakHostReceive isn't involved, so it's left alone.
The only issue is that if the Xray process suddenly stops for any reason, WeakHostSend stays disabled until the next reboot, which is the Windows default anyway.
Opus has implemented this, and I tested it: with WeakHostSend on for IPv6, direct IPv6 stalls on the current build and works with the fix. I'll open a PR soon.
LjhAUMEM commentedon Oct 5, 2026
wireguard windows simply prints a warning
https://github.com/WireGuard/wireguard-windows/blob/6ece77bc487c8aa697e3c092197621c4f3e5ccb8/tunnel/pitfalls.go#L174-L176
patterniha commentedon Oct 5, 2026
Yes I changed that as well, so now it just prints a message.
patterniha commentedon Oct 5, 2026
When Mobile Hotspot is on together with the TUN, it has to share the TUN interface, not Wi-Fi. Sharing Wi-Fi turns on forwarding there, which makes Windows ignore
autoOutboundsInterface, so Xray's own connections stall. Xray now detects this every time it happens, at start or later, and logs a warning saying to share the TUN instead:Settings → Network & internet → Mobile hotspot → Share my internet connection from → xray-tun
The TUN only appears in that list while Xray is running. Sharing it also sends the hotspot's devices through Xray.
TUN inbound: Handle weak host send and forwarding on the outbound int…
TUN inbound: Handle weak host send and forwarding on the outbound int…
TUN inbound: Document weak host send and forwarding for `autoOutbound…