ClashX設定ファイル完全解析:YAML設定を深く理解する

ClashX configuration guide cover

設定の概要

ClashXはYAMLフォーマットの設定ファイルを使用して、すべてのプロキシ動作を定義します。各設定項目の構造と機能を理解することが、ClashXをマスターする鍵です。

設定ファイルは通常~/.config/clash/config.yamlにあり、サブスクリプションリンクを介して自動更新することもできます。この記事では、設定ファイルの各部分を詳細に分析し、ニーズに最適な設定を作成するのに役立てます。

💡
YAMLフォーマットのポイント

YAMLはインデントに非常に敏感で、インデントにはスペース(タブではなく)を使用する必要があります。1レベルのインデントには2スペースを推奨します。

基本構造

完全なClashX設定ファイルは主に以下のセクションで構成されます:

基本設定ファイル構造

# General settings
port: 7890
socks-port: 7891
allow-lan: false
mode: rule
log-level: info

# Proxy Nodes
proxies:
  - name: "Node 1"
    type: ss
    server: example.com
    port: 443

# Proxy groups
proxy-groups:
  - name: "🚀 Node Selection"
    type: select
    proxies:
      - "Node 1"

# Rules
rules:
  - DOMAIN-SUFFIX,google.com,🚀 Node Selection
  - GEOIP,CN,DIRECT
  - MATCH,🚀 Node Selection

一般設定

一般設定はClashXの基本動作とパフォーマンスパラメータを制御します。

ポート設定

# HTTP proxy port
port: 7890

# SOCKS5 proxy port
socks-port: 7891

# Mixed port (supports HTTP and SOCKS5 at the same time)
mixed-port: 7892

# RESTful API port
external-controller: 127.0.0.1:9090

# API access secret (optional)
secret: "your-secret-key"

ネットワーク設定

# Allow Local Network connections
allow-lan: false

# Bind address (used with Local Network)
bind-address: "*"

# Running mode: rule (Rules) / global (Global) / direct (Direct)
mode: rule

# Log level: silent / error / warning / info / debug
log-level: info

# IPv6 support
ipv6: true

DNS設定

DNS設定はドメイン名解決の速度と正確性に影響します:

dns:
  enable: true
  listen: 0.0.0.0:53
  enhanced-mode: fake-ip  # or redir-host

  # Fake-IP address pool
  fake-ip-range: 198.18.0.1/16

  # Fake-IP filter (these domains do not use Fake-IP)
  fake-ip-filter:
    - "*.lan"
    - "localhost.ptlogin2.qq.com"

  # DNS server
  nameserver:
    - 119.29.29.29
    - 223.5.5.5
    - https://doh.pub/dns-query

  # Fallback DNS (used when the primary DNS fails)
  fallback:
    - https://1.1.1.1/dns-query
    - https://dns.google/dns-query

  # Select DNS by domain
  nameserver-policy:
    "geosite:cn":
      - 119.29.29.29
      - 223.5.5.5
    "geosite:geolocation-!cn":
      - https://1.1.1.1/dns-query
⚠️
DNSモードの選択

fake-ip: Better performance, but may be incompatible with some applications
redir-host: Good compatibility, but slightly slower

プロキシ設定(Proxies)

proxiesセクションでは、すべての利用可能なプロキシサーバーノードを定義します。ClashXは複数のプロキシプロトコルをサポートしています。

Shadowsocks (SS)

proxies:
  - name: "Shadowsocks nodes"
    type: ss
    server: example.com
    port: 443
    cipher: aes-256-gcm
    password: "your-password"
    udp: true

ShadowsocksR (SSR)

  - name: "ShadowsocksR nodes"
    type: ssr
    server: example.com
    port: 443
    cipher: aes-256-cfb
    password: "your-password"
    protocol: auth_aes128_md5
    protocol-param: ""
    obfs: tls1.2_ticket_auth
    obfs-param: "cloudflare.com"

VMess

  - name: "VMess nodes"
    type: vmess
    server: example.com
    port: 443
    uuid: b831381d-6324-4d53-ad4f-8cda48b30811
    alterId: 0
    cipher: auto
    tls: true
    skip-cert-verify: false
    servername: example.com
    network: ws
    ws-opts:
      path: /path
      headers:
        Host: example.com

Trojan

  - name: "Trojan nodes"
    type: trojan
    server: example.com
    port: 443
    password: "your-password"
    sni: example.com
    skip-cert-verify: false
    udp: true

HTTP/HTTPS Proxy

  - name: "HTTP proxy"
    type: http
    server: example.com
    port: 8080
    username: user
    password: pass
    tls: true
    skip-cert-verify: false

