Advanced Guides · mihomo Configuration Reference

Clash Advanced Configuration Guide

Start with the Getting Started guide to import your config, choose a rule mode, and verify your first connection. Then use this page to find the fields you want to adjust. The examples in its seven chapters cover different parts of a configuration; they are not meant to be combined into one config from top to bottom. Change one part at a time and keep a copy of the configuration that connects successfully, so you can tell what to roll back if something goes wrong.

1. Proxy Group Types and Choosing an Exit

Routing involves two consecutive decisions: a rule determines which proxy group handles a connection, then the group determines which exit to use. Keeping these decisions separate explains why changing a selection on the Proxies page may not affect an app that still uses its previous route. Set the core to rule mode, check the logs to see which rule matched the connection, then open the Proxies page and confirm which exit that rule’s group currently selects. A highlighted selection alone doesn’t prove the connection passed through that group. Existing connections may also keep their original exit, so test with a new connection.

Set up a manual choice before adding automatic routing

select works well as a stable manual entry point—for example, to set a default exit for everyday browsing while keeping a direct-connection option handy. url-test compares candidates by testing them against a specified URL, making it useful for choosing among similar exits. The tolerance value, in milliseconds, can reduce frequent switching when test results are close. A test only reflects access to that URL at that time; it doesn’t measure download throughput, video quality, or whether a particular service is reachable. If the test URL or path is unavailable, every candidate may report an error. That doesn’t mean all your routes are down.

TypeHow it selectsBest for
selectUser-selectedA fixed everyday exit or side-by-side troubleshooting
url-testSelects based on test resultsAutomatic selection among similar candidates
fallbackSelects the first available candidate in orderSetting an explicit primary and backup order
load-balanceDistributes connections according to the configured strategyCases where connections can use different exits

Verify group references with two rules

This example uses the built-in direct and reject policies to demonstrate group references without relying on external routes. To test it on its own, switch the client to rule mode, set the target to direct, and open the example site. Then switch to reject and start a new connection. The same rule should still match the same group, but the outcome will change. Use reject only for this comparison. In an existing config, put the test rule before broader rules and keep the original final catch-all. Don’t append a second catch-all.

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

Set backup order according to your needs

Use fallback when you need a fixed priority: list candidates from primary to backup and set an appropriate test interval. It chooses the next option when the preferred one is unavailable; it doesn’t migrate established sessions. If the primary comes back, don’t use whether an existing download switches immediately as your test. Consider load-balance when you need to distribute concurrent connections; it won’t split a single download across multiple exits. For logins or business services that depend on a stable source address, use a separate manual group rather than sharing a load-balanced group with ordinary stateless requests. Each automatic group can also increase the number of tests the client runs, so avoid adding groups that don’t serve a purpose.

Check for empty groups, circular references, and stale selections

When one proxy group references another, map the path from the entry point to the final exit to avoid circular references. Group names must match the targets in rules exactly. If a subscription supplies the candidates, check that a filter expression hasn’t excluded them all. If the selection shown after an update differs from what you expect, first check whether the client remembered the previous choice, then see if candidate names changed during the update. Display order doesn’t indicate priority—don’t infer primary and backup behavior from the order shown in the UI. If an automatic group looks fine but only one site has trouble, keep the same rule and test the site with a manual group: if that fails too, check the exit and destination; if only the automatic group fails, check its test URL, options, and switching behavior.

2. Managing Rule Providers

Rule providers are useful for maintaining a changing set of destinations. For just a few long-term exceptions, local rules are often easier to review. rule-providers defines the source, format, and storage location; a RULE-SET entry in rules is what brings that source into routing. Downloading a file or seeing a set’s name in the client doesn’t mean a connection will match it. Rules are evaluated in order, so a broader rule earlier in the list can catch a connection before a later set gets a chance to match. Treat source updates and rule order as separate things to check.

File format and matching behavior are separate settings

format specifies how to read the file; behavior specifies how to interpret its entries. With yaml, rule sets commonly use payload as the entry point. For text or binary sets, use the format actually published and supported by your core—don’t guess from the file extension. Use domain for domain sets, ipcidr for IP ranges, and classical for rule expressions such as DOMAIN and DOMAIN-SUFFIX. Set entries describe match conditions; specify the proxy group on the outer RULE-SET rule. Moving a full rule that includes a policy name from the main config into a set doesn’t migrate it correctly.

Create a local file as a test case

