sing-box tun 模式死活有问题,求助 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cchaan
V2EX    宽带症候群

sing-box tun 模式死活有问题,求助

  •  1
     
  •   cchaan 2 天前 1443 次点击

    各们好,最近在折腾 sing-box 的全局代理,发现同样的配置在新装的虚拟机 win10 和另一台闲置的 win10 上都无问题。但是放到自己的两台电脑上就死活不通了;最后把配置简化到 tun 透传 direct ,也是同样的状况。折腾几天了,实在想不到什么问题了,有懂的人麻烦指点一二。 测试命令是 curl -v https://www.baidu.com , 症状是

    * Host www.baidu.com:443 was resolved. * IPv6: (noe) * IPv4: 180.101.49.44, 180.101.51.73 * Trying 180.101.49.44:443... * connect to 180.101.49.44 port 443 from 0.0.0.0 port 52489 failed: Timed out * Trying 180.101.51.73:443... * connect to 180.101.51.73 port 443 from 0.0.0.0 port 58474 failed: Timed out * Failed to connect to www.baidu.com port 443 after 42582 ms: Could not connect to server * closing connection #0 curl: (28) Failed to connect to www.baidu.com port 443 after 42582 ms: Could not connect to server 

    以下是简化后在自己电脑上仍有问题的配置

    { "log": { "disabled": false, "level": "trace", "timestamp": true, "output": "" }, "inbounds": [{ "type": "tun", "tag": "tun-in", "interface_name": "singbox-tun", "address": ["192.0.2.0/24"], "route_address": ["0.0.0.0/1", "128.0.0.0/1", "::/1", "8000::/1"], "route_exclude_address": [ "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "fc00::/7" ], "auto_route": true, "strict_route": false }, {"tag": "dns-in","type": "direct","listen": "127.0.0.1","listen_port": 53} ], "outbounds": [ {"type": "direct","tag": "direct"}, {"type": "block","tag": "block"} ], "dns": { "strategy": "prefer_ipv4", "servers": [ {"type": "local","tag": "local-dns"}, {"type": "udp","tag": "cn-dns","server": "119.29.29.29"} ], "rules": [ {"inbound": ["tun-in"],"server": "cn-dns"} ] }, "route": { "auto_detect_interface": true, "default_domain_resolver": "local-dns", "final": "direct", "rules": [ {"action": "sniff"}, {"protocol": "dns","action": "hijack-dns"}, {"ip_is_private": true,"outbound": "direct"}, {"inbound": ["tun-in"],"outbound": "direct"} ] } } 
    第 1 条附言    1 天前

    以下是从sing-box启动后到 curl -v https://www.baidu.com 超时截取日志,日志级别 trace

    2026-01-29 13:30:32 INFO network: updated default interface 以太网, index 26 2026-01-29 13:30:32 TRACE inbound/tun[tun-in]: creating stack 2026-01-29 13:30:32 INFO inbound/tun[tun-in]: started at singbox-tun 2026-01-29 13:30:32 INFO inbound/direct[dns-in]: tcp server started at 127.0.0.1:53 2026-01-29 13:30:32 INFO inbound/direct[dns-in]: udp server started at 127.0.0.1:53 2026-01-29 13:30:32 INFO sing-box started (0.311s) 2026-01-29 13:30:35 INFO [3235526638 0ms] inbound/tun[tun-in]: inbound packet connection from 192.0.2.1:61288 2026-01-29 13:30:35 INFO [3235526638 0ms] inbound/tun[tun-in]: inbound packet connection to 192.0.2.2:53 2026-01-29 13:30:35 DEBUG [3235526638 0ms] router: match[0] => sniff 2026-01-29 13:30:35 DEBUG [3235526638 0ms] router: sniffed packet protocol: dns 2026-01-29 13:30:35 DEBUG [3235526638 0ms] router: match[1] protocol=dns => hijack-dns 2026-01-29 13:30:35 DEBUG [3235526638 0ms] dns: exchange www.baidu.com. IN A 2026-01-29 13:30:35 DEBUG [3235526638 0ms] dns: match[1] inbound=tun-in => route(cn-dns) 2026-01-29 13:30:35 DEBUG [3235526638 7ms] dns: exchanged www.baidu.com NOERROR 54 2026-01-29 13:30:35 INFO [3235526638 7ms] dns: exchanged CNAME www.baidu.com. 54 IN CNAME www.a.shifen.com. 2026-01-29 13:30:35 INFO [3235526638 7ms] dns: exchanged A www.a.shifen.com. 54 IN A 180.101.51.73 2026-01-29 13:30:35 INFO [3235526638 7ms] dns: exchanged A www.a.shifen.com. 54 IN A 180.101.49.44 
    第 2 条附言    1 天前
    破案了,inbounds.tun 设置 "stack": "gvisor",可用;但不知道为什么。
    第 3 条附言    10 小时 18 分钟前

    在Gemini和Grok两个AI帮助下,通过控制变量发现是防火墙的问题,确切说是受“公用网络”那个开关影响, 只要把开关关掉,curl立刻有返回了。大概原因是虚拟网络接口默认的Public网络类型,过滤策略极其严格。一个非常诡异的问题,背后的原因竟这么简单。

    16 条回复    2026-01-29 15:50:49 +08:00
    dxxzst
        1
    dxxzst  
       2 天前
    我之前发现,如果电脑上有两个网卡,比如一个有线网卡、一个无线网卡,这两个网卡如果同时开启,tun 会有问题。把不用的网卡停掉,就 OK 了。
    anytk
        2
    anytk  
       2 天前
    你的 tun 为啥用 `"address": ["192.0.2.0/24"],` 这个公网大网段,一般都是 172 私有地址下的小网段(/30) 。
    cchaan
        3
    cchaan  
    OP
       2 天前
    @dxxzst 试过了,把除了特理网卡外其他虚拟网卡都禁了,剩下一个 tailscale 不影响,也是一样的症状
    cchaan
        4
    cchaan  
    OP
       2 天前
    @anytk 192.0.2.0/24 是类似 CGNAT (100.64.0.0/10) 的特殊网段
    anytk
        5
    anytk  
       2 天前
    试试 `strict_route: true`
    crackself
        6
    crackself  
       2 天前 via Android
    试试这个,win Android openwrt 都没问题
    {
    "type": "tun",
    "tag": "tun",
    "interface_name": "SingBox",
    "address": [
    "172.18.0.1/30",
    "fdfe:dcba:9876::1/126"
    ],
    "mtu": 1500,
    "auto_route": true,
    "strict_route": true,
    "endpoint_independent_nat": false,
    "stack": "mixed"
    }
    crc8
        7
    crc8  
       2 天前
    这是 1.11 版本后的配置?
    Ipsum
        8
    Ipsum  
       2 天前
    sb 的日志不发来看看?
    isAK47
        9
    isAK47  
       1 天前
    "address": ["192.0.2.0/24"]---->"address": ["192.0.2.1/30"]
    cchaan
        10
    cchaan  
    OP
       1 天前
    @crackself 谢谢,试过了,没用
    cchaan
        11
    cchaan  
    OP
       1 天前
    @Ipsum 发上来了,附在上面
    angeltop
        12
    angeltop  
       1 天前
    {
    "log": { "level": "trace", "timestamp": true },
    "inbounds": [
    {
    "type": "tun",
    "tag": "tun-in",
    "interface_name": "singbox-tun",
    "address": ["172.19.0.1/30"],
    "auto_route": true,
    "strict_route": true,
    "route_address": ["0.0.0.0/1", "128.0.0.0/1"],
    "route_exclude_address": ["10.0.0.0/8","172.16.0.0/12","192.168.0.0/16"]
    }
    ],
    "outbounds": [
    { "type": "direct", "tag": "direct" },
    { "type": "block", "tag": "block" }
    ],
    "route": {
    "auto_detect_interface": false,
    "default_interface": "Wi-Fi",
    "final": "direct",
    "rules": [
    { "inbound": ["tun-in"], "outbound": "direct" }
    ]
    }
    }
    cchaan
        13
    cchaan  
    OP
       1 天前
    @crackself 破案了,"stack": "gvisor",可用;但不知道为什么。
    Hazard001
        14
    Hazard001  
       1 天前 via iPhone
    system 栈最好手动指定 mtu 为 1500
    dcty
        15
    dcty  
       1 天前
    我在路由器上跑 singbox 和 mihomo ( shellcrash ),singbox 有内存泄露问题,会导致路由器重启,mihomo 稳如老狗,当然不排除是我的配置文件有问题(规则和代理基本上一致,当然不排除规则有些许差异,懒得排查了)
    heiher
        16
    heiher  
       1 天前 via Android
    system stack 虽然可以复用内核网络栈实现,但 I/O 次数更多,效能还不如 userspace ,内核相关配置变动的干扰因素也多
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2028 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 21ms UTC 04:48 PVG 12:48 LAX 20:48 JFK 23:48
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86