Skip to content

senzyo/sing-box-templates

Repository files navigation

sing-box-templates

搭配 Toperlock/sing-box-subscribe 使用的 sing-box 配置转换模板, 仅适用于客户端

⚠️ 要求 sing-box 版本 ≥ 1.11.0 ⚠️

1. 模板分类

文件的存储路径按照 "入站方式 → DNS 协议 → 中国 DNS 服务商 → 国际 DNS 服务商 → 规则集 CDN → 配置文件名称" 进行层级划分。

比如对于 https://raw.githubusercontent.com/senzyo/sing-box-templates/public/tun/doh/ali/google/testingcf.jsdelivr.net/config.json, 即 https://raw.githubusercontent.com/senzyo/sing-box-templates/<Git 分支名称>/<入站方式>/<DNS 协议>/<中国 DNS 服务商>/<国际 DNS 服务商>/<规则集 CDN>/<配置文件名称>

  • 入站方式 的可选值: mixed, tun
  • DNS 协议 的可选值: doh, doq, dot, h3
  • 中国 DNS 服务商 的可选值: ali, dnspod
  • 国际 DNS 服务商 的可选值: adguard, cloudflare, google, opendns
  • 规则集 CDN 的可选值: fastly.jsdelivr.net, gcore.jsdelivr.net, testingcf.jsdelivr.net, ghproxy.net, gh-proxy.com, ghfast.top(域名经常变动, 关注地址发布页 ghproxy.link)
  • 配置文件名称 的可选值:
    • 对于 入站方式mixed 的, 可选值: config.json
    • 对于 入站方式tun 的, 可选值: config.json, config_fakeip.json, config_apple.json

当然有些 DNS 服务商不支持 DNS over QUIC (DoQ) 或 DNS over HTTP3 (DoH3), 所以, 当你用上述可选值选择模板时, 确保它在 public 分支中是存在的。

2. 选择模板

2.1 TUN

推荐 Android, Linux 和 Windows 使用入站方式为 tun 的模板, 比如:

https://raw.githubusercontent.com/senzyo/sing-box-templates/public/tun/doh/ali/google/testingcf.jsdelivr.net/config.json

也可使用 FakeIP, 比如:

https://raw.githubusercontent.com/senzyo/sing-box-templates/public/tun/doh/ali/google/testingcf.jsdelivr.net/config_fakeip.json

对于 Apple 设备, 使用文件名为 config_apple.json 的模板, 比如: ⚠️ 暂不可用 ⚠️

https://raw.githubusercontent.com/senzyo/sing-box-templates/public/tun/doh/ali/google/testingcf.jsdelivr.net/config_apple.json

2.2 Mixed

不推荐使用入站方式仅为 mixed 的模板, 比如:

https://raw.githubusercontent.com/senzyo/sing-box-templates/public/mixed/doh/ali/google/testingcf.jsdelivr.net/config.json

3. 使用示例

#!/bin/bash

url_gene="https://a.com"  # 生成配置的后端地址
url_sub="https://b.com"   # 来自机场的订阅链接
url_tpl="https://raw.githubusercontent.com/senzyo/sing-box-templates/public/tun/doh/ali/google/testingcf.jsdelivr.net/config.json"  # 配置所用模板的地址
url_dl="$url_gene/config/$url_sub&ua=clashmeta&emoji=1&file=$url_tpl"
echo $url_dl
curl -L -o config.json "$url_dl"

也就是说, 可以拼接 生成配置的后端地址+来自机场的订阅链接+配置所用模板的地址 得到最终的订阅地址, 然后将其添加至 Android 或 Apple 设备的 sing-box 图形客户端中。比如: https://a.com/config/https://b.com&ua=clashmeta&emoji=1&file=https://raw.githubusercontent.com/senzyo/sing-box-templates/public/tun/doh/ali/google/testingcf.jsdelivr.net/config.json

对于 Linux 和 Windows, 可参阅 sing-box on Linuxsing-box on Windows

至于 Toperlock/sing-box-subscribe 的更多参数信息, 请阅读其 README

4. 注意

在 Windows 中, 如果在 TUN 配置中启用了严格路由, 则:

  • 不必手动启用组策略中 计算机配置管理模板网络DNS 客户端禁用智能多宿主名称解析 这一策略了, 保持这一策略为 未配置/已禁用 即可。
  • 不必手动为 sing-box 配置 Windows 防火墙, sing-box 会自动配置的。
  • 不然, 你会发现虽然测速延迟还可以, 但实际速度很慢。
  • 由于 mihomo 和 sing-box 都使用 sing-tun, 所以上述注意事项同样适用于 mihomo。

5. DNS

5.1 DNS 协议

DNS 协议使用 DNS over HTTPSDNS over QUICDNS over TLSDNS over HTTP3, 更多 DNS 协议与格式参考 sing-box 文档。

5.2 DNS 服务商

中国 DNS 包括 Ali DNSDNSPod

国际 DNS 包括 AdGuard DNS, Cisco OpenDNS, Cloudflare DNSGoogle DNS

更多 DNS 服务商 参考

5.2.1 Ali DNS

根据 公共 DNS 免费版接入限速, 单 IP 访问量 超过 20 QPS, UDP/TCP 流量超过 2000 bps 将被限速。 升级到公共 DNS 付费版, 每月有 1000 万次 的免费解析额度。

5.2.2 DNSPod

根据 DoH 与 DoT 说明, 单个域名解析调用频率 限制为 20 QPS。 开通腾讯云 Public DNS 专业版, 每月有 300 万次 的免费解析额度。

  "dns": {
    "servers": [
      {
        "tag": "国际 DNS",
        "address": "https://dns.google/dns-query",
        "address_resolver": "CNNIC DNS",
        "detour": "🚀 默认出站"
      },
      {
        "tag": "中国 DNS",
        "address": "https://dns.alidns.com/dns-query",
        "address_resolver": "CNNIC DNS",
        "detour": "🐢 直连"
      },
      {
        "tag": "CNNIC DNS",
        "address": "1.2.4.8",
        "detour": "🐢 直连"
      }
    ],
  ...
  },

6. 规则集 CDN

仅影响客户端下载规则集的速度。

  "route": {
  ...
    "rule_set": [
    ...
      {
        "tag": "geosite_category-games",
        "type": "remote",
        "format": "binary",
        "url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/category-games.srs",
        "download_detour": "🐢 直连",
        "update_interval": "3d"
      },
    ...
    ]
  }

源地址举例:

https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/refs/heads/sing/geo/geosite/category-games.json

CDN 地址列举:

https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/category-games.json
https://gcore.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/category-games.json
https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/category-games.json
https://ghproxy.net/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/refs/heads/sing/geo/geosite/category-games.json
https://gh-proxy.com/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/refs/heads/sing/geo/geosite/category-games.json
https://ghfast.top/https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/refs/heads/sing/geo/geosite/category-games.json

可自行替换模板中使用的 CDN, 替换前推荐对这些 CDN 的域名进行 网站测速。另外不推荐 cdn.jsdelivr.net, 因为它偶尔会被墙。

GitLab 地址举例:

https://gitlab.com/senzyo_sama/as-gist/-/raw/master/Rule/sing-box/downloader.json

About

Templates for sing-box-subscribe.

Resources

Stars

Watchers

Forks

Languages