服务端简单配置

注意

  • 使用了"method": "2022-blake3-aes-128-gcm",
  • Shadowsocks-2022对密码格式有严格的校验要求,如果不符合规范,sing-box 启动时会直接报错。
  • 密码必须是 Base64 格式。
  • 密码生成方式:
openssl rand -base64 16
  • 生成的字符串类似于vgY7B3N6hM+8pW/J1Q9v9g==,把它填入 password 字段。
{
  "log": {
    "level": "info"
  },
  "dns": {
    "servers": [
      {
        "type": "tls",
        "tag": "ali-dns",
        "server": "223.5.5.5"
      }
    ]
  },
  "inbounds": [
    {
      "type": "shadowsocks",
      "tag": "ss-in",
      "listen": "::",
      "listen_port": 10808,
      "network": [
        "tcp",
        "udp"
      ],
      "method": "2022-blake3-aes-128-gcm",
      "password": "vgY7B3N6hM+8pW/J1Q9v9g==",
      "multiplex": {
        "enabled": true,
        "padding": true
      }

    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    }
  ],
  "route": {
    "rules": [
      {
        "port": 53,
        "action": "hijack-dns"

      }


    ],
    "final": "direct"
  }
}

客户端配置

下面的模版是,根据局域网设备的ip,确定出口

  • 如果是socks5协议,dns可能需要改为tls,而非udp,很多节点不支持udp
{
    "log": {
    "level": "info",
    "output": "/var/log/sing-box.log",
    "timestamp": true
  },
  "inbounds": [
    {
      "type": "tun",
      "tag": "tun-in",
      "interface_name": "tun0",
      "address": "172.19.0.1/30",
      "mtu": 1400,
      "auto_route": true,
      "strict_route": true,
      "auto_redirect": true,
      "stack": "system",
      "platform": {
        "http_proxy": {
          "enabled": false
        }
      }
    }
  ],
  "experimental": {
    "cache_file": {
      "enabled": true,
      "path": "/var/lib/sing-box/cache.db",
      "store_fakeip": true
    },
    "clash_api": {
      "external_controller": "0.0.0.0:9090",
      "external_ui": "/usr/share/sing-box/ui"
    }
  },
  "dns": {
    "servers": [
      {
        "tag": "Fake-IP",
        "type": "fakeip",
        "inet4_range": "198.18.0.0/15",
        "inet6_range": "fc00::/18"
      },
      {
        "tag": "Local-DNS",
        "type": "https",
        "domain_resolver": "Local-DNS-Resolver",
        "server_port": 443,
        "server": "223.5.5.5",
        "path": "/dns-query"
      },
      {
        "tag": "Local-DNS-Resolver",
        "type": "udp",
        "server_port": 53,
        "server": "223.5.5.5"
      },
      {
        "tag": "Remote-DNS",
        "type": "tls",
        "detour": "🚀 节点选择",
        "domain_resolver": "Remote-DNS-Resolver",
        "server_port": 853,
        "server": "8.8.8.8"
      },
      {
        "tag": "Remote-DNS-Resolver",
        "type": "udp",
        "detour": "🚀 节点选择",
        "server_port": 53,
        "server": "8.8.8.8"
      },
      {
        "tag": "DNS-VPS-1",
        "type": "udp",
        "server": "223.5.5.5",
        "detour": "VPS-140"
      }
    ],
    "rules": [
      {
        "rule_set": [
          "Category-Ads"
        ],
        "action": "reject"

      },
      {
        "source_ip_cidr": "10.0.1.2/32",
        "server": "DNS-VPS-1"
      },
      {
        "clash_mode": "direct",
        "action": "route",
        "server": "Local-DNS"
      },
      {
        "clash_mode": "global",
        "action": "route",
        "server": "Fake-IP"
      },
      {
        "rule_set": [
          "GeoSite-Private",
          "GeoSite-CN"
        ],
        "action": "route",
        "server": "Local-DNS"
      },
      {
        "rule_set": [
          "GeoLocation-!CN"
        ],
        "query_type": [
          "A",
          "AAAA"
        ],
        "action": "route",
        "server": "Fake-IP"
      },
      {
        "query_type": [
          "A",
          "AAAA"
        ],
        "action": "route",
        "server": "Fake-IP"
      }
    ],
    "disable_cache": false,
    "disable_expire": false,
    "independent_cache": true,
    "final": "Remote-DNS"
  },
  "outbounds": [
    {
      "type": "urltest",
      "tag": "🎈 自动选择",
      "url": "https://www.gstatic.com/generate_204",
      "interval": "3m",
      "tolerance": 150,
      "interrupt_exist_connections": true,
      "outbounds": [
        "VPS-140"
      ]
    },
    {
      "type": "selector",
      "tag": "🚀 节点选择",
      "interrupt_exist_connections": true,
      "outbounds": [
        "🎈 自动选择",
        "VPS-140"
      ]
    },
    {
      "type": "selector",
      "tag": "🎯 全球直连",
      "interrupt_exist_connections": true,
      "outbounds": [
        "direct",
        "block"
      ]
    },
    {
      "type": "selector",
      "tag": "🛑 全球拦截",
      "interrupt_exist_connections": true,
      "outbounds": [
        "block",
        "direct"
      ]
    },
    {
      "type": "selector",
      "tag": "🐟 漏网之鱼",
      "interrupt_exist_connections": true,
      "outbounds": [
        "🚀 节点选择",
        "🎯 全球直连"
      ]
    },
    {
      "type": "selector",
      "tag": "GLOBAL",
      "interrupt_exist_connections": true,
      "outbounds": [
        "🚀 节点选择",
        "🎈 自动选择",
        "🎯 全球直连",
        "🛑 全球拦截",
        "🐟 漏网之鱼"
      ]
    },
    {
      "tag": "VPS-144",
      "type": "vmess",
      "server": "111.111.111.111",
      "server_port": 10808,
      "uuid": "da8cd9b2-e200-442d-a549-6d09f2dfbd4d",
      "security": "auto",
      "alter_id": 0
    },
    {
      "type": "socks",
      "tag": "VPS-175",
      "server": "xxx.xxx.xxx",
      "server_port": 9125,
      "version": "5",
      "username": "xxxxxxx",
      "password": "xxxxxxx",
      "udp_over_tcp": true
    },
    {
      "type": "shadowsocks",
      "tag": "VPS-140",
      "server": "111.111.111.111",
      "server_port": 10809,
      "method": "2022-blake3-aes-128-gcm",
      "password": "Gn1JUS14bLUHgv1cWDDp4A==",
      "multiplex": {
        "enabled": true,
        "padding": true
      }
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    }
  ],
  "route": {
        "rules": [
            {
                "action": "sniff"
            },
            {
                "protocol": "quic",
                "action": "reject"
            },
            {
                "action": "hijack-dns",
                "protocol": "dns"
            },
            {
                "rule_set": [
                    "Category-Ads"
                ],
                "action": "reject"

            },
            {
                "action": "route",
                "network": "icmp",
                "outbound": "🎯 全球直连"
            },
            {
                "source_ip_cidr": [
                    "10.0.1.2"
                ],
                "action": "route",
                "outbound": "VPS-140"
            },
            {
                "action": "route",
                "clash_mode": "direct",
                "outbound": "🎯 全球直连"
            },
            {
                "action": "route",
                "clash_mode": "global",
                "outbound": "GLOBAL"
            },

            {
                "action": "route",
                "rule_set": [
                    "GeoSite-Private"
                ],
                "outbound": "🎯 全球直连"
            },
            {
                "action": "route",
                "rule_set": [
                    "GeoSite-CN"
                ],
                "outbound": "🎯 全球直连"
            },
            {
                "action": "route",
                "rule_set": [
                    "GeoIP-Private"
                ],
                "outbound": "🎯 全球直连"
            },
            {
                "action": "route",
                "rule_set": [
                    "GeoIP-CN"
                ],
                "outbound": "🎯 全球直连"
            },
            {
                "action": "route",
                "rule_set": [
                    "GeoLocation-!CN"
                ],
                "outbound": "🚀 节点选择"
            }
        ],
        "rule_set": [
            {
                "tag": "Category-Ads",
                "type": "remote",
                "url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/category-ads-all.srs",
                "format": "binary",
                "download_detour": "🎯 全球直连"
            },
            {
                "tag": "GeoIP-Private",
                "type": "remote",
                "url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geoip/private.srs",
                "format": "binary",
                "download_detour": "🎯 全球直连"
            },
            {
                "tag": "GeoSite-Private",
                "type": "remote",
                "url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/private.srs",
                "format": "binary",
                "download_detour": "🎯 全球直连"
            },
            {
                "tag": "GeoIP-CN",
                "type": "remote",
                "url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geoip/cn.srs",
                "format": "binary",
                "download_detour": "🎯 全球直连"
            },
            {
                "tag": "GeoSite-CN",
                "type": "remote",
                "url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/cn.srs",
                "format": "binary",
                "download_detour": "🎯 全球直连"
            },
            {
                "tag": "GeoLocation-!CN",
                "type": "remote",
                "url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/geolocation-!cn.srs",
                "format": "binary",
                "download_detour": "🎯 全球直连"
            }
        ],
        "auto_detect_interface": true,
        "final": "🐟 漏网之鱼",
        "default_domain_resolver": {
            "server": "Local-DNS"
        }
    }

},