mihomo Core · Configuration Reference

Clash Advanced Configuration Guide

Follow each stage of a connection, from rule matching to outbound selection.

Routing Rules
rules
Outbound Selection
proxy-groups
DNS & Traffic Capture
dns / tun

If you haven’t imported a subscription and made your first connection yet, start with the getting started guide to create a working configuration and confirm that rule mode and the system proxy are working. This page is for what comes next: jump to the relevant section to find out which rule matched first, which upstream handled DNS, or what the core actually loaded after you saved an override.

These examples are for mihomo. If you’re choosing a client, check the download page for Clash Plus options on your platform, then make sure the client exposes the configuration settings used here. Each YAML snippet has its own scope; they are not seven files you can simply concatenate. Merge duplicate top-level keys instead of pasting them in twice. Save a copy of your working configuration before making changes so you can test one at a time.

Proxy Group Types and Routing in Practice

Trace a Rule Target to Its Outbound

The last field in a matching rule determines where the traffic goes. It can point to built-in options such as DIRECT or REJECT, or to a proxy node or group. Rules don’t choose a server within a group, and groups don’t decide which domains belong to them. If traffic takes the wrong route, check the matched rule in the connection log first, then check the group’s current selection. Changing both at once may fix the symptom, but it won’t show which layer caused the problem.

Use durable purpose-based names for proxy groups, such as “Primary” or “Backup,” rather than adding temporary node names to multiple rules. When a subscription changes, you then only need to update the group’s candidates. Group names, node names, and rule targets must match exactly, including spaces and capitalization. Groups can reference other groups, but keep dependencies one-way: if Group A references Group B and Group B points back to Group A, there’s no final outbound. As a configuration grows, tracing each rule target down to its actual outbound is more reliable than clicking through every option in the UI.

Manual Selection, Latency Testing, and Failover

Common proxy groups and how they select candidates
TypeSelection methodBest for
selectManual selection by the userPinning an outbound or reproducing a connection issue
url-testResponse time from the test URLChoosing a low-latency outbound from similar candidates
fallbackFirst available candidate in the listTrying candidates in primary-to-backup order
load-balanceSelecting candidates according to the configured balancing strategyDistributing new connections when changing outbounds is acceptable

With url-test, choose a lightweight url that every candidate can reach. interval is in seconds; tolerance is in milliseconds. A tolerance helps prevent switches caused by minor latency fluctuations. The test only measures responses from that URL; it doesn’t guarantee stable logins, uploads, or long-lived connections to the services you use. If you want to use a primary outbound and switch only when it becomes unavailable, use fallback with the primary listed first—not a group that frequently switches to chase the lowest test latency.

Load balancing doesn’t split a single download connection across multiple routes; it selects candidates for different connections. For sign-in flows that check for changes in your source IP, start with a manual group and pin the outbound before testing anything else. After changing a group selection, close existing connections and start a fresh test. Reused connections may keep their original outbound, so repeatedly refreshing the same page can lead to the wrong conclusion.

Test Rules and Groups Against the Same Domain

config.yaml
mode: rule
proxy-groups:
  - name: Manual Test
    type: select
    proxies:
      - DIRECT
      - REJECT
rules:
  - DOMAIN,example.com,Manual Test
  - MATCH,DIRECT

You can use this snippet to test routing without a subscription. First select DIRECT and visit the example domain. Then switch “Manual Test” to REJECT and retry with a new connection. Both attempts should match the same domain rule but use different outbounds. Next, visit a domain that doesn’t match that rule and confirm it reaches the final rule. If it still loads on the second attempt, rule out page caching and an existing connection, then confirm the request is going through the active core in rule mode.

Once you add real candidates, use proxies to reference defined nodes or groups, and use to reference a source declared in proxy-providers. Don’t mix the two. First check in the client that the source loaded and the group has candidates, then run a test. If the group is empty, check source loading and name filters. If every candidate times out, check your local network and test URL first, then test one candidate on its own. For a step-by-step approach, see what to check when all proxy nodes time out.

