設定 · Clash文件

Outbound 出站

彙整原版 Clash 的 Shadowsocks、SSR、VMess、SOCKS5、HTTP、Snell 與 Trojan 出站格式,方便核對驗證、加密、TLS、UDP 和外掛欄位。

  • Shadowsocks
  • ShadowsocksR
  • VMess
  • Trojan
  • SOCKS5
設定

Clash 中有幾種類型的出站。每種類型都有自己的特點和使用情境。在本頁中,我們將介紹每種類型的通用特點以及如何使用和設定它們。

Proxies 代理節點

Proxies 代理節點是您可以設定的一些出站目標。就像代理伺服器一樣,您在這裡為資料包定義目的地。

Shadowsocks

Clash 支援以下 Shadowsocks 的加密方法:

系列加密方法
AEADaes-128-gcm, aes-192-gcm, aes-256-gcm, chacha20-ietf-poly1305, xchacha20-ietf-poly1305
串流aes-128-cfb, aes-192-cfb, aes-256-cfb, rc4-md5, chacha20-ietf, xchacha20
塊式aes-128-ctr, aes-192-ctr, aes-256-ctr

此外,Clash 也支援常用的 Shadowsocks 外掛程式 obfsv2ray-plugin

yaml
- name: "ss1"
  type: ss
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  cipher: chacha20-ietf-poly1305
  password: "password"
  # udp: true
yaml
- name: "ss2"
  type: ss
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  cipher: chacha20-ietf-poly1305
  password: "password"
  plugin: obfs
  plugin-opts:
    mode: tls # or http
    # host: bing.com
yaml
- name: "ss3"
  type: ss
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  cipher: chacha20-ietf-poly1305
  password: "password"
  plugin: v2ray-plugin
  plugin-opts:
    mode: websocket # 暂不支持 QUIC
    # tls: true # wss
    # skip-cert-verify: true
    # host: bing.com
    # path: "/"
    # mux: true
    # headers:
    #   custom: value

ShadowsocksR

Clash 也支援聲名狼藉的反審查協議 ShadowsocksR。

支援以下 ShadowsocksR 的加密方法:

系列加密方法
串流aes-128-cfb, aes-192-cfb, aes-256-cfb, rc4-md5, chacha20-ietf, xchacha20

支援的混淆方法:

  • plain
  • http_simple
  • http_post
  • random_head
  • tls1.2_ticket_auth
  • tls1.2_ticket_fastauth

支援的協議:

  • origin
  • auth_sha1_v4
  • auth_aes128_md5
  • auth_aes128_sha1
  • auth_chain_a
  • auth_chain_b
yaml
- name: "ssr"
  type: ssr
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  cipher: chacha20-ietf
  password: "password"
  obfs: tls1.2_ticket_auth
  protocol: auth_sha1_v4
  # obfs-param: domain.tld
  # protocol-param: "#"
  # udp: true

Vmess

Clash 支援以下 Vmess 的加密方法:

  • auto
  • aes-128-gcm
  • chacha20-poly1305
  • none
yaml
- name: "vmess"
  type: vmess
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  uuid: uuid
  alterId: 32
  cipher: auto
  # udp: true
  # tls: true
  # skip-cert-verify: true
  # servername: example.com # 优先于 wss 主机
  # network: ws
  # ws-opts:
  #   path: /path
  #   headers:
  #     Host: v2ray.com
  #   max-early-data: 2048
  #   early-data-header-name: Sec-WebSocket-Protocol
yaml
- name: "vmess-http"
  type: vmess
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  uuid: uuid
  alterId: 32
  cipher: auto
  # udp: true
  # network: http
  # http-opts:
  #   # method: "GET"
  #   # path:
  #   #   - '/'
  #   #   - '/video'
  #   # headers:
  #   #   Connection:
  #   #     - keep-alive
yaml
- name: "vmess-h2"
  type: vmess
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  uuid: uuid
  alterId: 32
  cipher: auto
  network: h2
  tls: true
  h2-opts:
    host:
      - http.example.com
      - http-alt.example.com
    path: /
yaml
- name: vmess-grpc
  type: vmess
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  uuid: uuid
  alterId: 32
  cipher: auto
  network: grpc
  tls: true
  servername: example.com
  # skip-cert-verify: true
  grpc-opts:
    grpc-service-name: "example"

Socks5

此外,Clash 還支援 Socks5 代理。

