V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
beginor
V2EX  ›  问与答

求一份在 macOS 上能用的 sing-box 1.12 的 tun 配置

  •  
  •   beginor · 2 天前 · 796 次点击

    最近在看 sing-box 的配置看看如何分流,有点儿上头。 混合 (mined) 模式+设置系统代理很容易就配置好了, 但是 tun 模式在 mac 上总是出错。

    sing-box 的 GitHub 上的 issue 中也有类似的问题, 照着配置了也是出错。

    也问 chatgpt ,根据提示一步一步写下来,还是出错。

    希望在 macOS 上用 sing-box 的 tun 模式的 V 友能分享一个配置, 只需要 tun 段即可。

    13 条回复    2025-09-26 09:10:11 +08:00
    wheat0r
        1
    wheat0r  
       2 天前
    注意这几点:
    1. 在 tun 里启用 sniff ,虽然官方变更看起来 sniff 只要在 route 启用就行,但是我这里个别场景会遇到问题。
    2. route 里配置 dns hijack 或启用 dns 监听,二选一。dns hijack 需要你在终端上配置一个子网以外的 dns 地址,dns 监听需要你在终端上配置 sing-box 主机地址作为 dns 。
    3. auto_route 肯定是要启用的,所以 route.auto_detect_interface 也记得要配置。
    4. sing-box 的配置变更比女人翻脸还快,快跑。
    beginor
        2
    beginor  
    OP
       2 天前   ❤️ 1
    @wheat0r 感谢回复。 你说的那几个都试过了, 在 macOS 下还是出错, 系统版本是 15.7, sing-box 1.12.8 。

    也尝试过最简单的配置:

    ```json
    {
    "type": "tun",
    "address": ["192.168.0.1/30"],
    "auto_route": true,
    "strict_route": true,
    "stack": "system",
    "sniff": true
    }
    ```

    也尝试过 [强迫症专属 sing-box 配置模板(更新至 1.12 版本)]( https://blog.rewired.moe/post/sing-box-config/) , 还是不行, 错误信息如下:

    ```
    +0800 2025-09-24 19:22:46 ERROR [2536688451 1ms] connection: open connection to 43.137.191.78:80 using outbound/direct[direct]: dial tcp 43.137.191.78:80: connect: network is unreachable
    +0800 2025-09-24 19:22:47 ERROR [438338950 0ms] connection: open connection to 199.16.158.8:443 using outbound/hysteria[proxy]: dial udp 62.210.127.217:35511: connect: network is unreachable
    ```
    wheat0r
        4
    wheat0r  
       2 天前
    @beginor 启动之后 tun 网卡出来了吗?有地址吗?
    iwfd965
        5
    iwfd965  
       2 天前
    "inbounds": [
    {
    "type": "mixed",
    "listen": "127.0.0.1",
    "listen_port": 1080
    },
    {
    "type": "tun",
    "tag": "tun-in",
    "address": ["172.19.0.1/30"],
    "route_exclude_address": [
    "127.0.0.0/8",
    "192.168.0.0/16",
    "10.0.0.0/8",
    "172.16.0.0/12",
    "100.64.0.0/10",
    "169.254.0.0/16",
    "224.0.0.0/4",
    "255.255.255.255/32",
    "fc00::/7",
    "fe80::/10",
    "ff00::/8"
    ],
    "auto_route": true,
    "strict_route": true,
    "stack": "mixed",
    "platform": {
    "http_proxy": {
    "enabled": true,
    "server": "127.0.0.1",
    "server_port": 1080,
    "bypass_domain": [
    "127.0.0.0/8",
    "192.168.0.0/16",
    "10.0.0.0/8",
    "172.16.0.0/12",
    "100.64.0.0/10",
    "169.254.0.0/16",
    "224.0.0.0/4",
    "255.255.255.255/32",
    "fc00::/7",
    "fe80::/10",
    "ff00::/8"
    ]
    }
    }
    }
    ],
    beginor
        6
    beginor  
    OP
       2 天前
    @wheat0r 没看到 tun 网卡, 应该还是哪里是配置不正确
    beginor
        7
    beginor  
    OP
       2 天前
    @iwfd965 感谢回复,贴进去了, 还是一样的错误
    beginor
        8
    beginor  
    OP
       2 天前
    @silencefly 感谢回复,明天照着这个再试一下
    wheat0r
        9
    wheat0r  
       2 天前
    @beginor #6 权限不够吧
    iwfd965
        10
    iwfd965  
       2 天前 via iPhone
    @beginor 可以检查一下其他模块配置,我目前自用正常
    SenLief
        11
    SenLief  
       2 天前
    不建议用 sing-box ,它的配置文件一直还在变动,为何不用稳定的 mihomo 呢?
    beginor
        12
    beginor  
    OP
       1 天前
    @wheat0r sudo 运行的, 应该不是权限问题。

    @iwfd965 好的, 谢谢, 我再查一下。

    @SenLief 已经在用了,就别劝退了
    beginor
        13
    beginor  
    OP
       18 小时 7 分钟前
    统一回复,感谢各位 V 友的热心回复, 最终在这里抄了一份配置出来

    https://github.com/OneOhCloud/OneBox/blob/main/src/config/version_1_12/tun-config.ts

    PS: 以 tun 模式启动之后, 在 macOS 上是看不到 vpn 或者或者网卡, 但是全部应用(包括不支持代理的命令行)都可以走代理!
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   941 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 19:17 · PVG 03:17 · LAX 12:17 · JFK 15:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.