Catch-all rule: Put MATCH last. Remove temporary direct or reject rules added for testing from the production configuration when you’re done.

Manage Rules with Rule Providers

Separate Match Lists from Routing Decisions

rule-providers defines where rule sets come from, their format, and how they’re loaded. rules determines when those sets are checked and which outbound handles a match. Defining a provider earlier in the file doesn’t give its entries higher priority. If the same domain appears in both a team direct-access list and a general service list, the first matching entry in rules wins. Put exceptions before general rule sets to make precedence easier to follow than editing multiple sources.

Choose a rule-set type that matches its contents. Use domain for domain patterns, ipcidr for IP ranges, and classical for typed rules that combine conditions such as domains and IP addresses. Entries in a classical rule set don’t include an outbound; specify it once on the RULE-SET line that references the set. If you download a plain-text list but declare it as YAML, or treat classical entries as domain patterns, a file on disk doesn’t mean the rules loaded successfully.

Verify References with a Local Rule Set First

Merge the first snippet into your main configuration, then save the second in the ruleset subdirectory of the core’s working directory. A desktop client may use its own configuration directory, and the subscription file location shown in the UI may not be the base directory for the core’s relative paths. Start with the client’s configuration-directory shortcut and confirm the path in the logs. This helps avoid repeated load failures caused by saving files in the installation directory. If you already have rules, add only the reference line and keep your existing final rule.

config.yaml
rule-providers:
  sample-domains:
    type: file
    behavior: domain
    format: yaml
    path: ./ruleset/sample-domains.yaml
rules:
  - RULE-SET,sample-domains,DIRECT
  - MATCH,DIRECT
ruleset/sample-domains.yaml
payload:
  - '+.example.com'

In this example, both the rule-set entry and the catch-all use direct access, so a page loading doesn’t prove the rule set matched. Check the connection log to see whether the match was RULE-SET or MATCH, then compare it with a domain that isn’t in the set. If every request reaches the catch-all, first confirm the client reports that the set loaded, then check the domain the request actually used. The URL shown in the address bar, the final URL after redirects, and the domains used by background resources may all differ.

Remote Updates, Caching, and Failure Handling

After local testing succeeds, change the source to type: http, enter an HTTPS URL you’ve verified, and set the refresh interval in seconds with interval. Give each remote source its own path so you can identify its cache and check when it was updated. Rule sets aren’t proxy subscriptions: rule sets update match entries, while subscriptions update proxy candidates. Their URLs aren’t interchangeable. For frequently changing sets, note who maintains them, what they’re for, and which format they use so you won’t have to guess from a filename later.

When a remote update fails, distinguish a first-time download failure from an outdated cache. Check the load logs to see whether connections are using new content, old cached content, or a rule set that never became available. If only one source is affected, check that it returns the expected format and that its DNS and network route are working. Don’t temporarily route all traffic through an unrelated group just to get the update through; that can change how other rules behave and make the original issue harder to diagnose.

When investigating misrouting, also check whether evaluating a rule required a DNS lookup. Some IP-based rules may need the destination address resolved first. For rules that only need to match an existing address, use no-resolve where supported for that rule type to avoid an extra lookup just to determine whether it matches. If you only need to match a known domain, use an explicit domain rule. GeoIP and GeoSite data have their own loading and update mechanisms, separate from rule-set caching. See the GeoIP and GeoSite update guide for details.

DNS Configuration and Resolution Paths

Understand Default DNS, Policy Routing, and Proxy DNS

Before changing DNS, identify where the failure occurs. If an app can’t open a site, the domain may not have resolved—or it may have resolved successfully and the connection failed afterward. Check whether the same request produced a DNS result, then compare the selected outbound and connection error. After switching upstreams, account for browser, system, and core caches: a cached success can temporarily hide a problem, while an old failure can make a fix look ineffective.

