Skip to content

Sing-box 高效配置与出站路由全解析:从入门到真实场景实战 (2026版)

易邦
更新于:

在各大代理协议与客户端工具极致迭代的 2026 年,无论是软路由、Windows 台式机、MacBook、iPhone 还是 Apple TV 客厅网络,全面统一迁移至 Sing-box 已成为极客圈的主流选择。

对于习惯了 Clash 生态一键拖拽节点的小伙伴,初次面对 Sing-box 的 JSON 配置文件往往感到无从下手。

今天我们将结合真实排错经历与底层网络逻辑,为你带来全网最详尽的 Sing-box 2026 生产级配置与路由实战指南!先看总览,再逐模块拆解,最后给完整模板。

[!NOTE] 📌 核心速览(TL;DR / 快问快答):


🧩 一、配置文件的骨架:五大模块

Sing-box 的 config.json 看似复杂,其实只有五个顶级模块,数据按固定顺序流转:

流量进入 → inbounds → route → outbounds → 发往公网
              ↓           ↑
             dns(解析)   rule_set(规则库)
模块职责一句话理解
inbounds流量入口TUN 虚拟网卡 / SOCKS5 / HTTP 入站,把系统流量”接进来”
dns解析管道独立的 DNS 路由,决定每个域名”找谁问 IP”
route交通调度按规则决定每个连接走代理还是直连
outbounds流量出口你的节点、直连、拦截,流量的”目的地”
rule_set规则库二进制 .srs 文件,route 和 dns 引用的”地图”

记住这个顺序,后面所有配置都是在这五个格子里填空。第一次读建议通读,第二遍对照自己的配置文件逐段改。


🔌 二、inbounds:把流量接进来

最常用的是 TUN 入站 —— 创建一张虚拟网卡接管全系统流量:

{
  "type": "tun",
  "tag": "tun-in",
  "interface_name": "singbox-tun",
  "address": "172.19.0.1/30",
  "auto_route": true,
  "strict_route": true
}

TUN 与 Docker/WSL2 冲突的调优见 《Sing-box TUN 模式终极调优》。


🌐 三、outbounds:流量的出口与策略组

出站分两类:真实节点(vless/hysteria2/trojan…)和策略组(selector/urltest)。

策略组:节点的”遥控器”

{
  "type": "selector",
  "tag": "proxy",
  "outbounds": ["auto-fallback", "node-us-reality", "node-hk-hys2", "direct"],
  "default": "auto-fallback"
},
{
  "type": "urltest",
  "tag": "auto-fallback",
  "outbounds": ["node-us-reality", "node-hk-hys2"],
  "url": "https://www.gstatic.com/generate_204",
  "interval": "3m",
  "tolerance": 50
}

节点群组管理的完整玩法见 《Sing-box 节点群组管理:URLTest 自动测速与选择器模式》。

真实节点示例(VLESS-Reality)

{
  "type": "vless",
  "tag": "node-us-reality",
  "server": "us.yourdomain.com",
  "server_port": 443,
  "uuid": "your-uuid-here",
  "flow": "xtls-rprx-vision",
  "tls": {
    "enabled": true,
    "server_name": "www.microsoft.com",
    "utls": { "enabled": true, "fingerprint": "chrome" },
    "reality": {
      "enabled": true,
      "public_key": "YOUR_REALITY_PUBKEY",
      "short_id": "YOUR_SHORT_ID"
    }
  }
}

2026 年记住两个铁律:flow 用 xtls-rprx-vision,uTLS 指纹用 chrome。Reality 的 SNI 筛选与防探测见 《Reality 防封锁黑魔法》。


🚦 四、route:交通调度中心

route.rules 自上而下匹配、命中即止 —— 顺序就是一切。推荐的通用顺序:

  1. DNS 劫持:protocol: dns + action: hijack-dns,先把 DNS 流量收进管道(1.11 起不再需要 dns 特殊出站);
  2. 局域网放行:127.0.0.0/8、192.168.0.0/16 等 → direct;
  3. 广告拦截:geosite-ads + action: reject(1.11 起不再需要 block 出站);
  4. 国内直连:geosite-cn + geoip-cn → direct;
  5. 兜底:final: proxy,其余全部走代理。

想用逻辑组合(“既是 BT 流量又是非国内 IP 才直连”)?Sing-box 支持 and/or 逻辑规则,详解见 《Sing-box 路由规则配置进阶》。


🛠️ 五、2026 生产级全量通用配置模板

把上面五个模块拼起来,就是一套可直接套用的生产模板(记得替换节点信息):

