在通用代理客户端生态中,Sing-box 凭借其极其纯净的底层实现、极低内存占用以及对新型协议(如 Reality、Hysteria2、TUIC)的敏捷原生支持,正在成为广大网络优化爱好者和开发者的主力内核。

然而,Sing-box 的迭代步子跨得极大。从 1.8.0 版本开始,直到最新的 1.12+ 版本,其核心配置文件格式(JSON)经历了几次重大的破坏性变更(Breaking Changes)

如果你直接套用两年前的旧配置,最新版的 Sing-box 客户端会直接报错闪退。

核心的改变主要集中在三处:

  1. 废弃 geoipgeosite 文本规则,强制或强烈建议迁移至二进制的 rule_set (SRS 格式) 以提升启动与匹配效率。
  2. DNS 路由机制重构:从旧版简单的 client_subnet 路由演进为独立的 dns.rules 高级规则分流。
  3. 入站与出站传输层参数聚合

本文将带您理清 Sing-box 的版本演进路线,手把手指导您完成旧版配置向 1.12+ 高性能新架构的无痛迁移。


一、Sing-box 版本演进路线图与核心变更

在动刀修改配置文件之前,我们先理清这几次大版本升级究竟动了什么:

PLAINTEXT
                ┌── 1.8.0 版本 ───> 首次引入 rule_set 二进制 (.srs) 格式,废弃直接读取 geoip.db/geosite.db
                │
Sing-box 演进 ──┼── 1.10.0 版本 ──> 重构 DNS 规则系统,废弃旧版 dns.servers 中的规则匹配
                │
                └── 1.12.0+ 版本 ─> 优化传输层配置参数(如 TLS/Multiplex 独立聚合),细化路由动作行为

1.1 1.8.0 版:规则集 SRS 革命

在 1.8.0 之前,Sing-box 像 Clash 一样,需要在本地放置几十兆的 geoip.dbgeosite.db。每次匹配域名时,内核要在内存中进行大量的字符串检索,消耗资源且速度慢。

1.2 1.10.0 版:DNS 匹配剥离

1.3 1.12.0+ 版:参数更名与结构优化


二、核心迁移实战一:从 geoip/geosite 迁移至 rule_set (SRS)

这是旧配置升级中最容易导致报错的一步。

2.1 旧版配置写法(已废弃)

JSON
{
  "route": {
    "rules": [
      {
        "geosite": ["google", "youtube"],
        "outbound": "proxy"
      },
      {
        "geoip": ["cn"],
        "outbound": "direct"
      }
    ]
  }
}

2.2 新版 1.12+ 配置写法(推荐)

新版需要先在全局 route.rule_sets 中定义规则集的数据源,然后在路由规则中通过 rule_set 的标签进行引用:

JSON
{
  "route": {
    "rules": [
      {
        "rule_set": ["geosite-google", "geosite-youtube"],
        "outbound": "proxy"
      },
      {
        "rule_set": ["geoip-cn"],
        "outbound": "direct"
      }
    ],
    "rule_sets": [
      {
        "tag": "geosite-google",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/google.srs",
        "download_detour": "direct"
      },
      {
        "tag": "geosite-youtube",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/youtube.srs",
        "download_detour": "direct"
      },
      {
        "tag": "geoip-cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geoip/cn.srs",
        "download_detour": "direct"
      }
    ]
  }
}

三、核心迁移实战二:重构 DNS 规则体系

在 1.10.0+ 之后,DNS 部分的设计必须采用“独立规则法”。

3.1 旧版 DNS 配置(已失效)

JSON
{
  "dns": {
    "servers": [
      {
        "tag": "google-dns",
        "address": "https://8.8.8.8/dns-query",
        "detour": "proxy"
      },
      {
        "tag": "local-dns",
        "address": "223.5.5.5",
        "detour": "direct"
      }
    ],
    // 旧版直接在 servers 里指定规则(现在这样写会导致报错)
    "rules": [
      {
        "geosite": "cn",
        "server": "local-dns"
      }
    ]
  }
}

3.2 1.12+ 新版 DNS 规则配置

新版必须将匹配逻辑写入 dns.rules,通过配置不同的 dns.servers 实现纯粹的 DNS 解析:

JSON
{
  "dns": {
    "servers": [
      {
        "tag": "dns-direct",
        "address": "223.5.5.5",
        "detour": "direct"
      },
      {
        "tag": "dns-proxy",
        "address": "https://8.8.8.8/dns-query",
        "detour": "proxy"
      }
    ],
    "rules": [
      {
        "outbound": "direct",
        "server": "dns-direct"
      },
      {
        "rule_set": ["geosite-google", "geosite-youtube"],
        "server": "dns-proxy"
      },
      {
        "rule_set": ["geoip-cn"],
        "server": "dns-direct"
      }
    ],
    "final": "dns-direct"
  }
}

四、核心迁移实战三:传输层参数更新 (以 TLS/Multiplex 为例)

随着版本的推进,一些出站和入站中关于连接优化的参数也进行了结构性微调。