nameserver specifies the upstream for ordinary queries. nameserver-policy sends queries for selected domains to specific resolvers. default-nameserver bootstraps the hostnames of DNS upstreams; it isn’t the preferred server for every query. If proxy endpoints use hostnames, use proxy-server-nameserver to handle proxy-node lookups separately. This makes it easier to tell whether a service domain failed to resolve or the core couldn’t resolve a proxy endpoint in the first place.

Keep Real Addresses First, Then Add DNS Policies

This snippet sends ordinary queries to one explicit upstream and queries for the example domain to another. It demonstrates how to assign resolvers; it isn’t a recommendation for their speed or suitability for your network. Both addresses are IPs, which helps rule out upstream hostname bootstrapping issues during initial testing. Configure internal domains separately to use a local resolver that can answer them; don’t send private names to the public resolvers in this example.

config.yaml
dns:
  enable: true
  enhanced-mode: redir-host
  default-nameserver:
    - 1.1.1.1
  nameserver:
    - 1.1.1.1
  nameserver-policy:
    '+.example.com':
      - 9.9.9.9

First confirm that both ordinary domains and policy-routed domains resolve, then add local exceptions or switch to encrypted upstreams. Test through the path you actually use: system lookup tools, browsers, and proxied apps may not use the same resolver. A browser using its own encrypted DNS may return different results from a command-line tool. If only one app behaves differently, check its DNS settings before changing the system-wide configuration.

The key difference between redir-host and fake-ip is the address returned to the app. The former typically returns a real address; the latter can return a mapped address associated with the domain. If an app needs real addresses for local discovery, diagnostics, or connection checks, add exceptions for the domains it actually uses rather than excluding entire categories of ordinary services. See TUN & Fake-IP for configuration and testing details.

Solve DNS Bootstrap Before Routing DNS Queries

With respect-rules enabled, connections to DNS upstreams are also handled by routing rules. Configure proxy-server-nameserver and make sure it has a working route before the proxy is established. A common loop occurs when reaching a DNS upstream requires the proxy, but resolving the proxy endpoint requires that same upstream. The result may be repeated timeouts as soon as the core starts, rather than one website loading slowly now and then. Start troubleshooting with a simple working path, then add upstream routing one step at a time.

Before switching upstreams, note one public domain that resolves, one known internal hostname, and whether your network actually supports IPv6. Test each again after the change to distinguish external DNS, internal naming, and address-family issues. Don’t compare only whether the returned IPs are identical: results for the same domain can vary by resolver location or cache age. Instead, confirm that queries go where expected and that the app selects a usable address and outbound when it connects.

Check both paths: A web connection going through a proxy doesn’t mean its DNS queries use the same route. Use the DNS leak test and configuration guide to check app behavior, DNS upstreams, and traffic capture separately.

TUN Traffic Capture and Fake-IP Mapping

Decide Whether to Capture System Traffic

The system proxy relies on apps reading the proxy settings, so it’s a good place to start with browsers and other compatible programs. TUN creates a virtual network interface and sends routed traffic to the core, making it useful for apps that ignore system proxy settings. Traffic captured by TUN still uses the current mode and rules to select an outbound; enabling TUN doesn’t automatically proxy every connection. If a program already works through the system proxy, keep it as a control and test TUN with a different app that doesn’t read the system proxy settings.

Before you start, make sure the client has permission to create a virtual interface and modify routes, and close other clients that might compete to capture traffic. After enabling TUN, check that the virtual interface was created and that your existing default network route still works. On managed devices, use only the VPN and routing settings permitted by the device administrator. If capture fails, don’t simultaneously change proxy groups, DNS upstreams, and the local firewall. Find the first error in permissions, service status, or route conflicts instead.

Capture Common DNS Requests First, Then Check the Limits

config.yaml
tun:
  enable: true
  stack: mixed
  auto-route: true
  auto-detect-interface: true
  dns-hijack:
    - 'any:53'
    - 'tcp://any:53'
dns:
  enable: true
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - '+.home.arpa'
  nameserver:
    - 1.1.1.1