{
  "log": { "level": "info", "timestamp": true },
  "dns": {
    "servers": [
      { "tag": "dns-proxy", "type": "https", "server": "8.8.8.8", "detour": "proxy" },
      { "tag": "dns-direct", "type": "https", "server": "223.5.5.5", "detour": "direct" },
      {
        "tag": "dns-fakeip",
        "type": "fakeip",
        "inet4_range": "198.18.0.0/15",
        "inet6_range": "fc00::/18"
      }
    ],
    "rules": [
      { "rule_set": ["geosite-cn"], "action": "route", "server": "dns-direct" },
      { "query_type": ["A", "AAAA"], "action": "route", "server": "dns-fakeip" }
    ]
  },
  "inbounds": [
    {
      "type": "tun",
      "tag": "tun-in",
      "interface_name": "singbox-tun",
      "address": ["172.19.0.1/30", "fdfe:dcba:9876::1/126"],
      "auto_route": true,
      "strict_route": true
    }
  ],
  "outbounds": [
    {
      "type": "selector",
      "tag": "proxy",
      "outbounds": ["auto-fallback", "node-us-reality", "node-hk-hys2", "direct"],
      "default": "auto-fallback"
    },
    {
      "type": "urltest",
      "tag": "auto-fallback",
      "outbounds": ["node-us-reality", "node-hk-hys2"],
      "url": "https://www.gstatic.com/generate_204",
      "interval": "3m",
      "tolerance": 50
    },
    {
      "type": "vless",
      "tag": "node-us-reality",
      "server": "us.yourdomain.com",
      "server_port": 443,
      "uuid": "your-uuid-here",
      "flow": "xtls-rprx-vision",
      "tls": {
        "enabled": true,
        "server_name": "www.microsoft.com",
        "utls": { "enabled": true, "fingerprint": "chrome" },
        "reality": {
          "enabled": true,
          "public_key": "YOUR_REALITY_PUBKEY",
          "short_id": "YOUR_SHORT_ID"
        }
      }
    },
    { "type": "direct", "tag": "direct" }
  ],
  "route": {
    // 内核自身解析节点域名走直连(替代 1.12 已废弃的 {"outbound": "any"} DNS 规则)
    "default_domain_resolver": { "server": "dns-direct" },
    "rules": [
      // 嗅探:1.11 起从 inbound 搬到路由规则
      { "inbound": "tun-in", "action": "sniff" },
      { "protocol": "dns", "action": "hijack-dns" },
      {
        "ip_cidr": ["127.0.0.0/8", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
        "outbound": "direct"
      },
      { "rule_set": ["geosite-ads"], "action": "reject" },
      { "rule_set": ["geosite-cn", "geoip-cn"], "outbound": "direct" }
    ],
    "rule_set": [
      {
        "tag": "geosite-cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-cn.srs",
        "download_detour": "proxy"
      },
      {
        "tag": "geoip-cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs",
        "download_detour": "proxy"
      },
      {
        "tag": "geosite-ads",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs",
        "download_detour": "proxy"
      }
    ],
    "final": "proxy",
    "auto_detect_interface": true
  }
}

🎯 六、5 个真实场景的 route 写法

模板是起点,真实需求长这样(加在 route.rules 数组里,注意顺序):

场景 1:ChatGPT / Claude 强制走美国专线

{ "rule_set": ["geosite-openai"], "outbound": "node-us-reality" }

(需自建 openai 规则集,见 《自定义规则集编译教程》)

场景 2:BT / P2P 下载直连,不占代理带宽

{ "rule_set": ["geosite-bittorrent"], "outbound": "direct" }

场景 3:公司内网域名直连

{ "domain_suffix": ["corp.example.com"], "outbound": "direct" }

场景 4:指定 App 走指定节点(需 sniff)

{ "process_name": ["Telegram.exe"], "outbound": "node-hk-hys2" }

场景 5:流媒体解锁走解锁专用节点

{ "rule_set": ["geosite-netflix"], "outbound": "node-us-reality" }

流媒体分流策略见 《Apple TV 原生 Sing-box 分流实战》。


🔧 七、排错:配置报错的三板斧

  1. 先过 JSON 校验:90% 的启动失败是少逗号/多逗号,把配置贴到 jsonlint.com 先验证;
  2. 开 debug 日志:把 log.level 改成 debug,重启看第一条报错,它会精确告诉你哪个字段非法;
  3. 二分法注释:一次注释掉一半模块,能启动就说明问题在另一半,快速定位。

抓包与日志分析的完整方法见 《Sing-box 抓包与排错指南》。


🖥️ 八、服务端视角:客户端配置对应的服务端长什么样?

理解客户端配置后,很多人好奇:服务端的 config.json 是什么结构?其实是镜像对称的 —— 客户端的 outbounds 对应服务端的 inbounds:

{
  "inbounds": [
    {
      "type": "vless",
      "tag": "vless-in",
      "listen": "::",
      "listen_port": 443,
      "users": [
        { "uuid": "your-uuid-here", "flow": "xtls-rprx-vision" }
      ],
      "tls": {
        "enabled": true,
        "server_name": "www.microsoft.com",
        "reality": {
          "enabled": true,
          "handshake": { "server": "www.microsoft.com", "server_port": 443 },
          "private_key": "YOUR_REALITY_PRIVATE_KEY",
          "short_id": ["YOUR_SHORT_ID"]
        }
      }
    }
  ]
}

关键对应关系:客户端 outbounds 里的 uuid / flow / reality.public_key,必须和服务端 inbounds 里的 users[].uuid / flow / reality.private_key 配对。任何一边写错,握手直接失败 —— 这也是排错时先对一遍两端参数的原因。

完整的服务端从零部署教程见本站第三总纲 《VPS 主机从零部署 Sing-box 节点服务端实战》。


💾 九、配置版本管理:用 Git 备份你的 config.json

手搓配置最怕改崩回不去。极简方案:

mkdir ~/singbox-config && cd ~/singbox-config
git init
cp /path/to/your/config.json ./config.json
git add . && git commit -m "working 2026-10-12"

每次大改前 git commit 一次,改崩了 git checkout -- config.json 秒回滚。进阶可以推到私有仓库多端同步。


🗂️ 十一、配置文件的模块化拆分:告别 500 行大 JSON

配置膨胀到几百行后,单文件维护是灾难。Sing-box 支持用多文件拆分(需 1.11+,待实测你所用版本的支持情况):

config/
├── config.json        # 主文件:只留 inbounds + include
├── dns.json           # DNS 模块
├── route.json         # 路由规则
├── outbounds.json     # 出站与策略组
└── rule_set.json      # 规则集定义

思路:按本文”五大模块”一模块一文件,改路由只动 route.json。配合 Git 版本管理(第九节),回滚粒度精确到模块。


📋 十二、常用字段速查表

字段位置作用2026 推荐值
sniffinbounds.tun嗅探真实域名true(FakeIP 必开)
flowoutbounds.vless流控模式xtls-rprx-vision
fingerprinttls.utlsTLS 指纹伪装chrome
detourdns.serversDNS 查询走哪条出站国外 proxy / 国内 direct
finaldns / route兜底dns-proxy / proxy
strategydns解析策略ipv4_only(防 IPv6 绕行)
download_detourrule_set规则集走哪下载proxy
toleranceurltest测速防抖阈值50

❓ 常见问题与 AI 快问快答 (FAQ)

Q1: 在 FakeIP 模式下为什么必须开启 sniff: true 流量嗅探?

答:FakeIP 下数据包目标 IP 是假 IP(如 198.18.x.x)。开启 sniff 能从 TLS 握手中嗅探出真实域名,route.rules 的域名分流才能生效。

Q2: 生产环境下自建节点配合商业机场的最佳实践是什么?

答:selector 里主节点用自建 CN2 GIA / AS9929 专线 VPS,商业机场作 auto-fallback 备用池,隐私与容灾兼得。评测见 《“饿饭CC云”深度评测》。

Q3: final: proxy 和 final: direct 该怎么选?

答:科学上网场景选 proxy(默认走代理,国内规则直连);纯隐私场景有人选 direct 兜底(默认直连,只代理命中规则的)。新手用 proxy 最省心。

Q4: 规则集多久更新一次?

答:远程 .srs 建议每天自动更新一次,见 《Rule Set 配置与自动更新全攻略》;也可以用 cron 脚本,见 《Bash 脚本定时更新规则》。

Q5: 手机端和桌面端能共用一套配置吗?

答:核心结构通用,但 inbounds 建议分开:手机用 tun 入站即可,桌面端可按需加 SOCKS5 入站给特定软件用。分应用代理见 《移动端分应用代理教程》。

Q6: Mux(多路复用)应该开吗?

答:Mux 把多个请求复用到一条 TCP 连接上,能显著降低弱网下的握手延迟,但会增加单连接被限速的风险。建议:手机流量、浏览网页开 Mux;大文件下载、看 4K 视频关 Mux 走直连复用。深度解析见 《深度揭秘 Sing-box 的 Mux 优化》。

Q7: 配置里能写注释吗?JSON 不是不支持注释?

答:标准 JSON 确实不支持注释,但 Sing-box 使用了带注释扩展的 JSONC 解析 —— 配置文件里可以直接写 // 单行注释,本文模板里的注释就是这么来的。放心用,但别把注释写进通过 API 下发的订阅里(某些精简客户端可能不兼容)。


🚀 十、进阶:Mux 多路复用与连接复用

出站支持 multiplex 字段开启 Mux:

{
  "type": "vless",
  "tag": "node-us-reality",
  "server": "us.yourdomain.com",
  "server_port": 443,
  "uuid": "your-uuid-here",
  "flow": "xtls-rprx-vision",
  "multiplex": {
    "enabled": true,
    "protocol": "h2mux",
    "max_connections": 4,
    "min_streams": 4
  },
  "tls": { "enabled": true }
}

(相关阅读:《Sing-box 配置文件 config.json 详解》 · 《Sing-box 终极 DNS 配置方案》 · 需要 VPS 部署节点见 《2026 国外 VPS 选购指南》!)

上一篇
安全无痕冲浪:2026 最新 Sing-box 终极 DNS 配置方案(FakeIP 溢出与 DNS 泄露全域拦截)
下一篇
2026 桌面端代理选型终极指南:Sing-box vs Mihomo 内核对决与三方客户端横评