Youtube视频


相关链接

sing-box配置文档

生成ech keypair

# plain_server_name 自己填
# 会生成keys和confis,分别保存到文件,如ech.key、ech.config
singbox generate <plain_server_name> --pq-signature-schemes-enabled

格式化ech.config为单行

可用于移动客户端通过config文本来配置ech的密钥
awk 'NF {printf "%s\\n",$0}' ech.config

服务端测试配置

仅测试,以下为vless ws配置
{
  "log": {
    "disabled": false,
    "level": "info",
    "timestamp": true
  },
  "dns": {
    "servers": [
      {
        "tag": "cf",
        "address": "https://1.1.1.1/dns-query",
        "strategy": "ipv4_only",
        "detour": "direct"
      },
      {
        "tag": "block",
        "address": "rcode://success"
      }
    ],
    "rules": [
      {
        "geosite": [
          "category-ads-all"
        ],
        "server": "block",
        "disable_cache": true
      }
    ],
    "final": "cf",
    "strategy": "",
    "disable_cache": false,
    "disable_expire": false
  },
  "inbounds": [
    {
      "type": "vless",
      "tag": "vless-in",
      "listen": "::",
      "listen_port": 443,
      "tcp_fast_open": false,
      "tcp_multi_path": false,
      "udp_fragment": false,
      "sniff": false,
      "sniff_override_destination": false,
      "sniff_timeout": "300ms",
      "domain_strategy": "prefer_ipv6",
      "udp_timeout": 300,
      "proxy_protocol": false,
      "proxy_protocol_accept_no_header": false,
      "users": [
        {
          "name": "Elden",
          "uuid": "你的UUID",
          "flow": ""
        }
      ],
      "tls": {
        "enabled": true, 
        "server_name": "你的域名",
        "certificate_path": "你的证书文件路径",
        "key_path": "你的密钥文件路径",
        "ech": {
          "enabled": true,
          "pq_signature_schemes_enabled": true,
          "dynamic_record_sizing_disabled": false,
          "key_path": "你的ECH KEYS文件路径"
        }
      },
      "transport": {
        "type": "ws",
        "path": "你的PATH路径",
        "headers": {},
        "max_early_data": 0,
        "early_data_header_name": ""
      }
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    },
    {
      "type": "dns",
      "tag": "dns-out"
    }
  ],
  "route": {
    "geoip": {
      "path": "geoip.db",
      "download_url": "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db",
      "download_detour": "direct"
    },
    "geosite": {
      "path": "geosite.db",
      "download_url": "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db",
      "download_detour": "direct"
    },
    "rules": [
      {
        "protocol": "dns",
        "outbound": "dns-out"
      },
      {
        "geosite": [
          "category-ads-all"
        ],
        "outbound": "block"
      }
    ],
    "auto_detect_interface": true,
    "final": "direct"
  },
  "experimental": {}
}

服务端运行命令

# -c 指定配置文件路径,以下代表当前目录存在server.json
singbox run -c server.json

PC客户端测试配置