auto-route lets the core set up TUN routes, while auto-detect-interface helps select the outbound interface. When both wired and wireless connections are available, after waking from sleep, or when switching hotspots, the default interface may change; repeat your connectivity checks. stack controls protocol handling on the virtual interface. The core offers options such as system, gvisor, and mixed. If you run into compatibility issues, change this setting on its own while leaving the rest of the configuration unchanged. Some clients generate or override these fields, so check the configuration that’s actually running.

This dns-hijack example handles DNS queries entering TUN, along with eligible UDP and TCP traffic on port 53. It won’t automatically convert an app’s encrypted DNS connection into a regular query, and it can’t capture traffic that never enters the virtual interface. Test system lookups and in-app lookups separately. If the former works as expected but the latter doesn’t, check the app’s DNS settings and actual route rather than blindly expanding the capture scope.

Where Fake-IP Mapping Fits—and How to Roll It Back Safely

Think of a Fake-IP address as a temporary address the core gives an app while keeping a domain-to-address mapping. When the app connects to that address, the core uses the mapped domain to evaluate rules and select an outbound. Seeing an address from the example range doesn’t mean DNS failed; what matters is whether the subsequent connection returns to the same core. If DNS goes through the core but another routing path handles the connection, the mapping can’t be restored at the right point. Check the DNS query, a new connection, and its matching log entry together.

fake-ip-filter makes selected domains resolve to real addresses, but it doesn’t configure a resolver for internal domains. If you use the example home.arpa, also point it to a local upstream in your DNS policy. If printers, file sharing, or similar services stop working, test both the hostname and a known IP address. If the IP works but the name doesn’t, check DNS. If the IP itself is unreachable, check routing and whether the app is being captured. Add exceptions only for names you’ve confirmed need them so you don’t lose domain information across an entire rule range.

To roll back, first disable TUN in the client and confirm that its virtual routes have been removed. If you tested Fake-IP, close apps that may still be reusing mapped addresses and, if needed, flush the local DNS cache. Then restore your previously working system proxy setup. Verify basic connectivity before restoring overrides. If the desktop client exits soon after launch, follow the client startup troubleshooting guide to check the logs and distinguish route permissions, configuration syntax, and port conflicts.

Domain Sniffing and Matching Limits

When the Core Sees an IP Address First

Some apps pass an already resolved destination address to the connection layer, so the core initially sees only an IP address and port. Sniffing attempts to recover a hostname from the start of a connection, such as an HTTP Host header or a server name visible in a TLS handshake. With that information, a connection that would otherwise match only an IP rule or the catch-all may be able to use a more specific domain rule. Sniffing doesn’t decrypt application data or replace DNS; if DNS itself is unavailable, enabling sniffing won’t fix the lookup.

Whether a hostname can be recovered depends on the protocol, handshake contents, and capture path. Apps that connect directly to IP addresses, devices using custom protocols, and handshakes that hide the server name may not give the core enough information. A single IP can serve many domains, so you can’t infer a unique site from an address alone. If no hostname is available, keeping sensible IP rules or a catch-all is usually more controllable than continually widening the sniffing scope.

Enable Sniffing Gradually by Protocol and Port

config.yaml
sniffer:
  enable: true
  force-dns-mapping: false
  parse-pure-ip: true
  override-destination: false
  sniff:
    HTTP:
      ports: [80, 8080]
    TLS:
      ports: [443, 8443]
  skip-domain:
    - '+.home.arpa'

This example covers only HTTP and TLS on the specified ports. First test parse-pure-ip with a connection that currently has no hostname information, and leave override-destination disabled to minimize changes to the original destination. The latter controls whether sniffed results can rewrite the connection destination; it isn’t the same as allowing domain rules to use sniffed names. force-dns-mapping enables additional sniffing for DNS-mapped traffic. If existing mappings route reliably, you usually don’t need it for your first test.