Save the first snippet below as rulesets/local-sites.yaml in the core’s configuration directory, creating the folder if needed. A GUI client’s config directory may not be its download folder; check the client’s config management page. The second snippet references that file. The final direct rule is only a sample fallback—keep the policies in your actual config. Temporarily change this set’s exit to reject, then test domains inside and outside the set. That’s more reliable than guessing at match order with several remote sources enabled. When done, restore direct and verify again with a new connection.

payload:
  - DOMAIN,example.com
  - DOMAIN-SUFFIX,example.net
rule-providers:
  local-sites:
    type: file
    behavior: classical
    format: yaml
    path: ./rulesets/local-sites.yaml
rules:
  - RULE-SET,local-sites,DIRECT
  - MATCH,DIRECT

Manage update intervals and caching when switching to a remote source

To use a rule set URL provided by a service, change the source to http, add url, and set interval in seconds. Give each source its own cache path; sharing one file between sets makes update results hard to trace. A set that changes infrequently can be checked daily—there’s no need to compensate for a bad URL with an extremely short interval. Treat the initial load and later refreshes separately: if there’s no local file yet, an unavailable URL or network means there’s no previous content to fall back on. If a later refresh fails, first check whether the client still has the cached version loaded; don’t test by deleting the file. To see whether remote content changed, keep a known-good local copy, compare its contents and modification time, and then decide whether to restore it.

Check rule order first, then distinguish domains from IP ranges

Put exceptions before the broader set they need to override, and keep MATCH at the end. If a set stops matching, first confirm that the current config is loaded, then check the first rule that actually matched in the logs. If a connection arrives with only an IP address, a domain set has no domain to match; adding more suffixes won’t help. IP range rules also involve different resolution behavior: if you don’t want to resolve a hostname just to evaluate a rule, consider no-resolve on applicable IP rules, but be aware that a rule may not match without a destination IP. Geodata and remote custom sets use different update mechanisms, so updating geodata won’t tell you whether a rule provider is working. For definitions, see the rules and routing sections of the glossary.

3. DNS Resolution Paths and Configuration

When troubleshooting DNS, identify who sends the query, who receives it, and which upstream handles it. Enabling dns.enable only means the core can process queries it receives; the system resolver, browser encrypted DNS, and domains received through a proxy may not follow the same path. A site opening in one browser doesn’t prove other apps use the same resolver. Instead of changing system settings and core upstreams at the same time, test a repeatable domain and check the logs to see whether the core receives the query. Then compare results from different upstreams. A browser may reuse an existing connection and skip a new DNS query.

Separate default DNS, proxy-node DNS, and per-domain upstreams

nameserver configures upstreams for regular queries. default-nameserver is mainly used to resolve the hostnames of upstream DNS servers; use addresses that can be reached directly where possible. It isn’t the first stop for every query. proxy-server-nameserver handles DNS for proxy server hostnames, making that startup dependency explicit. If regular upstreams are reached through a proxy, the proxy server itself must be resolvable and reachable first—otherwise you end up needing a proxy to resolve the proxy’s address. To send company intranet domains to a specific upstream, use nameserver-policy with the relevant domain suffixes. Avoid routing all queries through an office resolver, which may be unreachable when the device leaves the corporate network.

Start with a baseline using real IP addresses

The example below sets up a redir-host DNS test listener for local use only. It doesn’t change the system resolver or force the browser to use it. On a device with dig, query the listener port directly. The example upstream must be reachable from your local network; if it isn’t, use an upstream approved by your network administrator. First check the address records, then test an app connection to the same domain. If the lookup succeeds but the connection fails, investigate the connection stage rather than continuing to switch resolvers. Keep this config before trying Fake-IP so you can compare the two.

dns:
  enable: true
  listen: 127.0.0.1:1053
  enhanced-mode: redir-host
  default-nameserver:
    - 223.5.5.5
  nameserver:
    - 223.5.5.5
dig @127.0.0.1 -p 1053 example.com A

Decide whether you really need a second set of upstreams

fallback doesn’t simply mean “query the backup only if the primary times out.” Used with fallback-filter, it also filters results. Adding several upstreams without checking how they work can produce different answers for the same hostname depending on network location, and make troubleshooting harder. First determine whether the lookup failed, returned an unexpected answer, or returned the right answer but the connection still failed. Add filters for specific domains or IP ranges only when result filtering is actually needed. Encrypted DNS protects the connection to the upstream; it doesn’t automatically route every app through that upstream or change how the server selects a nearby IP. For details on the fields, see the DNS configuration guide.

Check address families, caches, and routing dependencies

