Configuration · Clash documentation

Configuration Quick Start

Learn the default config.yaml location, the -d and -f startup options, IPv6 bracket notation, and quoting and precedence rules for DNS wildcard matching.

  • config.yaml
  • -d
  • -f
  • IPv6
  • DOMAIN-SUFFIX
Configuration

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:

shell
clash -d . # current directory
clash -d /etc/clash

Alternatively, use the -f option to specify the configuration file:

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

Special syntax

Clash configuration files use some special syntax you may need to know:

IPv6 addresses

Enclose IPv6 addresses in square brackets ([]), for example:

txt
[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.

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 a leading dot (.) to match wildcard subdomains at multiple levels.

ExpressionMatchesDoes not match
.google.comwww.google.comgoogle.com
.google.comthoughtful.sandbox.google.comgoogle.com
.google.comone.two.three.google.comgoogle.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.

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