Are you an LLM? You can read better optimized documentation at /zh-TW\tutorial\configuration-reference.md for this page in Markdown format
參考配置
推薦工具
手搓總有錯誤時, 工具解放左手
clash/mihomo 官方參考配置
- yaml案例及配置可參考 快捷配置 - 虛空終端 Docs
- yaml語法 MetaCubeX/mihomo 配置語法
參考yaml
yaml
# HTTP(S) 代理服務端口
port: 7890
# SOCKS5 代理服務端口
socks-port: 7891
# Linux 和 macOS 的透明代理服務端口 (TCP 和 TProxy UDP 重定向)
# redir-port: 7892
# Linux 的透明代理服務端口 (TProxy TCP 和 TProxy UDP)
# tproxy-port: 7893
# HTTP(S) 和 SOCKS4(A)/SOCKS5 代理服務共用一個端口
# mixed-port: 7890
# 本地 SOCKS5/HTTP(S) 代理服務的認證
# authentication:
# - "user1:pass1"
# - "user2:pass2"
# 設置為 true 以允許來自其他 LAN IP 地址的連接
# allow-lan: false
# 僅當 `allow-lan` 為 `true` 時有效
# '*': 綁定所有 IP 地址
# 192.168.122.11: 綁定單個 IPv4 地址
# "[aaaa::a8aa:ff:fe09:57d8]": 綁定單個 IPv6 地址
# bind-address: '*'
# Clash 路由工作模式
# rule: 基於規則的數據包路由
# global: 所有數據包將被轉發到單個節點
# direct: 直接將數據包轉發到互聯網
mode: rule
# 默認情況下, Clash 將日誌打印到 STDOUT
# 日誌級別: info / warning / error / debug / silent
# log-level: info
# 當設置為 false 時, 解析器不會將主機名解析為 IPv6 地址
# ipv6: false
# RESTful Web API 監聽地址
external-controller: 127.0.0.1:9090
# 配置目錄的相對路徑或靜態 Web 資源目錄的絕對路徑. Clash core 將在
# `http://{{external-controller}}/ui` 中提供服務.
# external-ui: folder
# RESTful API 密鑰 (可選)
# 通過指定 HTTP 頭 `Authorization: Bearer ${secret}` 進行身份驗證
# 如果RESTful API在 0.0.0.0 上監聽, 務必設置一個 secret 密鑰.
# secret: ""
# 出站接口名稱
# interface-name: en0
# fwmark (僅在 Linux 上有效)
# routing-mark: 6666
# 用於DNS服務器和連接建立的靜態主機 (如/etc/hosts) .
#
# 支持通配符主機名 (例如 *.clash.dev, *.foo.*.example.com)
# 非通配符域名優先級高於通配符域名
# 例如 foo.example.com > *.example.com > .example.com
# P.S. +.foo.com 等於 .foo.com 和 foo.com
# hosts:
# '*.clash.dev': 127.0.0.1
# '.dev': 127.0.0.1
# 'alpha.clash.dev': '::1'
# profile:
# 將 `select` 手動選擇 結果存儲在 $HOME/.config/clash/.cache 中
# 如果不需要此行為, 請設置為 false
# 當兩個不同的配置具有同名的組時, 將共享所選值
# store-selected: true
# 持久化 fakeip
# store-fake-ip: false
# DNS 服務設置
# 此部分是可選的. 當不存在時, DNS 服務將被禁用.
dns:
enable: false
listen: 0.0.0.0:53
# ipv6: false # 當為 false 時, AAAA 查詢的響應將為空
# 這些 名稱服務器(nameservers) 用於解析下列 DNS 名稱服務器主機名.
# 僅指定 IP 地址
default-nameserver:
- 114.114.114.114
- 8.8.8.8
# enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16 # Fake IP 地址池 CIDR
# use-hosts: true # 查找 hosts 並返回 IP 記錄
# search-domains: [local] # A/AAAA 記錄的搜索域
# 此列表中的主機名將不會使用 Fake IP 解析
# 即, 對這些域名的請求將始終使用其真實 IP 地址進行響應
# fake-ip-filter:
# - '*.lan'
# - localhost.ptlogin2.qq.com
# 支持 UDP、TCP、DoT、DoH. 您可以指定要連接的端口.
# 所有 DNS 查詢都直接發送到名稱服務器, 無需代理
# Clash 使用第一個收到的響應作為 DNS 查詢的結果.
nameserver:
- 114.114.114.114 # 默認值
- 8.8.8.8 # 默認值
- tls://dns.rubyfish.cn:853 # DNS over TLS
- https://1.1.1.1/dns-query # DNS over HTTPS
- dhcp://en0 # 來自 dhcp 的 dns
# - '8.8.8.8#en0'
# 當 `fallback` 存在時, DNS 服務器將向此部分中的服務器
# 與 `nameservers` 中的服務器發送併發請求
# 當 GEOIP 國家不是 `CN` 時, 將使用 fallback 服務器的響應
# fallback:
# - tcp://1.1.1.1
# - 'tcp://1.1.1.1#en0'
# 如果使用 `nameservers` 解析的 IP 地址在下面指定的子網中,
# 則認為它們無效, 並使用 `fallback` 服務器的結果.
#
# 當 `fallback-filter.geoip` 為 true 且 IP 地址的 GEOIP 為 `CN` 時,
# 將使用 `nameservers` 服務器解析的 IP 地址.
#
# 如果 `fallback-filter.geoip` 為 false, 且不匹配 `fallback-filter.ipcidr`,
# 則始終使用 `nameservers` 服務器的結果
#
# 這是對抗 DNS 汙染攻擊的一種措施.
# fallback-filter:
# geoip: true
# geoip-code: CN
# ipcidr:
# - 240.0.0.0/4
# domain:
# - '+.google.com'
# - '+.facebook.com'
# - '+.youtube.com'
# 通過特定的名稱服務器查找域名
# nameserver-policy:
# 'www.baidu.com': '114.114.114.114'
# '+.internal.crop.com': '10.0.0.1'
proxies:
# Shadowsocks
# 支持的加密方法:
# aes-128-gcm aes-192-gcm aes-256-gcm
# aes-128-cfb aes-192-cfb aes-256-cfb
# aes-128-ctr aes-192-ctr aes-256-ctr
# rc4-md5 chacha20-ietf xchacha20
# chacha20-ietf-poly1305 xchacha20-ietf-poly1305
- name: "ss1"
type: ss
server: server
port: 443
cipher: chacha20-ietf-poly1305
password: "password"
# udp: true
- name: "ss2"
type: ss
server: server
port: 443
cipher: chacha20-ietf-poly1305
password: "password"
plugin: obfs
plugin-opts:
mode: tls # or http
# host: bing.com
- name: "ss3"
type: ss
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
# vmess
# 支持的加密方法:
# auto/aes-128-gcm/chacha20-poly1305/none
- name: "vmess"
type: vmess
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
- name: "vmess-h2"
type: vmess
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: /
- name: "vmess-http"
type: vmess
server: server
port: 443
uuid: uuid
alterId: 32
cipher: auto
# udp: true
# network: http
# http-opts:
# # method: "GET"
# # path:
# # - '/'
# # - '/video'
# # headers:
# # Connection:
# # - keep-alive
- name: vmess-grpc
server: server
port: 443
type: vmess
uuid: uuid
alterId: 32
cipher: auto
network: grpc
tls: true
servername: example.com
# skip-cert-verify: true
grpc-opts:
grpc-service-name: "example"
# socks5
- name: "socks"
type: socks5
server: server
port: 443
# username: username
# password: password
# tls: true
# skip-cert-verify: true
# udp: true
# http
- name: "http"
type: http
server: server
port: 443
# username: username
# password: password
# tls: true # https
# skip-cert-verify: true
# sni: custom.com
# Snell
# 請注意, 目前還沒有UDP支持.
- name: "snell"
type: snell
server: server
port: 44046
psk: yourpsk
# version: 2
# obfs-opts:
# mode: http # or tls
# host: bing.com
# Trojan
- name: "trojan"
type: trojan
server: server
port: 443
password: yourpsk
# udp: true
# sni: example.com # aka 服務器名稱
# alpn:
# - h2
# - http/1.1
# skip-cert-verify: true
- name: trojan-grpc
server: server
port: 443
type: trojan
password: "example"
network: grpc
sni: example.com
# skip-cert-verify: true
udp: true
grpc-opts:
grpc-service-name: "example"
- name: trojan-ws
server: server
port: 443
type: trojan
password: "example"
network: ws
sni: example.com
# skip-cert-verify: true
udp: true
# ws-opts:
# path: /path
# headers:
# Host: example.com
# ShadowsocksR
# 支持的加密方法: ss 中的所有流加密方法
# 支持的混淆方式:
# 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
- name: "ssr"
type: ssr
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
proxy-groups:
# 中繼鏈路代理節點. 節點不應包含中繼. 不支持 UDP.
# 流量節點鏈路: clash <-> http <-> vmess <-> ss1 <-> ss2 <-> Internet
- name: "relay"
type: relay
proxies:
- http
- vmess
- ss1
- ss2
# url-test 通過對 指定URL 進行基準速度測試來選擇將使用哪個代理.
- name: "auto"
type: url-test
proxies:
- ss1
- ss2
- vmess1
# tolerance: 150
# lazy: true
url: 'http://www.gstatic.com/generate_204'
interval: 300
# fallback-auto 基於優先級選擇可用策略. 可用性通過訪問 指定URL 來測試, 就像自動 url-test 組一樣.
- name: "fallback-auto"
type: fallback
proxies:
- ss1
- ss2
- vmess1
url: 'http://www.gstatic.com/generate_204'
interval: 300
# 負載均衡: 同一 eTLD+1 的請求將撥號到同一代理.
- name: "load-balance"
type: load-balance
proxies:
- ss1
- ss2
- vmess1
url: 'http://www.gstatic.com/generate_204'
interval: 300
# strategy: consistent-hashing # or round-robin
# select 手動選擇, 用於選擇代理或策略組
# 您可以使用 RESTful API 來切換代理, 建議在GUI中切換.
- name: Proxy
type: select
# disable-udp: true
# filter: 'someregex'
proxies:
- ss1
- ss2
- vmess1
- auto
# 直接連接到另一個接口名稱或 fwmark, 也支持代理
- name: en1
type: select
interface-name: en1
routing-mark: 6667
proxies:
- DIRECT
- name: UseProvider
type: select
use:
- provider1
proxies:
- Proxy
- DIRECT
proxy-providers:
provider1:
type: http
url: "url"
interval: 3600
path: ./provider1.yaml
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
tunnels:
# 單行配置
- tcp/udp,127.0.0.1:6553,114.114.114.114:53,proxy
- tcp,127.0.0.1:6666,rds.mysql.com:3306,vpn
# 全 yaml 配置
- network: [tcp, udp]
address: 127.0.0.1:7777
target: target.com
proxy: proxy
rules:
- DOMAIN-SUFFIX,google.com,auto
- DOMAIN-KEYWORD,google,auto
- DOMAIN,google.com,auto
- DOMAIN-SUFFIX,ad.com,REJECT
- SRC-IP-CIDR,192.168.1.201/32,DIRECT
# 用於 IP 規則 (GEOIP, IP-CIDR, IP-CIDR6) 的可選參數 "no-resolve"
- IP-CIDR,127.0.0.0/8,DIRECT
- GEOIP,CN,DIRECT
- DST-PORT,80,DIRECT
- SRC-PORT,7777,DIRECT
- RULE-SET,apple,REJECT # 僅 Premium 版本支持
- MATCH,auto