An A-record lookup alone won’t explain an app that prefers IPv6. Check AAAA records too, confirm the system has a route for the returned address, and see which address the app actually chose. A successful lookup doesn’t mean every returned address is reachable. After changing upstreams, test with a new connection and account for caches in the system, app, and core; refreshing a browser page may reuse its existing connection. If respect-rules makes DNS upstream connections follow routing rules, configure a separate resolution path for proxy hostnames and check which rule the upstream itself matches. If it works at home but fails on another network, first check whether that network can reach the relevant address, port, and protocol. Don’t blame config syntax without evidence.

4. TUN Traffic Routing and Fake-IP Mapping

TUN controls how app traffic enters the core; Fake-IP controls how DNS answers map back to the original domain. They’re often used together, but they’re separate features. The system proxy relies on apps honoring the system’s proxy settings. TUN routes eligible traffic through a virtual interface, which can let apps that ignore the system proxy reach the core—as long as their traffic actually passes through that interface. Enabling TUN doesn’t automatically route every system component or existing virtual network the same way. Troubleshoot in this order: verify the interface and routes, check the DNS path, then inspect rule matches. Reversing that order can make a traffic-capture problem look like a proxy-node failure.

Verify permissions and routing on each platform

Keep a configuration that connects successfully, turn off unrelated system proxy settings and other traffic-capture tools, then enable TUN by itself. Desktop clients may use a system service to configure the virtual interface and routes. On Linux, also check permissions, virtual device availability, and the current routing table. Mobile clients typically connect through the system VPN feature; permissions and compatibility restrictions depend on the OS and client, so desktop steps don’t apply. On any platform, the client’s TUN toggle doesn’t prove that routes are active. Start a fresh test connection, look for a corresponding log entry, and compare the same app’s behavior with system proxy mode.

Apply TUN and address mapping in two stages

The snippets below are for a local environment where the core can manage interfaces and routes. Keep the redir-host config from chapter 3, add only the tun section, and verify that regular connections still work. stack: mixed is a starting point for testing, not the only choice on every platform. The dns-hijack example targets ordinary UDP DNS requests passing through this interface. It doesn’t intercept HTTPS-encrypted queries or guarantee that every local system resolution path is captured. To handle regular TCP DNS through TUN, configure it separately according to the client’s support. Don’t switch mapping modes until traffic routing and the DNS path are working.

tun:
  enable: true
  stack: mixed
  auto-route: true
  auto-detect-interface: true
  dns-hijack:
    - any:53

Once traffic capture is confirmed, merge the following fields into the existing dns section; don’t add a second top-level key with the same name. DNS queries return synthetic addresses assigned by the core. Later connections must pass back through the core holding the mapping so it can recover the original domain and apply domain rules. If a synthetic address leaves through another interface, the connection won’t work. First check that the address range doesn’t conflict with existing routes; office networks, VMs, and test networks may already use a similar range.

dns:
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - '+.local'

Use the smallest rollback needed for LAN exceptions

If an intranet service depends on real IP addresses, add narrowly scoped exceptions based on the symptoms instead of bypassing an entire range by default. If a synthetic address causes an app to fail, consider adding the specific domain suffix to the Fake-IP filter. If the address is correct but printer traffic is still routed through the virtual interface, check route exclusions rather than broadening the domain exception. The filter above only affects Fake-IP responses; it doesn’t provide multicast discovery. If devices rely on LAN discovery, separately confirm they’re on the same network and that the system allows that type of traffic. Test access by IP and by hostname separately.

Stop troubleshooting in a reversible order

If all internet access stops after enabling TUN, first turn off the client’s TUN setting and confirm that the virtual routes have been removed. Then restore the previous DNS mode and start a new test connection. An app may cache a synthetic address, so it might keep sending requests to the old address after TUN is off. Fully quit and reopen the affected app; that’s more useful than repeatedly refreshing the same page. Save the routing state and client logs from before and after traffic capture. They’re more useful than a note saying “everything stopped working.” If the local gateway is unreachable even with TUN disabled, restore the system network baseline before changing proxy group selections.

5. When to Use Domain Sniffing

Domain sniffing is useful when the core receives a connection but only has its destination IP address. It attempts to identify a domain from supported protocol metadata, giving domain rules something to match. It doesn’t replace DNS or fix traffic that never reaches the core. Before enabling it, capture a connection you can reproduce reliably: check whether the logs already show a domain, whether the connection matched an IP rule or the final catch-all, and which protocol and port it uses. If the logs already show the correct domain rule and the problem is that the exit can’t connect, sniffing won’t fix the route.