4.1 Multiplex (多路复用) 参数变更

为了防止连接频繁握手降低效率,我们可以开启 multiplex

JSON
{
  "outbounds": [
    {
      "type": "shadowsocks",
      "tag": "proxy",
      "server": "1.2.3.4",
      "server_port": 10086,
      // 聚合的多路复用配置
      "multiplex": {
        "enabled": true,
        "protocol": "smux",
        "max_connections": 4,
        "min_streams": 4,
        "padding": true
      }
    }
  ]
}

4.2 TLS 伪装参数微调

tls 选项中,server_name(即 SNI 伪装域名)不能再简写为全局字符串,必须规范写入 tls 对象中:

JSON
"tls": {
  "enabled": true,
  "server_name": "gateway.microsoft.com",
  "utls": {
    "enabled": true,
    "fingerprint": "chrome"
  }
}

五、1.12+ 开箱即用完整新版 JSON 配置模板

这里为您提供一份完整的、兼容 1.12+ 客户端的单机分流配置模板。可以直接复制并修改服务器 IP 后导入 iOS(Loon/Surge 支持转化导入)、Android 或桌面端 Sing-box 中使用:

JSON
{
  "log": {
    "level": "info",
    "timestamp": true
  },
  "dns": {
    "servers": [
      {
        "tag": "dns-direct",
        "address": "223.5.5.5",
        "detour": "direct"
      },
      {
        "tag": "dns-proxy",
        "address": "https://1.1.1.1/dns-query",
        "detour": "proxy"
      }
    ],
    "rules": [
      {
        "outbound": "direct",
        "server": "dns-direct"
      },
      {
        "rule_set": ["geoip-cn", "geosite-cn"],
        "server": "dns-direct"
      }
    ],
    "final": "dns-proxy"
  },
  "inbounds": [
    {
      "type": "tun",
      "tag": "tun-in",
      "interface_name": "singbox-tun",
      "address": ["172.19.0.1/30"],
      "auto_route": true,
      "strict_route": true,
      "stack": "system",
      "sniff": true
    }
  ],
  "outbounds": [
    {
      "type": "vless",
      "tag": "proxy",
      "server": "your-server-ip",
      "server_port": 443,
      "uuid": "your-uuid-here",
      "flow": "xtls-rprx-vision",
      "network": "tcp",
      "tls": {
        "enabled": true,
        "server_name": "images.apple.com",
        "utls": {
          "enabled": true,
          "fingerprint": "chrome"
        },
        "reality": {
          "enabled": true,
          "public_key": "your-public-key-here",
          "short_id": "your-short-id-here"
        }
      }
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "dns",
      "tag": "dns-out"
    }
  ],
  "route": {
    "rules": [
      {
        "protocol": "dns",
        "outbound": "dns-out"
      },
      {
        "rule_set": ["geosite-google", "geosite-youtube"],
        "outbound": "proxy"
      },
      {
        "rule_set": ["geoip-cn", "geosite-cn"],
        "outbound": "direct"
      }
    ],
    "rule_sets": [
      {
        "tag": "geosite-google",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/google.srs",
        "download_detour": "direct"
      },
      {
        "tag": "geosite-youtube",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/youtube.srs",
        "download_detour": "direct"
      },
      {
        "tag": "geosite-cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/cn.srs",
        "download_detour": "direct"
      },
      {
        "tag": "geoip-cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geoip/cn.srs",
        "download_detour": "direct"
      }
    ]
  }
}

六、常见配置迁移错误与调试排查方法

在升级到新版配置后,如果客户端报错,可按以下三个维度排查:

  1. 报错提示 invalid rule_set type
    • 原因:这通常是因为你在本地指定了文件路径("type": "local"),但你在配置中将 format 设为了 source(文本格式),但加载的文件却是 .srs(二进制格式),或者反之。
    • 检查方法:远程 SRS 文件的 format 必须明确声明为 "format": "binary"
  2. 启动时卡在下载 downloading rule_set 导致超时闪退
    • 原因:因为首次启动时,本地没有任何规则集,Sing-box 会尝试联网下载。此时如果你没有配置正确的直连或默认代理,导致下载请求被拦截或死锁。
    • 解决:为所有 rule_sets 里的元素增加 "download_detour": "direct",确保初始规则文件能够通过直连网络顺利下回本地。
  3. 报错 unexpected end of JSON input
    • 原因:括号未成对闭合或多出了逗号。新旧配置迁移时,因为删减了字段,最容易在花括号 {} 或是逗号 , 上出错。建议使用 jsonlint.com 等工具在线校验 JSON 的合法性。

七、性能对比:旧版文本 vs 1.12+ SRS 二进制

迁移完之后,你可以直观地体察到以下性能提升:

完成 1.12+ 新版配置重构后,你的 Sing-box 客户端将以更轻快、更稳定的姿态保障你的日常高效出海。

版权声明

作者: 易邦

链接: https://blog.e8k.net/posts/sing-box-1.12-migration-guide/

许可证: 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。