sing-box icon indicating copy to clipboard operation
sing-box copied to clipboard

tproxy ipv6 未能预期工作

Open Verycuteabbey opened this issue 1 year ago • 7 comments

环境为 Arch Linux x86_64, 使用 nftables inet 表进行 tproxy

sing-box 版本:

sing-box version 1.12.8

Environment: go1.25.1 X:nodwarf5 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale
CGO: enabled

sing-box inbounds 配置:

"inbounds": [
  {
    "type": "mixed",
    "tag": "mixed-in",
    "listen": "::",
    "listen_port": 7890,
    "tcp_fast_open": true,
    "tcp_multi_path": true
  },
  {
    "type": "tproxy",
    "tag": "tproxy-in",
    "listen": "::",
    "listen_port": 7891
  }
]

nftables 规则:

#!/usr/bin/nft -f

flush ruleset

define BYPASS_DEST_IPV4 = { 100.92.0.0/10 }
define BYPASS_DEST_IPV6 = { fd7a:115c:a1e0::/48 }
define BYPASS_SOURCE_IPV4 = { 192.168.100.0/24 }

define LOCAL_IPV4 = { 0.0.0.0/8, 10.0.0.0/8, 127.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 }
define LOCAL_IPV6 = { ::/128, ::1/128, fe80::/10 }

table inet sing-box {
    chain prerouting {
        type filter hook prerouting priority mangle; policy accept;

        meta l4proto { tcp, udp } socket transparent 1 mark set 1
        socket transparent 0 socket wildcard 0 return

        ip daddr $LOCAL_IPV4 return
        ip6 daddr $LOCAL_IPV6 return

        ip6 daddr != 2000::/3 return

        meta l4proto { tcp, udp } tproxy to :7891 meta mark set 1
    }
}

table inet proxy {
    chain output {
        type route hook output priority mangle; policy accept;

        meta skuid sing-box return

        ip daddr $LOCAL_IPV4 return
        ip6 daddr $LOCAL_IPV6 return

        ip daddr $BYPASS_DEST_IPV4 return
        ip6 daddr $BYPASS_DEST_IPV6 return
        ip saddr $BYPASS_SOURCE_IPV4 return

        ip6 daddr != 2000::/3 return

        meta l4proto { tcp, udp } meta mark set 1
    }
}

当我使用 log 后在 journalctl -kf 查看过日志,v4 v6 均成功导向 sing-box 的 7891 端口 但就是无法被 sing-box 接收到,日志中 inbound connection 均只有 v4 连接

sysctl 已经将 v4 v6 的转发开启,ip route 与 ip rule 均已设置 v4 v6 的

麻烦大佬帮忙看看到底哪里出了问题,已经被困扰 1 个月了,android 的 box for root 都能成功😭😭😭

Verycuteabbey avatar Sep 18 '25 10:09 Verycuteabbey

请给出去除节点的完整配置和相关日志。

以及测试的复现过程。

daminit avatar Sep 19 '25 06:09 daminit

请给出去除节点的完整配置和相关日志。

以及测试的复现过程。

这个是去除 outbounds 后的完整配置 config.json

当给 tproxy 和 fwmark 打上 log prefix 后,它是这样的:

ipv4

Image

ipv6

Image

以上只有 ipv4 被 sing-box 接收到


复现过程直接套用上述 nft 规则并设置

Image

Verycuteabbey avatar Sep 19 '25 12:09 Verycuteabbey

我注意到你的 ipv6的source IP是 fd22... 不是一个公共IPv6 , 怀疑你的路由表没有对IPv6的默认路由。导致你对这个 IPv6的 tcping 没有回复。

另外,推荐使用 curl -4 和 curl -6来测试而不是使用tcping , curl来的测试更有价值。

希望提供更多信息,我在本地无法复现。 最近有一句关于 Tproxy的 相关 Issue 也已经修了,而且那个是 UDP 。[#3045 ]

daminit avatar Sep 19 '25 13:09 daminit

也许你还可以测测其他的项目的 tproxy是否可用,例如: https://gost.run/tutorials/redirect/

daminit avatar Sep 19 '25 13:09 daminit

我注意到你的 ipv6的source IP是 fd22... 不是一个公共IPv6 , 怀疑你的路由表没有对IPv6的默认路由。导致你对这个 IPv6的 tcping 没有回复。

另外,推荐使用 curl -4 和 curl -6来测试而不是使用tcping , curl来的测试更有价值。

希望提供更多信息,我在本地无法复现。 最近有一句关于 Tproxy的 相关 Issue 也已经修了,而且那个是 UDP 。[#3045 ]

感谢你的推荐及解答,我的 ipv6 是 ra 下放的 slaac 无状态地址,不过 ip -6 route show 查看是有 default via 路由 v6 网关的

如果取消 v6 fwmark 将恢复正常(但不 tproxy),一旦打标记就会这样

对此你有什么想法吗?

另外,curl -6 会直接超时连接(对应 tcping no reply)

Verycuteabbey avatar Sep 19 '25 13:09 Verycuteabbey

换用 auto_redirect。

nekohasekai avatar Sep 19 '25 13:09 nekohasekai

已解决,被 firewalld 的 ipv6_rpfilter 拦截 关掉即可恢复😭😭😭

Verycuteabbey avatar Sep 29 '25 15:09 Verycuteabbey