Check whether the protocol exposes a domain

For ordinary HTTP, the domain may be available in the request’s host information. For common TLS connections, the core may be able to read the server name from the handshake. QUIC is a separate case: using a familiar secure-web port doesn’t mean it’s covered by TLS sniffing settings. An app may connect directly to an IP, reuse an existing connection, or use a handshake that hides the server name; in those cases, no domain result is expected. The hostname shown in an app and the server name sent with the underlying connection may also differ, especially with shared connections or multi-tenant hosting. Don’t assume a sniffed domain identifies every page request on that connection.

Limit sniffing to justified ports and preserve the original destination

Start with common web ports. Don’t expand to a wide range unless you know other protocols are compatible. The example asks the core to sniff connections that have only an IP address and use the result for matching, while leaving the original destination address unchanged. After enabling it, make two new connections to the same test service using the same DNS and proxy group, then compare the matched rules. If a domain appears in the logs but the exit doesn’t change, an earlier, broader rule may be matching first. If the logs already showed a domain, sniffing may not explain the difference. Keeping the original destination also helps distinguish a change in rule matching from a change in the actual connection target.

sniffer:
  enable: true
  force-dns-mapping: false
  parse-pure-ip: true
  override-destination: false
  sniff:
    HTTP:
      ports: [80, 8080]
    TLS:
      ports: [443]
    QUIC:
      ports: [443]

Distinguish re-sniffing, exclusions, and destination overrides

force-dns-mapping expands sniffing to traffic with a domain learned from DNS mapping; you don’t need it when testing IP-only connections. If you need to handle a specific domain, consider force-domain. For domains you have evidence are being misidentified, consider skip-domain. If you have a clearly defined IP range, check whether the core supports an address exclusion field. Domain exclusions require a name the core can identify; adding a domain entry doesn’t automatically exclude an entire service accessed by IP. override-destination changes the destination used for subsequent routing based on the sniffed result—it’s not just a display option in the logs. Keep it off for internal apps that depend on fixed addresses, then test it separately if needed.

Turn inconsistent results into reproducible test records

If the same site sometimes matches a domain group and sometimes an IP group, compare the two requests’ entry points, transport protocols, address families, and whether each used a new connection. A browser switching protocols or an app choosing a different address family can send seemingly identical visits down different paths. To reproduce the issue, fully quit the test app and start two new sessions, recording each one without changing DNS or rules between tests. If only one domain is affected, add a narrow exclusion and check the logs to ensure other domains still behave as expected. If the issue only appears after widening the port range, revert to the original ports. Raise the log level only long enough to capture one test round, then restore it. Remove internal hostnames and sensitive addresses before sharing the logs.

6. Local Overrides and Multiple Subscriptions

Keep subscription content, device preferences, and temporary troubleshooting changes separate. The upstream subscription supplies server information; local overrides hold long-term preferences; experimental changes belong in a separate config. Editing a file generated from a subscription directly may be undone at the next update. Changing the same field in both the UI and YAML also makes it hard to tell which layer takes effect. GUI clients differ in override formats and merge order, so a merge directive from one client isn’t universal mihomo syntax. Check what the core actually receives rather than relying on what the editor saved. To reuse settings across devices, see our multi-device config sync guide.

Confirm the merge behavior in your client

Start with an easy-to-observe test—for example, change only the log level, apply it, restart the client, and see if it persists. Then refresh the subscription and check again. A simple field persisting doesn’t mean lists merge the same way. Mappings may merge key by key, while lists may be replaced in full. Changing just one rules entry or one proxy-groups item could remove every other entry. If the client can show the effective config, compare it before and after the change. In particular, check that other DNS fields and the final catch-all rule are still there. If there’s no effective-config view, verify using connection logs and the available group selections instead of drawing conclusions from a preview.

Let the core load proxy lists by source

If a source provides a file containing a proxies list, you can load it with separate proxy-providers entries and reference them through a group’s use field. The example requires local files obtained from authorized sources, stored in separate paths under the core’s config directory. Each file must contain a proxy list the core can parse—not a client subscription URL as plain text. If a service only provides a complete config with its own DNS and rules, don’t assume you can reference it as a proxy list and merge all its settings. First confirm which formats the source supports, or export the proxies through a method supported by the client.

proxy-providers:
  source-a:
    type: file
    path: ./providers/source-a.yaml
  source-b:
    type: file
    path: ./providers/source-b.yaml
