sing-box 1.8.0+ 迁移指南

Youtube视频


相关链接

sing-box官方文档

sing-box官方仓库

Server 服务端

{
  "log": {
    "disabled": false,
    "level": "info",
    "timestamp": true
  },
  "dns": {
    "servers": [
      {
        "tag": "cloudflare",
        "address": "https://1.1.1.1/dns-query",
        "strategy": "ipv4_only",
        "detour": "direct"
      },
      {
        "tag": "block",
        "address": "rcode://success"
      }
    ],
    "rules": [
      {
        "rule_set": [
          "geosite-category-ads-all"
        ],
        "server": "block"
      }
    ],
    "final": "cloudflare",
    "strategy": "",
    "disable_cache": false,
    "disable_expire": false
  },
  "inbounds": [
    {
      // 你的入站配置
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    },
    {
      "type": "dns",
      "tag": "dns-out"
    }
  ],
  "route": {
    "rules": [
      {
        "protocol": "dns",
        "outbound": "dns-out"
      },
      {
        "ip_is_private": true,
        "outbound": "direct"
      },
      {
        "rule_set": [
          "geosite-category-ads-all"
        ],
        "outbound": "block"
      }
    ],
    "rule_set": [
      {
        "tag": "geosite-category-ads-all",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs",
        "download_detour": "direct"
      }
    ],
    "auto_detect_interface": true,
    "final": "direct"
  },
  "experimental": {
    "cache_file": {
      "enabled": true,
      "path": "cache.db",
      "cache_id": "mycacheid",
      "store_fakeip": true
    }
  }
}

Client 客户端

{
  "dns": {
    "servers": [
      {
        "tag": "alidns",
        "address": "https://223.5.5.5/dns-query",
        "strategy": "ipv4_only",
        "detour": "direct"
      },
      {
        "tag": "cloudflare",
        "address": "https://1.1.1.1/dns-query",
        "strategy": "ipv4_only",
        "detour": "proxy"
      },
      {
        "tag": "block",
        "address": "rcode://success"
      }
    ],
    "rules": [
      {
        "outbound": [
          "any"
        ],
        "server": "alidns"
      },
      {
        "domain_suffix": [
          ".cn"
        ],
        "server": "alidns"
      },
      {
        "rule_set": [
          "geosite-cn"
        ],
        "server": "alidns"
      },
      {
        "rule_set": [
          "geosite-category-ads-all"
        ],
        "server": "block"
      }
    ],
    "final": "cloudflare",
    "strategy": "",
    "disable_cache": false,
    "disable_expire": false
  },
  "inbounds": [
    {
      "type": "mixed",
      "tag": "mixed-in",
      "listen": "::",
      "listen_port": 5353,
      "tcp_fast_open": true,
      "udp_fragment": true,
      "sniff": true,
      "set_system_proxy": true
    }
  ],
  "outbounds": [
    {
      // 你的出站配置
      }
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    },
    {
      "type": "dns",
      "tag": "dns-out"
    }
  ],
  "route": {
    "rules": [
      {
        "protocol": "dns",
        "outbound": "dns-out"
      },
      {
        "ip_is_private": true,
        "outbound": "direct"
      },
      {
        "domain_suffix": [
          ".cn"
        ],
        "outbound": "direct"
      },
      {
        "rule_set": [
          "geoip-cn",
          "geosite-cn",
          "geosite-private"
        ],
        "outbound": "direct"
      },
      {
        "rule_set": [
          "geosite-category-ads-all"
        ],
        "outbound": "block"
      }
    ],
    "rule_set": [
      {
        "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-cn",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-cn.srs",
        "download_detour": "proxy"
      },
      {
        "tag": "geosite-private",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-private.srs",
        "download_detour": "proxy"
      },
      {
        "tag": "geosite-category-ads-all",
        "type": "remote",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs",
        "download_detour": "proxy"
      }
    ],
    "auto_detect_interface": true,
    "final": "proxy"
  },
  "experimental": {
    "clash_api": {
      "external_controller": "127.0.0.1:9090",
      "external_ui_download_url": "",
      "secret": "22e694e4-093d-44bb-8ed2-b0e548c87a2e",
      "default_mode": "",
      "external_ui_download_detour": "",
      "external_ui": "ui"
    },
    "cache_file": {
      "enabled": true,
      "path": "cache.db",
      "cache_id": "mycacheid",
      "store_fakeip": true
    }
  }
}

Headless Rule 无头规则

  • 格式

    {
      "rules": [
        {
          "query_type": [
            "A",
            "HTTPS",
            32768
          ],
          "network": [
            "tcp"
          ],
          "domain": [
            "test.com"
          ],
          "domain_suffix": [
            ".cn"
          ],
          "domain_keyword": [
            "test"
          ],
          "domain_regex": [
            "^stun\\..+"
          ],
          "source_ip_cidr": [
            "10.0.0.0/24",
            "192.168.0.1"
          ],
          "ip_cidr": [
            "10.0.0.0/24",
            "192.168.0.1"
          ],
          "source_port": [
            12345
          ],
          "source_port_range": [
            "1000:2000",
            ":3000",
            "4000:"
          ],
          "port": [
            80,
            443
          ],
          "port_range": [
            "1000:2000",
            ":3000",
            "4000:"
          ],
          "process_name": [
            "curl"
          ],
          "process_path": [
            "/usr/bin/curl"
          ],
          "package_name": [
            "com.termux"
          ],
          "wifi_ssid": [
            "My WIFI"
          ],
          "wifi_bssid": [
            "00:00:00:00:00:00"
          ],
          "invert": false
        },
        {
          "type": "logical",
          "mode": "and",
          "rules": [],
          "invert": false
        }
      ]
    }
  • 自定义规则集

    {
      "version": 1,
      "rules": [
        {
          "domain_suffix": [
            ".dev"
          ]
        }
      ]
    }
  • 将规则集转换为srssing-box二进制规则集文件

    # --output 为输出的规则集文件,最后面指定的是自定义规则集的文件
    ./sing-box rule-set compile --output dev-rule.srs dev-rule.json
  • 添加自定义规则集,如果不转化为二进制,下面的format可以指定为source

    {
      "rule_set": [
        {
          "tag": "dev",
          "type": "local",
          "format": "binary",
          "path": "dev-rule.srs"
        }
      }
如果觉得我的文章对你有用,请随意赞赏