仅测试,以下为vless ws配置
{
  "dns": {
    "servers": [
      {
        "tag": "alidns",
        "address": "https://223.5.5.5/dns-query",
        "address_strategy": "prefer_ipv4",
        "strategy": "ipv4_only",
        "detour": "direct"
      },
      {
        "tag": "cf",
        "address": "https://1.1.1.1/dns-query",
        "strategy": "ipv4_only",
        "detour": "direct"
      },
      {
        "tag": "block",
        "address": "rcode://success"
      }
    ],
    "rules": [
      {
        "geosite": [
          "cn"
        ],
        "domain_suffix": [
          ".cn"
        ],
        "server": "alidns",
        "disable_cache": false
      },
      {
        "geosite": [
          "category-ads-all"
        ],
        "server": "block",
        "disable_cache": true
      }
    ],
    "final": "cf",
    "strategy": "",
    "disable_cache": false,
    "disable_expire": false
  },
  "inbounds": [
    {
      "type": "mixed",
      "tag": "mixed-in",
      "listen": "::",
      "listen_port": 5353,
      "tcp_fast_open": false,
      "tcp_multi_path": false,
      "udp_fragment": false,
      "sniff": true,
      "sniff_override_destination": false,
      "sniff_timeout": "300ms",
      "domain_strategy": "prefer_ipv4",
      "udp_timeout": 300,
      "proxy_protocol": false,
      "proxy_protocol_accept_no_header": false,
      "set_system_proxy": true
    }
  ],
  "outbounds": [
    {
      "type": "vless",
      "tag": "proxy",
      "server": "你的域名",
      "server_port": 443,
      "uuid": "你的UUID",
      "flow": "",
      "tls": {
        "enabled": true,
        "ech": {
          "enabled": true,
          "pq_signature_schemes_enabled": true,
          "dynamic_record_sizing_disabled": false,
          "config_path": "你的ech.config文件目录"
        }
      },
      "packet_encoding": "",
      "transport": {
        "type": "ws",
        "path": "你服务端配置的PATH路径",
        "headers": {},
        "max_early_data": 0,
        "early_data_header_name": ""
      }
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    },
    {
      "type": "dns",
      "tag": "dns-out"
    }
  ],
  "route": {
    "geoip": {
      "path": "geoip.db",
      "download_url": "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db",
      "download_detour": "direct"
    },
    "geosite": {
      "path": "geosite.db",
      "download_url": "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db",
      "download_detour": "direct"
    },
    "rules": [
      {
        "protocol": "dns",
        "outbound": "dns-out"
      },
      {
        "geosite": [
          "cn",
          "private"
        ],
        "geoip": [
          "cn",
          "private"
        ],
        "domain_suffix": [
          ".cn"
        ],
        "outbound": "direct"
      },
      {
        "geosite": [
          "category-ads-all"
        ],
        "outbound": "block"
      }
    ],
    "auto_detect_interface": true,
    "final": "proxy"
  },
  "experimental": {}
}

IOS客户端测试配置

仅测试,以下是vless quic配置
{
  "dns": {
    "servers": [
      {
        "tag": "alidns",
        "address": "https://223.5.5.5/dns-query",
        "address_strategy": "prefer_ipv4",
        "strategy": "ipv4_only",
        "detour": "direct"
      },
      {
        "tag": "cf",
        "address": "https://1.1.1.1/dns-query",
        "strategy": "ipv4_only",
        "detour": "direct"
      },
      {
        "tag": "block",
        "address": "rcode://success"
      }
    ],
    "rules": [
      {
        "geosite": [
          "cn"
        ],
        "domain_suffix": [
          ".cn"
        ],
        "server": "alidns",
        "disable_cache": false
      },
      {
        "geosite": [
          "category-ads-all"
        ],
        "server": "block",
        "disable_cache": true
      }
    ],
    "final": "cf",
    "strategy": "",
    "disable_cache": false,
    "disable_expire": false
  },
  "inbounds": [
    {
      "tag": "tun-in",
      "type": "tun",
      "interface_name": "utun",
      "inet4_address": "172.19.0.1/30",
      "auto_route": true,
      "strict_route": true,
      "stack": "gvisor",
      "mtu": 9000,
      "sniff": true,
      "sniff_timeout": "300ms",
      "domain_strategy": "",
      "udp_timeout": 300
    }
  ],
  "outbounds": [
    {
      "type": "vless",
      "tag": "proxy",
      "server": "你的域名",
      "server_port": 443,
      "uuid": "你的UUID",
      "flow": "",
      "tls": {
        "enabled": true,
        "ech": {
          "enabled": true,
          "pq_signature_schemes_enabled": true,
          "dynamic_record_sizing_disabled": false,
          "config": "你的ECH CONFIGS文本,请参考格式化"
        }
      },
      "packet_encoding": "",
      "transport": {
        "type": "quic"
      }
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    },
    {
      "type": "dns",
      "tag": "dns-out"
    }
  ],
  "route": {
    "geoip": {
      "path": "geoip.db",
      "download_url": "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db",
      "download_detour": "direct"
    },
    "geosite": {
      "path": "geosite.db",
      "download_url": "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db",
      "download_detour": "direct"
    },
    "rules": [
      {
        "protocol": "dns",
        "outbound": "dns-out"
      },
      {
        "geosite": [
          "cn",
          "private"
        ],
        "geoip": [
          "cn",
          "private"
        ],
        "domain_suffix": [
          ".cn"
        ],
        "outbound": "direct"
      },
      {
        "geosite": [
          "category-ads-all"
        ],
        "outbound": "block"
      }
    ],
    "auto_detect_interface": true,
    "final": "proxy"
  },
  "experimental": {}
}
如果觉得我的文章对你有用,请随意赞赏