進階用法 · Clash文件

依規則分流的 WireGuard

說明關閉 WireGuard 預設路由接管後,如何使用 interface-name、DIRECT 與 DOMAIN 規則將流量送入 wg0,並核對 AllowedIPs、MTU 和 endpoint。

  • WireGuard
  • interface-name
  • AllowedIPs
  • MTU
  • endpoint
進階用法

假設您的核心支援 Wireguard 且已啟用。Table 選項可防止 wg-quick 覆寫預設路由。

例如 wg0.conf

ini
[Interface]
PrivateKey = ...
Address = 172.16.0.1/32
MTU = ...
Table = off
PostUp = ip rule add from 172.16.0.1/32 table 6666

[Peer]
AllowedIPs = 0.0.0.0/0
AllowedIPs = ::/0
PublicKey = ...
Endpoint = ...

然後在 Clash 中您只需要有一個 DIRECT 策略群組,它包含一個指定的出站介面:

yaml
proxy-groups:
  - name: Wireguard
    type: select
    interface-name: wg0
    proxies:
      - DIRECT
rules:
  - DOMAIN,google.com,Wireguard

這通常比 Clash 自己實作的使用者空間 Wireguard 用戶端效能更好。Wireguard 在核心中支援。