跳转至

sing-box 客户端 + 服务端配置参考

折腾一下 sing-box,这样的话就只有 mihomo 不会用了(

警告

以下配置可能无法满足您的需求

服务端配置(移除注释):

{
  "log": {
    "level": "warn",
    "output": "/var/log/sing-box/box.log", // 日志位置,不需要可删除
    // 注意: 自定义日志位置需要确保 sing-box 可访问
    // sing-box 默认工作路径是 /var/lib/sing-box
    "timestamp": true
  },
  "dns": {
    "servers": [
      {
        "type": "local",
        "tag": "local-dns"
      }
    ]
  },
  "inbounds": [
    {
      "tag": "proxy-in",
      "multiplex": { // 多路复用,仅限部分代理
        "enabled": true
      // 其他字段
    }
    // 其他入站
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct-out"
    }
    // 其他出站配置,比如 warp...
  ],
  "route": {
    "rules": [
      {
        "action": "sniff"
      },
      {
        "action": "resolve"
      },
      {
        "protocol": ["bittorrent", "quic"], // 屏蔽 quic,不需要可删除
        "action": "reject"
      },
      // ...其他路由规则
    ],
    "rule_set": [
      // 一些规则集,屏蔽还是走其他出站自己配置
      {
        "type": "remote",
        "tag": "cn-site",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/cn.srs",
        "update_interval": "7d"
      },
      {
        "type": "remote",
        "tag": "cn-ip",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geoip/cn.srs",
        "update_interval": "7d"
      }
    ]
  }
}
注意到网上分享的配置一般都开启了 TFO[TCP Fast Open],我个人观点是不推荐启用。如果要启用 TFO 的话一定要验证 TFO 是否生效,可以用 ss 等命令查看本地 TFO 成功计数,我测试下来电信家宽成功率还是蛮高的,测试过美国/日本/香港三个不同机房,高峰期 22 点左右成功率在 90% 左右,白天成功率则在 97% 以上)。

不推荐 TFO 是因为多路复用性价比更高,对应 sing-box 的 multiplex 字段,其他代理自带的 mux 不推荐用,比如 naive 和 anytls。

客户端配置:

{
  "log": {
    "level": "warn"
  },
  "certificate": { "store": "mozilla" }, // 使用 mozilla 证书集合
  "dns": {
    "servers": [
      {
        "tag": "dns-remote",
        "type": "tcp",
        "server": "1.1.1.1",
        "detour": "proxy"
      },
      {
        "domain_resolver": "dns-local",
        "path": "dns-query",
        "server": "dns.alidns.com",
        "tag": "dns-direct",
        "type": "https"
      },
      {
        "tag": "dns-local",
        "type": "local"
      }
    ],
    "rules": [ // dns 分流规则
      {
        "type": "logical",
        "mode": "or",
        "rules": [
          {
            "domain": ["example.com"] // 额外添加域名走 dns-direct
          },
          {
            "rule_set": ["cn-site", "cn-location"]
          }
        ],
        "server": "dns-direct"
      }
    ]
  },
  "inbounds": [
    {
      "type": "tun",
      "address": ["172.19.0.1/30", "fdfe:dcba:9876::1/126"],
      "mtu": 9000,
      "stack": "system",
      "auto_route": true,
      "auto_redirect": true,
      "route_exclude_address_set": ["cnip"],
      "strict_route": true
    },
    {
      "type": "mixed", // 留一个 mixed 给浏览器用
      "listen": "127.0.0.1",
      "listen_port": 1080
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      // ...其他字段
      "multiplex": {
        "enabled": true
      }
    },
    {
      "tag": "direct",
      "type": "direct"
    }
  ],
  "route": {
    "rules": [
      {
        "action": "sniff"
      },
      {
        "protocol": "dns",
        "action": "hijack-dns"
      },
      {
        "ip_is_private": true,
        "outbound": "direct"
      },
      {
        "rule_set": ["cn-location", "cn-site"],
        "outbound": "direct"
      }
      //...其他规则
    ],
    "rule_set": [
      {
        "type": "remote",
        "tag": "cn-site",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo-lite/geosite/cn.srs",
        "update_interval": "2d"
      },
      {
        "format": "binary",
        "tag": "cn-location",
        "type": "remote",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geosite/geolocation-cn.srs",
        "update_interval": "7d"
      }
    ],
    "default_domain_resolver": {
      "server": "dns-remote"
    },
    "auto_detect_interface": true
  },
  "experimental": {
    "cache_file": {
      "enabled": true
    }
  }
}
然后你会注意到我并没有 fakeip,因为 fakeip 基本上只是为了满足小众需求的产物,大部分人只是跟风为了所谓的降低延迟使用 fakeip。如果真的在乎这些延迟,sing-box 1.14 可以启用乐观缓存,1.14 之前可以单独开一个 http 代理给浏览器用。


Loading Comments...