If the issue only affects apps using QUIC, compare with a client that can explicitly use TCP. Then, if supported by your core, add QUIC and the required ports to sniff. Adding a sniffing protocol won’t help if UDP traffic isn’t being captured. If you’re unsure which port the app uses, check a connection entry before editing the configuration. Testing a broad range of unrelated ports adds variables and can make a slow handshake look like a general network slowdown.

Check the Actual Match and Keep LAN Exceptions

Before and after enabling sniffing, open a new connection to the same domain in the same app. Record the original destination, whether a hostname appeared, the matching rule, and the final outbound. If the dashboard shows a domain but not where it came from, don’t assume sniffing supplied it; the app may have provided the name or it may come from DNS mapping. Repeat the test with sniffing disabled to confirm whether this setting actually changed routing.

LAN devices, services at fixed addresses, and diagnostic tools often rely on the original destination. If only these connections fail after enabling sniffing, check whether they fall within its scope. skip-domain works for exceptions with known hostnames, but it can’t identify a target that provides no hostname information. For services accessed only by IP, narrow the port range or, after checking core support, add an exception by destination network. Once connectivity is restored, decide whether other services still need sniffing.

A hostname can also be recovered correctly while traffic still takes the wrong outbound. In that case, go back to rule order and check whether an earlier rule set matched first or the configuration is in global mode. If multiple sources could match a domain, test with one precise temporary rule, then restore the rule set you maintain long term. Keep logs to the relevant troubleshooting entries, and remove internal domains, device addresses, and subscription details before sharing them. If you need to review the basic modes, see the mode selection section of the getting started guide.

Local Overrides and Merging Multiple Subscriptions

Source Subscription, Overrides, and the Runtime Configuration

A source subscription is what the upstream provides; a local override is what you want to keep; and the runtime configuration is what the core ultimately reads. Clients may show these in different places. Editing a cached subscription directly often means losing changes at the next update. If the client provides an override feature, use it for local rules, proxy groups, and DNS exceptions. If it doesn’t show the merged result, check the active configuration and load logs rather than relying on a “saved” message in an editor.

Override syntax is client-specific; mihomo doesn’t define one universal format. Some tools insert list items at the beginning, while others replace an entire section. For example, if you only want to add an exception to rules but the tool replaces the whole array, existing rules may disappear. Likewise, a new rule appended after an existing MATCH will never run. Compare item counts, the final catch-all, and group references before and after applying changes. To review top-level sections, see the config.yaml structure guide.

Combine Candidates by Source Name, Not by Concatenating Configs

To combine multiple proxy sources, each source must provide a node file that mihomo can read. Declare each one under proxy-providers, then use use in a local proxy group to include its candidates. This example uses two local files: place both in the core’s working directory, and make sure each contains a proxies list with valid node configurations. This snippet doesn’t include nodes or read subscriptions open in the client’s tabs. Load it only after both files are ready.

proxy-providers:
  main-source:
    type: file
    path: ./providers/main.yaml
  spare-source:
    type: file
    path: ./providers/spare.yaml
proxy-groups:
  - name: Combined Outbound
    type: select
    use:
      - main-source
      - spare-source
    proxies:
      - DIRECT

If you already have proxy-groups, merge only the “Combined Outbound” group into the existing list, then update the rules that should use it to reference that group. Keeping direct access available for testing can help distinguish a source issue from a main configuration issue. For services that must use a controlled outbound, however, don’t leave a direct-access option in the production group where it could be selected by mistake. Don’t concatenate complete subscriptions that include ports, rules, and DNS settings. Choose one base configuration, extract only the nodes you need, or use a merge method supported by your client.

When switching to HTTP sources, use a separate cache path for each one. Subscription URLs may contain account credentials, so keep them only in a controlled local configuration—not in shared documents, screenshots, or diagnostic logs. If sources contain nodes with the same name, use a naming option supported by your client, then check which candidates actually appear and which one is selected. If you filter by name, make the criteria clear; an upstream naming change could otherwise remove every candidate from the group.

Test the Updated Configuration, Not Just the First Load

