作为网络代理界冉冉升起的新星,Sing-Box 凭借其极致的性能、极低的内存占用和天然的多平台跨端兼容,正逐渐取代 Clash 成为很多硬核用户的核心选择。然而,不同于 Clash 的 YAML 可视化订阅格式,Sing-Box 默认采用的原生 JSON 配置文件格式 结构严谨但门槛极高,稍有不慎就会因逗号缺失或大括号嵌套错误导致内核崩溃。

掌握手写 Sing-Box 极简 JSON 配置的关键在于厘清其五大核心模块:DNS 模块(负责分流解析防污染)、Route 规则路由模块(执行 IP 与域名分流)、Inbounds 入站监听模块(接管本地 HTTP/Socks5 流量)、Outbounds 出站组模块(定义直连、分流及落地代理节点),以及 Experimental 实验性特性。本文将为您提供一份完全兼容 2026 最新官方核心语法、包含详尽中文化注释的极简分流模板,助您完美打通全平台无感加速。


Sing-Box 核心 JSON 语法架构解析

一份规范的 Sing-Box 配置文件主要由以下几个核心键值对组成:

JSON
{
  "log": {},          // 日志级别与输出设置
  "dns": {},          // DNS 解析器分流组(极其重要,防DNS泄漏)
  "inbounds": [],     // 本地监听的接口(HTTP、Socks5、Tun 虚拟网卡等)
  "outbounds": [],    // 物理出口节点定义(Direct、Block、Selector选择器、节点组)
  "route": {}         // 路由分流引擎(匹配域名、IP、端口并将流量丢给指定的 outbound)
}

2026 官方标准极简 JSON 模板 (带详尽中文注释)

以下模板可以直接保存为 config.json 并在 Windows、macOS、Linux 或移动端 Sing-Box 客户端中导入:

JSON
{
  "log": {
    "level": "info",
    "timestamp": true
  },
  "dns": {
    "servers": [
      {
        "tag": "dns_proxy",
        "address": "https://8.8.8.8/dns-query",
        "address_resolver": "dns_direct",
        "detour": "节点选择"
      },
      {
        "tag": "dns_direct",
        "address": "223.5.5.5",
        "detour": "direct"
      },
      {
        "tag": "dns_block",
        "address": "rcode://success"
      }
    ],
    "rules": [
      {
        "outbound": "any",
        "server": "dns_direct"
      },
      {
        "clash_mode": "Direct",
        "server": "dns_direct"
      },
      {
        "clash_mode": "Global",
        "server": "dns_proxy"
      },
      {
        "rule_set": "geosite-geolocation-!cn",
        "server": "dns_proxy"
      },
      {
        "query_type": [
          "AAAA"
        ],
        "server": "dns_block"
      }
    ],
    "final": "dns_direct",
    "strategy": "ipv4_only"
  },
  "inbounds": [
    {
      "type": "socks",
      "tag": "socks-in",
      "listen": "127.0.0.1",
      "listen_port": 10808,
      "sniff": true
    },
    {
      "type": "http",
      "tag": "http-in",
      "listen": "127.0.0.1",
      "listen_port": 10809,
      "sniff": true
    }
  ],
  "outbounds": [
    {
      "type": "selector",
      "tag": "节点选择",
      "outbounds": [
        "香港-Hysteria2",
        "日本-Reality",
        "direct"
      ],
      "default": "香港-Hysteria2"
    },
    {
      "type": "hysteria2",
      "tag": "香港-Hysteria2",
      "server": "hk.yourdomain.com",
      "server_port": 443,
      "up_mbps": 50,
      "down_mbps": 100,
      "password": "yourpassword",
      "tls": {
        "enabled": true,
        "server_name": "hk.yourdomain.com",
        "insecure": false
      }
    },
    {
      "type": "vless",
      "tag": "日本-Reality",
      "server": "jp.yourdomain.com",
      "server_port": 443,
      "uuid": "your-uuid-here",
      "flow": "xtls-rprx-vision",
      "tls": {
        "enabled": true,
        "server_name": "images.apple.com",
        "utls": {
          "enabled": true,
          "fingerprint": "chrome"
        },
        "reality": {
          "enabled": true,
          "public_key": "your-reality-public-key-here",
          "short_id": "your-short-id"
        }
      }
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    }
  ],
  "route": {
    "rules": [
      {
        "type": "logical",
        "mode": "or",
        "rules": [
          {
            "port": 53
          },
          {
            "protocol": "dns"
          }
        ],
        "outbound": "dns-out"
      },
      {
        "clash_mode": "Direct",
        "outbound": "direct"
      },
      {
        "clash_mode": "Global",
        "outbound": "节点选择"
      },
      {
        "rule_set": [
          "geosite-category-ads-all"
        ],
        "outbound": "block"
      },
      {
        "rule_set": [
          "geosite-geolocation-!cn",
          "geoip-google"
        ],
        "outbound": "节点选择"
      },
      {
        "rule_set": [
          "geoip-cn",
          "geosite-cn"
        ],
        "outbound": "direct"
      }
    ],
    "rule_set": [
      {
        "tag": "geosite-category-ads-all",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/geosite-category-ads-all.srs",
        "download_detour": "节点选择"
      },
      {
        "tag": "geosite-geolocation-!cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/geosite-geolocation-!cn.srs",
        "download_detour": "节点选择"
      },
      {
        "tag": "geosite-cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geosite/geosite-cn.srs",
        "download_detour": "节点选择"
      },
      {
        "tag": "geoip-cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geoip/geoip-cn.srs",
        "download_detour": "节点选择"
      },
      {
        "tag": "geoip-google",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/lyc8503/sing-box-rules/rule-set-geoip/geoip-google.srs",
        "download_detour": "节点选择"
      }
    ],
    "final": "direct",
    "auto_detect_interface": true
  }
}

🛠️ Sing-Box 核心模块避坑指引

手写 JSON 配置文件时,有三个最容易出错的地方:

1. DNS 泄漏与 Detour 环路

2. Rule-Set 格式冲突

3. AAAA (IPv6) 解析阻断


相关推荐

版权声明

作者: 易邦

链接: https://e8k.net/posts/sing-box-json-config/

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

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