Clash MiClash Mi
  • 🏠 首页Home
  • 📖 介绍Intro
  • ⬇️ 下载Download
  • 📖 教程Docs
  • 🚀 机场推荐Airport
导航Navigation
  • 🏠 首页Home
  • 📖 介绍Intro
  • ⬇️ 下载Download
  • 📖 教程Tutorial
  • 🚀 机场推荐Airport
  • Clash 工作原理How Clash Works
  • 快速入手Quick Start
  • Inbound 入站Inbound
  • Outbound 出站Outbound
  • Rules 规则Rules
  • Clash DNSClash DNS
  • 配置参考Config Reference
  • 外部控制设置External Controller
  • 在线面板Web Panel
  • RESTful APIRESTful API
  • ShadowsocksShadowsocks
  • SnellSnell
  • SOCKS5SOCKS5
  • TCPTCP
  • TProxyTProxy
  • TrojanTrojan
  • UDPUDP
  • VMessVMess
  • WireGuardWireGuard

快速入手 ​

建议您在继续阅读本节之前,先阅读介绍。在您对 Clash 的工作原理有了简单的了解后,您可以开始编写您自己的配置。

配置文件 ​

主配置文件名为 config.yaml。默认情况下,Clash 会在 $HOME/.config/clash 目录读取配置文件。如果该目录不存在,Clash 会在该位置生成一个最小的配置文件。

如果您想将配置文件放在其他地方(例如 /etc/clash),您可以使用命令行选项 -d 来指定配置目录:

clash -d .
clash -d /etc/clash

或者,您可以使用选项 -f 来指定配置文件:

clash -f ./config.yaml
clash -f /etc/clash/config.yaml

特殊语法 ​

Clash 配置文件中有一些特殊的语法,您可能需要了解:

IPv6 地址 ​

您应该使用方括号([])来包裹 IPv6 地址,例如:

[aaaa::a8aa:ff:fe09:57d8]

DNS 通配符域名匹配 ​

在某些情况下,您需要匹配通配符域名。例如,当您设置 Clash DNS 时,您可能想要匹配 localdomain 的所有子域名。

Clash 在 DNS 配置中提供了匹配不同级别通配符域名的支持,其语法如下:

任何包含这些字符的域名都应该用单引号(')包裹。例如,'*.google.com'。静态域名的优先级高于通配符域名(foo.example.com > *.example.com > .example.com)。

使用星号(*)来匹配单级通配符子域名:

表达式匹配不匹配
*.google.comwww.google.comgoogle.com
*.bar.google.comfoo.bar.google.combar.google.com
*.*.google.comthoughtful.sandbox.google.comone.two.three.google.com

使用点号(.)来匹配多级通配符子域名:

表达式匹配不匹配
.google.comwww.google.comgoogle.com
.google.comthoughtful.sandbox.google.comgoogle.com
.google.comone.two.three.google.comgoogle.com

使用加号(+)来匹配多级通配符子域名:

+ 通配符的工作方式类似于 DOMAIN-SUFFIX,您可以一次进行多级的快速匹配:

表达式匹配
+.google.comgoogle.com
+.google.comwww.google.com
+.google.comthoughtful.sandbox.google.com
+.google.comone.two.three.google.com

Quick Start ​

Before continuing, we recommend reading Introduction. Once you understand how Clash works, you can start writing your own configuration.

Configuration File ​

The main configuration file is named config.yaml. By default, Clash reads the config file from $HOME/.config/clash. If the directory does not exist, Clash will generate a minimal config file there.

If you want to put the config file elsewhere (e.g. /etc/clash), you can use the -d option:

clash -d .
clash -d /etc/clash

Or use the -f option to specify the config file:

clash -f ./config.yaml
clash -f /etc/clash/config.yaml

Special Syntax ​

There are some special syntax in Clash configuration file you may need to know:

IPv6 Address ​

You should use brackets ([]) to wrap IPv6 addresses, for example:

[aaaa::a8aa:ff:fe09:57d8]

DNS Wildcard Domain Matching ​

In some cases you need to match wildcard domains. For example, when you configure Clash DNS, you may want to match all subdomains of localdomain.

Clash provides support for matching different levels of wildcard domains in DNS configuration:

Any domain containing these characters should be wrapped with single quotes ('), e.g. '*.google.com'. Static domains have higher priority than wildcards (foo.example.com > *.example.com > .example.com).

Use asterisk (*) to match single-level wildcard subdomains:

ExpressionMatchesDoes not match
*.google.comwww.google.comgoogle.com
*.bar.google.comfoo.bar.google.combar.google.com
*.*.google.comthoughtful.sandbox.google.comone.two.three.google.com

Use dot (.) to match multi-level wildcard subdomains:

ExpressionMatchesDoes not match
.google.comwww.google.comgoogle.com
.google.comthoughtful.sandbox.google.comgoogle.com
.google.comone.two.three.google.comgoogle.com

Use plus (+) to match multi-level wildcard subdomains:

The + wildcard works similar to DOMAIN-SUFFIX, you can quickly match multiple levels at once:

ExpressionMatches
+.google.comgoogle.com
+.google.comwww.google.com
+.google.comthoughtful.sandbox.google.com
+.google.comone.two.three.google.com

© 2026 Clash Mi · 首页 · 文档中心 · 机场推荐