プロキシグループ設定

プロキシグループを使用すると、複数のノードを組み合わせて、自動選択やロードバランシングなどの高度な機能を実現できます。

select - 手動選択

ユーザーが使用するノードを手動で選択します:

proxy-groups:
  - name: "🚀 Node Selection"
    type: select
    proxies:
      - "🇭🇰 Hong Kong Node"
      - "🇯🇵 Japan Node"
      - "🇺🇸 US Node"
      - DIRECT

url-test - 自動速度テスト

遅延が最も低いノードを自動的に選択します:

  - name: "♻️ Auto Select"
    type: url-test
    proxies:
      - "Node 1"
      - "Node 2"
      - "Node 3"
    url: "http://www.gstatic.com/generate_204"
    interval: 300    # Test interval (seconds)
    tolerance: 50    # Tolerance (milliseconds)

fallback - フェイルオーバー

プライマリノードが障害した場合、自動的にバックアップノードに切り替えます:

  - name: "🔰 Failover"
    type: fallback
    proxies:
      - "primary node"
      - "backup node1"
      - "backup node2"
    url: "http://www.gstatic.com/generate_204"
    interval: 300

load-balance - ロードバランシング

複数のノード間でトラフィックを分散します:

  - name: "⚖️ Load Balancing"
    type: load-balance
    proxies:
      - "Node 1"
      - "Node 2"
      - "Node 3"
    url: "http://www.gstatic.com/generate_204"
    interval: 300
    strategy: consistent-hashing  # or round-robin

relay - チェーンプロキシ

トラフィックが複数のプロキシノードを経由します:

  - name: "🔗 chained proxy"
    type: relay
    proxies:
      - "Node 1"
      - "Node 2"
💡
プロキシグループのベストプラクティス

• Create different proxy groups for different purposes (e.g., streaming, gaming, downloads)
• Use url-test for automatic optimization
• Include url-test groups as options in select groups

ルール設定

ルールはどのトラフィックがプロキシを経由し、どれが直接接続するかを決定します。ルールは上から下に照合され、マッチすると照合を停止します。

完全なルール例

rules:
  # Local NetworkDirect
  - DOMAIN-SUFFIX,local,DIRECT
  - IP-CIDR,127.0.0.0/8,DIRECT
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - IP-CIDR,10.0.0.0/8,DIRECT,no-resolve

  # Block ads
  - DOMAIN-KEYWORD,adservice,REJECT
  - DOMAIN-SUFFIX,doubleclick.net,REJECT

  # Streaming
  - DOMAIN-SUFFIX,youtube.com,🎬 Streaming
  - DOMAIN-SUFFIX,netflix.com,🎬 Streaming
  - DOMAIN-KEYWORD,spotify,🎬 Streaming

  # Apple Services
  - DOMAIN-SUFFIX,apple.com,🍎 Apple Services
  - DOMAIN-SUFFIX,icloud.com,🍎 Apple Services

  # Google Services
  - DOMAIN-SUFFIX,google.com,🚀 Proxy
  - DOMAIN-SUFFIX,googleapis.com,🚀 Proxy
  - DOMAIN-SUFFIX,gstatic.com,🚀 Proxy

  # CN websitesDirect
  - GEOIP,CN,DIRECT

  # FinalRules
  - MATCH,🚀 Proxy

ルール優先度の推奨

1. LAN
最高優先度
2. ブロックルール
REJECT
3. 特別なサービス
動画、ゲームなど
4. 地理的位置
GEOIPルール
5. デフォルトポリシー
MATCH

詳細設定オプション

ルールプロバイダー

外部ファイルからルールを読み込むことで、メンテナンスと更新が容易になります:

rule-providers:
  reject:
    type: http
    behavior: domain
    url: "https://cdn.example.com/reject.yaml"
    path: ./ruleset/reject.yaml
    interval: 86400

  proxy:
    type: http
    behavior: domain
    url: "https://cdn.example.com/proxy.yaml"
    path: ./ruleset/proxy.yaml
    interval: 86400

rules:
  - RULE-SET,reject,REJECT
  - RULE-SET,proxy,🚀 Proxy

TUNモード

システムレベルのプロキシ、アプリケーションの設定が不要:

tun:
  enable: true
  stack: system  # or gvisor
  dns-hijack:
    - any:53
  auto-route: true
  auto-detect-interface: true

実験的機能

experimental:
  # Ignore domains that fail to resolve
  ignore-resolve-fail: true

  # Interface name detection
  interface-name: en0
⚠️
重要な注意事項

• TUN mode requires administrator privileges
• Configuration changes need to be reloaded to take effect
• Recommended to validate configuration in test environment first