Enable one source first and confirm that it loads and provides at least one usable candidate. Then add the second source. In rule mode, test a connection that clearly points to the combined group and check both the matched rule and outbound. Next, refresh one source manually and make sure the override is still applied, the list wasn’t replaced wholesale, and the previous manual selection still points to an existing node. Problems that appear only after an update often come from renamed nodes, failed cache loads, or a change in the client’s merge order.

Roll back in two steps: disable the local override and confirm the base subscription still works, then revert your independent changes one at a time—rules first, DNS next, for example. Don’t change subscriptions and core settings in the same reload. Keep at least one verified working copy of any configuration you rely on, and note which client and use case it’s for. If you’re migrating, first follow the subscription import steps in the new client to establish a basic connection, then move over the local settings you’ve tested.

Local Dashboard and Connection Troubleshooting

Distinguish Proxy Ports, the Control API, and the Dashboard

The proxy listener port handles app traffic. external-controller provides a status and control API. A desktop client’s built-in dashboard may already be connected to the core, so there may be no need to open another port. A browser dashboard is just the interface for the control API: opening a static page doesn’t mean it’s connected to the core, and a working control API doesn’t mean app traffic is being proxied. When something fails, identify which path is affected first; don’t enter the system proxy address as the control address.

For local use only, bind the control API to a loopback address and set a separate key that stays on your device. A desktop client may manage its own control address and key, so check its settings before making changes. Proxy-side allow-lan and the control API bind address are separate settings; disabling the former doesn’t restrict the latter. Dashboards can switch proxy groups and manage connections, so don’t expose the control port to the public internet or let untrusted web pages use it.

Verify the Local Listener and Authentication

config.yaml
external-controller: 127.0.0.1:9090
secret: "example-only-not-a-real-secret"

The example key only illustrates the field format. Replace it with a long random value generated on your device before saving and enabling the setting. The example port may also be in use by another process. Before reloading, check that the client doesn’t have a separate management port configured. After reloading, confirm in the logs that the listener started successfully. You can make the request below from your device to check the response without putting your real key in shell history. Assuming this address and port belong to the current core and the key is active, a request to the version endpoint without credentials should return an unauthorized response.

curl -i --noproxy 127.0.0.1 http://127.0.0.1:9090/version

If the connection is refused, look for signs that the listener failed, the process isn’t running, or the configured port doesn’t match. An unauthorized response means the request reached a service that requires authentication; check the control address and credentials configured in the client. If you get a page from another app, check which process owns the port. For browser errors involving cross-origin requests or mixed content, use a trusted local dashboard or the client’s built-in UI instead of relaxing origin restrictions so any web page can connect.

Follow One New Connection to Verify the Configuration

Once the dashboard connects, leave only the app you want to test open and start a new request. First check whether the request appears at all: if there’s no entry, check the app’s network path, system proxy, or TUN. If it appears, inspect the matched rule and connection chain. If it reaches the catch-all, check the target hostname, rule order, and rule-set loading. If the group is right but the outbound isn’t, check the manual selection, health checks, and current candidates. If the outbound is correct but the request still times out, investigate DNS results and connection errors. Change one setting at a time so you can compare the logs.

The connection list may also show background requests generated by your browser. Don’t assume every entry came from the test you just ran. Compare the destination, source app, or connection time. A site may use separate domains for sign-in, static assets, and APIs. If the homepage loads but sign-in fails, inspect those requests individually instead of copying a successful entry. For empty connection lists, common port issues, and differences between modes, see the FAQ.

When you’re done, restore your usual log level and disable any temporary control API or test rules. If you need to keep a record, note the mode, expected rule, actual outbound, and steps to reproduce the issue. Remove internal addresses, full subscription URLs, keys, and personal connection details before sharing it. This makes the next check easier and helps prevent temporary test settings from being left in your production configuration.

Control access: A dashboard is a configuration interface, not a read-only status page. If you don’t need an external dashboard, use the client’s built-in controls to avoid opening another listener port that you’ll need to manage.