Before continuing with this section, we recommend reading Introduction. Once you have a basic understanding of how Clash works, you can start writing your own configuration.
Configuration file
The main configuration file is named config.yaml. By default, Clash reads it from the $HOME/.config/clash directory. If that directory does not exist, Clash generates a minimal configuration file there.
To keep the configuration file elsewhere, such as /etc/clash, use the -d command-line option to specify its directory:
clash -d . # current directory
clash -d /etc/clashAlternatively, use the -f option to specify the configuration file:
clash -f ./config.yaml
clash -f /etc/clash/config.yamlSpecial syntax
Clash configuration files use some special syntax you may need to know:
IPv6 addresses
Enclose IPv6 addresses in square brackets ([]), for example:
[aaaa::a8aa:ff:fe09:57d8]Wildcard domain matching in DNS
In some cases, you need to match wildcard domains. For example, when configuring Clash DNS, you may want to match every subdomain of localdomain.
Clash DNS configuration supports wildcard domain matching at different levels using the following syntax:
TIP
Any domain containing these characters must be enclosed in single quotes ('); for example, '*.google.com'. Exact domains take precedence over wildcard domains (foo.example.com > *.example.com > .example.com).
Use an asterisk (*) to match a single-level wildcard subdomain.
| Expression | Matches | Does not match |
|---|---|---|
*.google.com | www.google.com | google.com |
*.bar.google.com | foo.bar.google.com | bar.google.com |
*.*.google.com | thoughtful.sandbox.google.com | one.two.three.google.com |
Use a leading dot (.) to match wildcard subdomains at multiple levels.
| Expression | Matches | Does not match |
|---|---|---|
.google.com | www.google.com | google.com |
.google.com | thoughtful.sandbox.google.com | google.com |
.google.com | one.two.three.google.com | google.com |
Use a plus sign (+) to match wildcard subdomains at multiple levels.
+ wildcards work like DOMAIN-SUFFIX, allowing fast matching across multiple levels at once.
| Expression | Matches |
|---|---|
+.google.com | google.com |
+.google.com | www.google.com |
+.google.com | thoughtful.sandbox.google.com |
+.google.com | one.two.three.google.com |
