跳转至

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
  },
  "inbounds": [
    {
      "tag": "proxy-in",
      "multiplex": { // 多路复用,仅限部分代理
        "enabled": true
      // 其他字段
    }
    // 其他入站
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct-out"
    }
    // 其他出站配置,比如 warp...
  ],
  "route": {
    "rules": [
      // ...一些路由规则
    ],
    "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 成功计数。

$ watch -n 1 "nstat -az | grep TcpExtTCPFastOpen"
...
TcpExtTCPFastOpenActive         16605              0.0
TcpExtTCPFastOpenActiveFail     12                 0.0
TcpExtTCPFastOpenPassive        0                  0.0
TcpExtTCPFastOpenPassiveFail    0                  0.0
TcpExtTCPFastOpenListenOverflow 0                  0.0
TcpExtTCPFastOpenCookieReqd     0                  0.0
TcpExtTCPFastOpenBlackhole      0                  0.0
TcpExtTCPFastOpenPassiveAltKey  0                  0.0
不推荐 TFO 是因为多路复用性价比更高,对应 sing-box 的 multiplex 字段,不过 sing-mux 说实话体验一般,有不少小问题。同时不推荐用 anytls 等会话层复用代理。

客户端配置(仅适用于 Linux,Windows 等其他平台需要关闭 auto_redirect 相关设置):

{
  "log": {
    "level": "warn"
  },
  "dns": {
    "servers": [
      {
        "tag": "dns-remote",
        "type": "https", // 强烈建议远程 dns 使用 doh 以获得更好的性能,如果代理有原生 udp 能力可以考虑使用 h3(有可能降速)
        "server": "8.8.4.4",
        "tls": {
          "enabled": true,
          "server_name": "dns.google"
        },
        "detour": "proxy"
      },
      {
        "tag": "dns-local",
        "type": "h3",
        "server": "223.5.5.5",
        "tls": {
          "enabled": true,
          "server_name": "dns.alidns.com"
        }
      }
    ],
    "rules": [ // dns 分流规则
      {
        "rule_set": ["cn-site", "cn-location"]
        "server": "dns-local"
      }
    ],
    "optimistic": {
      "enabled": true
    }
  },
  "http_clients": [
    {
      "tag": "go"
    }
  ],
  "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
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      // ...其他字段
      "multiplex": {
        "enabled": true
      }
    },
    {
      "tag": "direct",
      "type": "direct"
    }
  ],
  "route": {
    "rules": [
      {
        "network": ["icmp"],
        "outbound": "direct"
      },
      {
        "ip_is_private": true,
        "outbound": "direct"
      }
    ],
    "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": "5d"
      },
      {
        "type": "remote",
        "tag": "cn-ip",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/sing/geo/geoip/cn.srs",
        "update_interval": "7d"
      },
      {
        "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 代理给浏览器用(不过就和 fakeip 一样需要做好域名分流了)。


Loading Comments...