yaml
- name: "socks"
  type: socks5
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  # username: username
  # password: password
  # tls: true
  # skip-cert-verify: true
  # udp: true

HTTP

Clash 也支援 HTTP 代理:

yaml
- name: "http"
  type: http
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  # username: username
  # password: password
yaml
- name: "http"
  type: http
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  # username: username
  # password: password
  tls: true
  skip-cert-verify: true

Snell

作為可選的反審查協議,Clash 也整合了對 Snell 的支援。

yaml
# 暂不支持 UDP
- name: "snell"
  type: snell
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 44046
  psk: yourpsk
  # version: 2
  # obfs-opts:
    # mode: http # or tls
    # host: bing.com

Trojan

Clash 內建了對流行協議 Trojan 的支援:

yaml
- name: "trojan"
  type: trojan
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  password: yourpsk
  # udp: true
  # sni: example.com # aka server name
  # alpn:
  #   - h2
  #   - http/1.1
  # skip-cert-verify: true
yaml
- name: trojan-grpc
  type: trojan
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  password: "example"
  network: grpc
  sni: example.com
  # skip-cert-verify: true
  udp: true
  grpc-opts:
    grpc-service-name: "example"
yaml
- name: trojan-ws
  type: trojan
  # interface-name: eth0
  # routing-mark: 1234
  server: server
  port: 443
  password: "example"
  network: ws
  sni: example.com
  # skip-cert-verify: true
  udp: true
  # ws-opts:
    # path: /path
    # headers:
    #   Host: example.com

Proxy Groups 策略群組

Proxy Groups 策略群組用於根據不同策略分發規則傳遞過來的請求,其可以直接被規則引用,也可以被其他策略群組引用,而最上級策略群組被規則引用。

relay 中繼

請求將依序透過指定的代理伺服器進行中繼,目前不支援 UDP。指定的代理伺服器不應包含另一個 relay 中繼。

url-test 延遲測試

Clash 會定期透過清單中的各個代理伺服器,向指定 URL 傳送 HTTP HEAD 請求以測量延遲。您可以設定最大容許值、測試間隔與目標 URL。

fallback 可用性測試

Clash 會定期透過清單中的各個代理伺服器,向指定 URL 傳送 HTTP HEAD 請求以檢查可用性,並使用第一個可用的伺服器。

load-balance 負載均衡

相同 eTLD+1 的請求將使用同一個代理伺服器。

select 手動選擇

Clash 啟動時預設使用策略群組中的第一個代理伺服器。使用者可透過 RESTful API 選擇要使用的伺服器。在此模式下,可以在設定中直接寫入伺服器,或透過Proxy Providers 代理集動態新增。

無論採用哪種方式,有時也可以透過直接連線路由封包;此時可使用 DIRECT 直接連線出站。

若要使用不同的網路介面,請建立包含 DIRECT 直接連線出站的策略群組,並設定 interface-name 選項。

yaml
- name: "My Wireguard Outbound"
  type: select
  interface-name: wg0
  proxies: [ 'DIRECT' ]

Proxy Providers 代理集

代理集使使用者可以動態載入代理伺服器清單,而不是在設定檔中硬編碼。目前有兩種代理集可以載入伺服器清單:

  • http:Clash 啟動時會從指定 URL 載入伺服器清單。若設定 interval 選項,Clash 會定期從遠端更新清單。
  • file:Clash 啟動時會從指定的檔案位置載入伺服器清單。

兩種模式都可使用健康檢查,其行為與策略群組中的 fallback 完全相同。伺服器清單檔案也採用與主要設定檔相同的格式:

yaml
proxy-providers:
  provider1:
    type: http
    url: "url"
    interval: 3600
    path: ./provider1.yaml
    # filter: 'a|b' # golang regex 正则表达式
    health-check:
      enable: true
      interval: 600
      # lazy: true
      url: http://www.gstatic.com/generate_204
  test:
    type: file
    path: /test.yaml
    health-check:
      enable: true
      interval: 36000
      url: http://www.gstatic.com/generate_204
yaml
proxies:
  - name: "ss1"
    type: ss
    server: server
    port: 443
    cipher: chacha20-ietf-poly1305
    password: "password"

  - name: "ss2"
    type: ss
    server: server
    port: 443
    cipher: chacha20-ietf-poly1305
    password: "password"
    plugin: obfs
    plugin-opts:
      mode: tls