proxy-groups:
  - name: Source A
    type: select
    use:
      - source-a
  - name: Source B
    type: select
    use:
      - source-b
  - name: Egress
    type: select
    proxies:
      - Source A
      - Source B
      - DIRECT

Plan for name conflicts and update failures

Give each source its own group name where possible. During troubleshooting, you can then identify the source from the outer group instead of guessing based on duplicate proxy names. Avoid conflicts between group names, built-in policy names, and custom exit names. If an existing rule points directly to a proxy name, a rename during a source update will break that reference; it’s usually more reliable to point rules to a stable group name. Use a separate cache and update interval for each remote source. After updating a group, check that it still has candidates and that the previously selected option is still available. If one source fails, keep the other available for comparison rather than reimporting every subscription at once. If you temporarily remove a failed source, also remove any downstream references to it.

Save recoverable states, not just one oversized config

Change notes should at least identify the base config, loaded sources, active override layer, and the connection used to verify the result. Keep a recent working copy of your local overrides. For large changes, validate rules, groups, and DNS separately so you can identify which layer broke connectivity. When investigating a port conflict, check whether another instance is still running; rolling back a config won’t free a port held by another process. Subscription URLs may contain usable access credentials, so don’t expose them in screenshots, logs, or synced files. If you’re new to Clash and hit an import error, port conflict, or connection loss, start with the 10 questions new Clash users ask rather than trying to work around basic problems by merging subscriptions.

7. External Controller and Local Access

The controller lets you inspect and manage a running core; it doesn’t route web traffic. external-controller is the controller’s listening address. mixed-port is the proxy port apps use. They aren’t interchangeable. A working proxy port doesn’t mean the controller is running, and a panel showing connections doesn’t mean the system proxy is enabled. Prefer a loopback address for access from your own device. Even with allow-lan disabled, check the controller’s listening address separately—it doesn’t control the controller’s access scope.

Verify the listener before loading a local dashboard

The example binds the controller to the local machine and serves the dashboard from the dashboard directory in the config folder. Before using it, add static files from a trusted dashboard release and confirm the entry file is in the specified directory, not nested one folder deeper after extraction. GUI clients may manage the controller themselves; check the current port before changing anything, and don’t let multiple core instances compete for the same address. The sample password only shows where the field goes. Replace it with a unique, strong random value before applying the config. Don’t reuse subscription credentials or store the real value in public notes, shareable dashboard URLs, or command history.

external-controller: 127.0.0.1:9090
>secret: "demo-only-change-before-use"
external-ui: dashboard

After applying the config, open http://127.0.0.1:9090/ui/ in a local browser to view the static dashboard. If it asks for the controller address, use the same local port and enter the configured password in the dashboard’s authentication field. Loading the page assets and authenticating with the API are two separate checks. If the interface loads but proxy groups don’t appear, check authentication and the API address; don’t clear the password to troubleshoot. If the browser itself uses a proxy, make sure loopback requests stay local rather than going through a proxy exit.

Use the symptoms to check the port, directory, or authentication

SymptomCheck firstHow to verify
Connection refusedListening address, port, and process statusCheck the client startup logs and look for a port conflict
Dashboard path not foundStatic directory and entry fileConfirm the actual config directory and check for an extra nested folder
API returns unauthorizedPassword and the dashboard’s saved authentication settingsConfirm you’re connected to the intended instance, then enter the credentials again
Dashboard loads, but the browser blocks requestsPage origin and API originOpen the local dashboard from the same loopback address and port first

Cross-origin deployments add browser origin restrictions, mixed-content policies, and network reachability to the troubleshooting list. On the same device, prefer a local dashboard served from the same origin as the API to reduce variables. Don’t allow every origin or bind the listener to the entire network. A loopback address inside a container belongs to the container, not the host. If the connection fails, first check where the service is running and how its ports are mapped. If you need remote administration, use a private management channel and access controls approved by your team. Don’t expose the core’s controller port directly. The controller can change runtime state, including group selections; it’s not just a read-only status page.

Use the dashboard to collect evidence, then restore normal settings

To investigate a failed connection, note when it happened and choose a repeatable test. Check the connection view for its entry point, destination, matched rule, and exit; then check the logs to see where it failed. A screenshot of proxy group latency alone doesn’t show whether the destination site connected. A group selection changed in the dashboard may be remembered by the client, but distinguish that runtime choice from what the config file defines. To keep a rule working after updates, edit the config layer that maintains it. After troubleshooting, restore temporary group selections and log levels, and close any extra dashboard access you no longer need. Remove subscription URLs, controller passwords, internal hosts, and full connection logs before sharing.

Download Clash