Skip to content

规则:一条连接的一生 ​

路由先决定一条流看到哪些事实,再按规则顺序选择动作。代理出站遵循“先拨后应”:目标真实连上后才让客户端握手成功。

完整配置 ​

yaml
rule_sets:
  lan-private:
    rules:
      - ip_is_private: true

outbounds:
  direct:
    type: direct
  proxy:
    type: socks
    server: 127.0.0.1:1080

route:
  rules:
    - {rule_set: lan-private, outbound: direct}
    - {protocol: dns, action: hijack-dns}
    - {action: sniff, timeout: 1s, sniffer: [tls, http, quic]}
    - {domain_suffix: [blocked.example], action: reject, method: drop}
    - {domain_suffix: [example.com], outbound: proxy}
  final: direct

dns:
  servers:
    real: {type: udp, address: 1.1.1.1:53}
    fake: {type: fakeip, inet4_range: 198.18.0.0/15}
  rules:
    - {domain_suffix: [lan], server: fake}
  final: real

字段和动作见 路由规则、规则动作 和 协议探测。

怎样选 ​

  • 地址直连优先放在前面,可下沉到内核快路径。
  • 需要域名的规则前先放 sniff,否则首包还没有协议和域名。
  • hijack-dns 把客户端写死的 DNS 交给统一 DNS 引擎。
  • resolve 在规则链中途解析名字;PASS/PASS-RULE 继续后续规则。
  • route-options 修改目标、UDP 空闲时间和 TLS 分片;选项只影响后续执行。

模式与规则集 ​

mode: rule 遍历规则;global 走 GLOBAL 选择器;direct 全部直连。自定义模式名可通过 clash_mode 限定规则。规则集来自本地文件、URL、内联 payload 或 sing-box 规则,见 rule_set。

相关 ​

页面历史

开发者设计、代码地图和验证记录保留在仓库 manual/。