Skip to content

[不连接] TUN 入站,sniff+routeOnly+AsIs,直连 IPv6 流量无法连接 #6776

Closed

Description

@simplerick-simplefun

完整性要求

  • 我读完了 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

  1. Fangliding commented on Sep 18, 2026

    @Fangliding
    Member

    #6281 (comment)

    开个抓包跟踪一下或者不用两个auto自己配缩小范围

    不是你自己无视?

  2. simplerick-simplefun commented on Oct 2, 2026

    @simplerick-simplefun
    Author

    #6281 (comment)

    开个抓包跟踪一下或者不用两个auto自己配缩小范围

    不是你自己无视?

    破案了,具体情况见下面的回复:#6776 (comment)


    我测试了下。
    用抓包看,可以看到测试流量进入了 xray tun 网卡,但是没有被转发到 Ethernet 网卡。对于“Xray tun 启动后,前几秒直连 IPv6 可以正常连接”的情况,是正常转发的,但“过了几秒后,直连 IPv6 流量无法连接”的情况,就不再转发到 Ethernet 网卡了。抓包图中可以看到 4秒时 测试连接成功,23秒时 测试连接失败。

    Image

    仔细看这个抓包的图,似乎能看到问题:curl 从 [fdfe::1] 经过 xray tun 网卡发送流量给 公网ipv6,下一步应该是 xray 程序从本地 ipv6 经过 绑定的 Ethernet 网卡 转发流量给 公网ipv6,但是 经过的网卡变成了 xray tun,于是流量发不出去。

    手动配置 autoOutboundsInterface 或 streamSettings.sockopt.interface 为网卡名后,没有变化。
    没有手动配置 autoSystemRoutingTable,因为看起来xray对路由表的变更也很正常:
    原始路由表:

    > route print
    ===========================================================================
    Interface List
     11...00 23 57 3c 53 16 ......Realtek USB GbE Family Controller
     48...00 15 5d db 43 50 ......Hyper-V Virtual Ethernet Adapter
     17...38 f3 ab 34 9e e8 ......Realtek PCIe GbE Family Controller
      7...38 fc 98 8d 3e 0c ......Intel(R) Wi-Fi 6 AX200 160MHz
     14...38 fc 98 8d 3e 0d ......Microsoft Wi-Fi Direct Virtual Adapter
     19...3a fc 98 8d 3e 0c ......Microsoft Wi-Fi Direct Virtual Adapter #2
      3...38 fc 98 8d 3e 10 ......Bluetooth Device (Personal Area Network)
      1...........................Software Loopback Interface 1
    ===========================================================================
    
    IPv4 Route Table
    ===========================================================================
    Active Routes:
    Network Destination        Netmask          Gateway       Interface  Metric
              0.0.0.0          0.0.0.0     192.168.50.1   192.168.50.113     25
            127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
            127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
      127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
         172.29.240.0    255.255.240.0         On-link      172.29.240.1    271
         172.29.240.1  255.255.255.255         On-link      172.29.240.1    271
       172.29.255.255  255.255.255.255         On-link      172.29.240.1    271
         192.168.50.0    255.255.255.0         On-link    192.168.50.113    281
       192.168.50.113  255.255.255.255         On-link    192.168.50.113    281
       192.168.50.255  255.255.255.255         On-link    192.168.50.113    281
            224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
            224.0.0.0        240.0.0.0         On-link    192.168.50.113    281
            224.0.0.0        240.0.0.0         On-link      172.29.240.1    271
      255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
      255.255.255.255  255.255.255.255         On-link    192.168.50.113    281
      255.255.255.255  255.255.255.255         On-link      172.29.240.1    271
    ===========================================================================
    Persistent Routes:
      None
    
    IPv6 Route Table
    ===========================================================================
    Active Routes:
     If Metric Network Destination      Gateway
     17    281 ::/0                     fe80::3ad5:47ff:fedb:4350
      1    331 ::1/128                  On-link
     17    281 2408:aaaa:bbbbbbbb::/64 On-link
     17    281 2408:aaaa:xxxxxxxx:5740/128
                                        On-link
     17    281 2408:aaaa:xxxxxxxx:6abe/128
                                        On-link
     17    281 fe80::/64                On-link
     48    271 fe80::/64                On-link
     17    281 fe80::5fd6:22e3:e54f:fec4/128
                                        On-link
     48    271 fe80::8e08:8465:7ec8:f30c/128
                                        On-link
      1    331 ff00::/8                 On-link
     17    281 ff00::/8                 On-link
     48    271 ff00::/8                 On-link
    ===========================================================================
    Persistent Routes:
      None
    

    改变后的表:

    > route print
    ===========================================================================
    Interface List
     20...........................Wintun Tunnel
     11...00 23 57 3c 53 16 ......Realtek USB GbE Family Controller
     48...00 15 5d db 43 50 ......Hyper-V Virtual Ethernet Adapter
     17...38 f3 ab 34 9e e8 ......Realtek PCIe GbE Family Controller
      7...38 fc 98 8d 3e 0c ......Intel(R) Wi-Fi 6 AX200 160MHz
     14...38 fc 98 8d 3e 0d ......Microsoft Wi-Fi Direct Virtual Adapter
     19...3a fc 98 8d 3e 0c ......Microsoft Wi-Fi Direct Virtual Adapter #2
      3...38 fc 98 8d 3e 10 ......Bluetooth Device (Personal Area Network)
      1...........................Software Loopback Interface 1
    ===========================================================================
    
    IPv4 Route Table
    ===========================================================================
    Active Routes:
    Network Destination        Netmask          Gateway       Interface  Metric
              0.0.0.0          0.0.0.0     192.168.50.1   192.168.50.113     25
              0.0.0.0          0.0.0.0         On-link          10.0.0.1      0
             10.0.0.0      255.255.0.0         On-link          10.0.0.1    256
             10.0.0.1  255.255.255.255         On-link          10.0.0.1    256
         10.0.255.255  255.255.255.255         On-link          10.0.0.1    256
            127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
            127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
      127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
         172.29.240.0    255.255.240.0         On-link      172.29.240.1    271
         172.29.240.1  255.255.255.255         On-link      172.29.240.1    271
       172.29.255.255  255.255.255.255         On-link      172.29.240.1    271
         192.168.50.0    255.255.255.0         On-link    192.168.50.113    281
       192.168.50.113  255.255.255.255         On-link    192.168.50.113    281
       192.168.50.255  255.255.255.255         On-link    192.168.50.113    281
            224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
            224.0.0.0        240.0.0.0         On-link    192.168.50.113    281
            224.0.0.0        240.0.0.0         On-link      172.29.240.1    271
      255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
      255.255.255.255  255.255.255.255         On-link    192.168.50.113    281
      255.255.255.255  255.255.255.255         On-link      172.29.240.1    271
    ===========================================================================
    Persistent Routes:
      None
    
    IPv6 Route Table
    ===========================================================================
    Active Routes:
     If Metric Network Destination      Gateway
     17    281 ::/0                     fe80::3ad5:47ff:fedb:4350
     20      0 ::/0                     On-link
      1    331 ::1/128                  On-link
     17    281 2408:aaaa:bbbbbbbb::/64 On-link
     17    281 2408:aaaa:xxxxxxxx:5740/128
                                        On-link
     17    281 2408:aaaa:xxxxxxxx:6abe/128
                                        On-link
     20    256 fdfe::/64                On-link
     20    256 fdfe::1/128              On-link
     17    281 fe80::/64                On-link
     48    271 fe80::/64                On-link
     17    281 fe80::5fd6:22e3:e54f:fec4/128
                                        On-link
     48    271 fe80::8e08:8465:7ec8:f30c/128
                                        On-link
      1    331 ff00::/8                 On-link
     17    281 ff00::/8                 On-link
     48    271 ff00::/8                 On-link
    ===========================================================================
    Persistent Routes:
      None
    
  3. simplerick-simplefun commented on Oct 3, 2026

    @simplerick-simplefun
    Author

    #6281 (comment)

    开个抓包跟踪一下或者不用两个auto自己配缩小范围

    不是你自己无视?

    又研究了一下,破案了。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.

  4. RPRX commented on Oct 5, 2026

    @RPRX
    Member

    这个属于回环问题,我觉得 autoOutboundsInterface 在 Windows 上自动执行一下上面的命令吧,毕竟这选项就是确保不回环 @patterniha

  5. RPRX commented on Oct 5, 2026

    @RPRX
    Member

    又一个因 Windows 系统自作聪明所导致的问题

  6. patterniha commented on Oct 5, 2026

    @patterniha
    Collaborator

    I checked this issue when it was first reported, but I couldn’t reproduce it.

    默认的属性是,ipv4 两个属性都是 Disabled,而 ipv6 默认是 WeakHostSend: Enabled, WeakHostReceive: Disabled

    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.

  7. RPRX commented on Oct 5, 2026

    @RPRX
    Member

    原来不是 Windows 的锅吗,不过这个要么 core 自动改要么报错退出吧,不然跑起来后回环 100% CPU 也废了啊

  8. RPRX commented on Oct 5, 2026

    @RPRX
    Member

    或者可能很快耗尽临时端口,歇几秒后 handshake 超时释放一大批,这样不断循环

  9. patterniha commented on Oct 5, 2026

    @patterniha
    Collaborator

    原来不是 Windows 的锅吗,不过这个要么 core 自动改要么报错退出吧,不然跑起来后回环 100% CPU 也废了啊

    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.

  10. patterniha commented on Oct 5, 2026

    @patterniha
    Collaborator

    Yes I changed that as well, so now it just prints a message.

  11. patterniha commented on Oct 5, 2026

    @patterniha
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions