Advanced Usage · Configuration Reference

mihomo Advanced Configuration Guide

Check seven parts of the configuration that actually runs: rules determine which group handles a connection, groups determine the exit, and resolution and traffic capture determine what the core can see.

The user guide covers initial import, connection, and verification. This page assumes you already have a working connection and focuses on tuning fields, checking behavior, and tracking regressions. If you haven't installed a client yet, start with the downloads page for Clash Plus platform support on desktop and mobile. See its FAQ for package and architecture issues. The examples here are for mihomo configuration; whether a GUI client can override a field depends on what it actually loads.

Proxy Group Types in Practice

Separate Exit Selection from Rule Matching

First decide which exits a type of connection can use, then decide how to choose among them. Routing rules are checked from top to bottom; the first match sends the connection to its target, which can be a built-in direct action or a proxy group. Changing a proxy group changes the selection within that group—it does not send a matched connection back through the rule list. If traffic takes the wrong route, check the matched rule in the connection details first, then inspect the group's exit. Don't infer whether a rule is correct from the proxy name currently shown.

For everyday use, keep one manual group for sessions that need a fixed region or identity, and create a separate automatic group for general traffic that doesn't need a fixed exit. Both groups should offer candidates suited to their intended use. For example, don't mix several regions in an automatic group for a service that requires a consistent exit. Even when both candidates work, frequent exit changes can trigger repeated sign-ins. For these use cases, stability matters more than probe results.

Group Types and Switching Behavior

TypeSelection behaviorUse case
selectSelected by the user or control panelFixed exit; side-by-side troubleshooting
url-testRoutes based on probe results; configurable switching toleranceChoose the best candidate for the same purpose
fallbackPrefer the first available candidate in the listPrimary and backup routes with a defined priority
load-balanceDistributes different connections among candidates according to a policyConcurrent connections that don't require a fixed exit

Automatic probes measure how a candidate performs against a test address. They don't measure download bandwidth or prove that a particular service is reachable. Choose a stable test address with a small response body that the candidate can actually reach. For automatic groups, tolerance is measured in milliseconds and prevents small differences from triggering a switch; interval is measured in seconds, and setting it too low increases probe traffic. In a fallback group, candidate order determines priority: a faster backup doesn't automatically take precedence over the primary.

A Manual Group You Can Test in Isolation

Start with built-in actions to check references between rules and proxy groups, so line issues don't complicate the first test. This example routes only a rule for a reserved test domain; all other requests remain direct. The manual group explicitly places direct first. Change the selection in the client, then start a new connection. This snippet demonstrates how selection works; it is not a recommendation to use direct as the fallback for a production proxy group.

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

To adapt this example for real routing, fill proxies with node names already in your configuration, or use use to reference a defined proxy provider. Names must match exactly; use distinct naming conventions for nodes and groups. Groups can reference other groups, but business-facing groups should point one way to lower-level exit groups to avoid circular references. Before deployment, make sure each automatic group has at least one suitable candidate. Don't fill every business group with the same unchecked catch-all group.

Verify Switching and Persistence

First note the matched rule and current exit in the connection details, then change the group's selection. For the test, close the existing connection or restart the app: browser connection pools, persistent connections, and long-lived sessions may keep using the old exit. If a new connection still takes the old route, confirm that the client is in rule mode and that the test connection actually matched the intended group. Don't change rule order, group selection, and the system proxy toggle in one test. Even if things start working again, you won't know which change fixed it.

With profile.store-selected enabled, a previous manual selection may be restored after reload, so the first candidate may not be the one currently in use. Don't assume that other devices using the same group share its runtime state. Validate in two stages: first, check that a new connection uses the selected exit; then restart and confirm which selection is loaded. For a comparison of latency, region, and traffic multipliers, see how to choose Clash nodes.

Manage Rule Sets as Subscriptions

Keep Rule Sources Separate from Routing Actions

A rule set answers “which targets belong in this category?” The main configuration answers “which exit should this category use?” Register the source under rule-providers, reference it with RULE-SET in the main rule list, and specify the policy there. This lets you change exits without editing source files, or update domains and network ranges without reordering the main rules. Organize rule sets by purpose rather than size—for example, manage internal services, local testing, and general traffic separately.

Check the provider’s behavior and format first. The former defines what the entries mean: domain for domain entries, ipcidr for IP ranges, and classical for entries that include rule types. The latter defines how to read the file: plain text and YAML with payload are not interchangeable, and binary formats should follow the upstream specification. File extensions are only a clue; check the source documentation or inspect the file structure.

Verify the Reference with a Local File First

Create rules/local-domains.yaml in mihomo's working directory. A core launched by a GUI client may use a separate working directory, not the folder containing the current configuration file. If you get a path error, check the runtime directory shown by the client, then check system permissions. The examples below show two levels of reference using reserved example domains. The first snippet is part of the main configuration; the second is the rule set file. They cannot be pasted together at the root of one file.

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

When visiting a test subdomain, the specific domain rule should match first. For the example root domain, check the connection details to confirm the match came from the rule set. Don't use “the site loads” as your only validation: a final fallback rule might produce the same action. If the detailed match shows the fallback, check whether the provider loaded, then verify the entry format and domain. For domain entries in classical, include the rule type and target; don't copy over the third field from a main rule, which specifies the exit.

Remote Updates Don't Automatically Mean Safe Rollouts

After local validation, you can switch the source type to http, set the url to a trusted source, assign each provider its own writable cache path, and set interval in seconds. Don't have two providers write to the same file. Initial loading requires all three: an accessible upstream, a writable path, and a parseable response. Opening the URL in a browser doesn't prove that the core can fetch it during startup using the same resolution and outbound route.

Before updating, record the source URL, purpose, current entry scope, and local exceptions. After updating, test two kinds of samples: targets that should match and nearby targets that must not. The latter are especially useful for catching a sudden expansion in rule set scope. For business-critical rules, don't change the policy group name at the same time as switching upstreams. Keep a readable copy of the previous rule file, and practice switching back to the local provider during a maintenance window to confirm rollback doesn't depend on the remote server.

Order, Resolution, and Missing-Rule Fallbacks

A target can match multiple sets, but priority is still determined by position in the main rule list. Put narrow exceptions before broader rules and keep the fallback last. IP-based matching may trigger a lookup if the connection's destination address isn't available yet. To avoid an extra lookup for a rule where that's appropriate, use no-resolve on the IP-based match. This doesn't prevent matching an address that's already available, nor does it disable DNS resolution for the connection as a whole.

Optimize DNS Configuration

Choose Resolution Paths by Query Type

Start by separating three kinds of names: regular website domains, domains used by proxy nodes, and hostnames in encrypted DNS service addresses. Regular queries use nameserver or a matching nameserver-policy; node domains can be resolved separately with proxy-server-nameserver. To resolve the hostname of a DNS service itself, consider the bootstrap role of default-nameserver. Mixing these query types often creates a dependency loop on the first connection.

For example, the node may be offline while its hostname can only be resolved through that same node. Even if other websites have valid cached results, the full route can't recover. To troubleshoot this, start from a cold launch: close existing connections, restart the core, check the logs to confirm the node hostname resolves first, then test website resolution. Testing a page that's already open isn't very useful—your browser and operating system may have cached the result and mask a broken bootstrap configuration for a while.

Start with a Minimal DNS Configuration

This example separates bootstrap, regular queries, and node resolution, and starts with redir-host so you can inspect real addresses. The upstreams shown are suitable only in environments that can reach these public DNS services. If your network requires an organization-provided resolver, replace them with an approved address. Don't overwrite the resolver for internal company domains, or send internal domain names to an upstream that hasn't been authorized to handle them.

dns:
  enable: true
  listen: 127.0.0.1:1053
  ipv6: false
  enhanced-mode: redir-host
  default-nameserver:
    - 223.5.5.5
  nameserver:
    - https://223.5.5.5/dns-query
  proxy-server-nameserver:
    - 223.5.5.5

listen only controls where mihomo accepts DNS requests; it doesn't change the operating system's or browser's DNS settings. The commands below require dig to be installed and the core to be listening on the example address. Compare the status and record type from both queries, then verify which resolver path the application actually uses. Setting dns.ipv6: false suppresses AAAA responses from built-in DNS resolution. It doesn't disable IPv6 in the operating system or replace checking IPv6 routes.

dig @127.0.0.1 -p 1053 example.com A
dig @127.0.0.1 -p 1053 example.com AAAA

Choose Split DNS or Fallback Resolution

When you need specific domains to use a fixed upstream, consider nameserver-policy. For example, send internal services to an intranet resolver while regular domains continue to use the default upstream. For each domain category, test at least one name confirmed to exist and one confirmed not to exist. Internal services resolving to public addresses or a test domain unexpectedly receiving a wildcard record may indicate that the wrong upstream was used. Query speed alone can't tell you whether the answer is correct.

fallback doesn't simply put backup servers at the end of the queue and query them only after the primary times out. It can query in parallel with the primary and select a result according to fallback-filter. Routing a domain to a fallback and filtering results by returned address are different decision paths. If you don't have a clear fallback policy, there's no need to configure this layer. If geographic data is involved, make sure the data file is available; otherwise the same YAML may behave differently on another machine.

Distinguish Successful Resolution from Successful Access

Getting an address only proves that the resolution stage returned a result; it doesn't mean the connection will take the expected route. If resolution works but the site doesn't, check whether the connection reached the core, took the wrong policy, or the node can reach the returned address. Conversely, if queries to the built-in listener work but the browser gets a different result, first check the browser's secure DNS, system cache, and application-specific resolver. Change one thing at a time, and record the query status, target domain, and exit before and after each change.

After changing DNS settings, test direct services, proxied services, and domains available only on the intranet separately. If needed, also test the first request after waking from sleep. If changing encrypted DNS services triggers a certificate warning, check the system clock and trust chain; don't disable certificate validation to bypass the warning. For field interactions and DNS interception, see DNS upstreams, fallback resolution, and query interception.

TUN Mode and Fake-IP

Test Traffic Capture and Address Mapping Separately

TUN is a way to route traffic into the core; Fake-IP is a way to respond to DNS queries. TUN sends traffic matching the virtual interface's routes to the core. Fake-IP assigns a mapped address to a domain, which can be resolved back to that domain only if the subsequent connection returns to the same core. The two often work together, but enabling one doesn't necessarily enable the other. If the system proxy already covers the target app, you can keep the existing traffic capture method and avoid adding route complexity for apps that don't need it.

First record the default route, the network interface in use, and whether other VPNs or virtual adapters are active. When you first enable TUN, test on a single network environment if possible; don't change routes while switching Wi-Fi networks. If the GUI client provides a service mode or permission controls, complete authorization as required by the client first. Even if the UI shows the switch as enabled, confirm the virtual interface and target routes in the runtime state. A UI toggle alone doesn't prove the system is configured.

Enable It, Then Test a Simple Route

The example below shows common traffic capture fields for a desktop environment where you have the required permissions. auto-route creates routes automatically, auto-detect-interface identifies the actual outbound interface, and dns-hijack sends matching regular DNS requests to built-in DNS. This doesn't let mihomo decrypt encrypted DNS traffic from a browser. Mobile clients usually connect through the platform's network extension or VPN interface, so desktop routing fields shouldn't be copied over without adjustment.

tun:
  enable: true
  stack: system
  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:
    - '+.lan'
    - '+.local'
  nameserver:
    - 223.5.5.5

For testing, disable any explicit proxy settings in the test app so you can confirm whether the connection uses the TUN path. For a test domain not on the filter list, check that the DNS response belongs to the configured mapping range, then confirm the same request appears in the core's connection log. A Fake-IP address isn't the website's real address, so don't use it to test connectivity from another device. If you see a mapped response but no connection in the core log, investigate the traffic capture path before changing the policy group.

LAN Exceptions and App Compatibility

Some LAN services rely on real addresses, multicast discovery, or their own resolution logic. fake-ip-filter only prevents matching domains from receiving mapped responses; it doesn't configure multicast discovery, internal DNS, or LAN routes for the app. If printing, file sharing, or internal services stop working, first check whether they use a hostname, broadcast discovery, or a fixed address. Add the narrowest exception that meets the actual need, then check whether related addresses are still routed through the virtual interface.

If the mapping range conflicts with an organization network or another virtual interface, don't just switch to an address range that looks unused and deploy it. Check the target system's routing table and identify the route that covers the range. After adjusting it, restart the core and clear the test app's DNS cache. An app holding an old mapping may continue to fail even when the new configuration is working. Once restored, also verify that the system's default route hasn't changed, especially on devices using Ethernet, Wi-Fi, or a VPN at the same time.

Compare Rollback Behavior with Two Toggles

When widespread issues occur, retest the same target with a known-working system proxy configuration to see whether the problem happens only when TUN is enabled. If only TUN has issues, keep traffic capture enabled and temporarily switch DNS responses back to redir-host for a second comparison. This helps distinguish routing problems from address mapping problems. If the issue persists, check whether the target uses TCP, UDP, or a component that ignores system settings. Don't infer that an entire protocol is covered just because one website works.

Domain Sniffing and Matching Boundaries

Use Sniffing Only to Fill in Missing Domain Clues

Domain sniffing is useful when the core sees only a destination IP, but the connection handshake still carries a domain clue. It can try to retrieve matching information from an HTTP request's hostname or the server name visible in a TLS handshake. It doesn't decrypt traffic and can't guarantee that a domain can be read from every connection. If an explicit proxy request or Fake-IP mapping already provides the correct domain, verify your existing rules first instead of enabling another layer of sniffing by default.

Before enabling sniffing, prepare test traffic that should be routed by domain but appears as an address in the connection log. Note the traffic capture method, destination port, protocol, and expected rule. Then choose a connection that's already behaving correctly as a counterexample and confirm the change doesn't alter its match. Ideally, run both samples from the same client: different browsers may resolve names, reuse connections, and select protocols differently, so their results may not be directly comparable.

Limit Ports First, Then Check for Matches

This example starts with common HTTP and TLS ports. It allows attempts to identify pure-IP connections without using sniffed names to override the actual destination. ports limits where sniffing is attempted; it doesn't guarantee that the service uses the corresponding protocol. If an internal app uses a non-standard port, confirm its protocol first and add only that port. Don't add every port as a substitute for inspecting the problem connection.

sniffer:
  enable: true
  parse-pure-ip: true
  override-destination: false
  sniff:
    HTTP:
      ports: [80, 8080]
    TLS:
      ports: [443]
  skip-domain:
    - '+.lan'
    - '+.local'

parse-pure-ip controls whether to attempt sniffing for pure-IP traffic with no domain clues. override-destination controls how the destination is handled for the subsequent connection, which is a separate decision. If you only need to add information for routing, leave the latter disabled to prevent the domain from being resolved again to a different address. Before changing the dial destination, check with the team responsible for the target service and compare the address, certificate, and app response against a fixed test target.

Distinguish Unseen, Unrecognized, and Unmatched Names

An app may not send usable domain clues, may use encrypted handshake information, or may use a protocol outside the configured scope. For example, enabling TLS sniffing as shown doesn't mean QUIC traffic over UDP can be identified. If connection details always show an address, first check the actual protocol and port, then check whether pure-IP sniffing is enabled. If the handshake contains no usable name, consider a trusted DNS mapping or an explicit IP rule rather than expanding the sniffing scope and continuing to probe.

If the domain appears in the connection details but the wrong policy is still selected, check rule order, rule set type, and whether an earlier address rule matched first. Sniffing only provides information for matching; it doesn't increase a rule's priority. During troubleshooting, keep the exit unchanged and compare only the target name and matched rule in the connection details. This avoids mistaking different DNS results from different exits for a sniffing effect. Use a new connection during testing so an old reused session doesn't keep its previous route.

Keep Exceptions and Recovery Paths for Internal Services

skip-domain is useful for listing known domains that don't need sniffing, but it can't automatically exempt internal addresses that have no domain clues. For internal apps available only at fixed IPs, handle them through the connection scope and existing routing rules. For services that depend on a particular virtual host or require a fixed backend address, don't enable destination override without testing. And don't disable certificate checks to troubleshoot mismatches: a certificate mismatch can indicate that the destination address changed.

Before rollout, compare at least one connection that needs its domain filled in, one that should continue matching by address, and one internal connection that should go direct. Keep only the target type, port, and match result needed for diagnosis in change records; don't post real internal hostnames or users' browsing history in public tickets. If you can't reproduce a clear benefit, disable the sniffing configuration, restore the existing routing, and confirm the app's actual protocol before testing again.

Local Overrides and Multi-Subscription Merging

Separate Source Data from Local Settings

Treat updatable subscriptions as input. Use local overrides for rule exceptions, system integration, DNS, and settings that vary by device. Editing the remote configuration downloaded by a client can leave changes overwritten at the next update. Making the entire file a permanent override can preserve outdated values long after upstream fields change. First list the fields that must be controlled locally and document the purpose of each; let the source or client defaults manage everything else.

Override mechanisms differ between clients; there's no universal merge standard for mihomo YAML. Dictionaries may merge recursively or be replaced wholesale, and lists can't be assumed to merge by name. Take rules as an example: appending a rule at the end may leave it behind an earlier MATCH, while replacing the entire list may discard the original rules. In a test configuration, add just one easy-to-spot exception, then inspect the final configuration and a real match. Confirm how the client processes it before widening the override.

Import Nodes by Provider Instead of Concatenating YAML Files

If a source provides the proxies list required by a proxy provider, create a separate provider for that source, then use use in a local policy group to combine them. If the source delivers a complete configuration with groups and rules—or isn't YAML at all—export compatible node data using a method supported by the client. Don't assume changing the file extension makes it the right format. The example below uses local files for initial validation, without depending on remote updates.

proxy-providers:
  source-a:
    type: file
    path: ./providers/source-a.yaml
  source-b:
    type: file
    path: ./providers/source-b.yaml
proxy-groups:
  - name: Merged-Select
    type: select
    use:
      - source-a
      - source-b
rules:
  - DOMAIN-SUFFIX,example.com,Merged-Select
  - MATCH,DIRECT

Before use, create two files in the working directory. Each must have proxies: as its root key and contain at least one node that conforms to the core's format and is approved for use. Maintain the files separately. Groups reference provider names, not filenames; if you change a provider name, update every use entry. Duplicate node names can make menu selections and sources hard to distinguish. Prefix names by source when importing, and keep the naming scheme stable so updates don't leave previous manual selections without a matching entry.

Check Merge Order and Side Effects

Establish a consistent assembly order for the final configuration: load the base configuration first, add source nodes next, then apply local overrides. When merging lists, explicitly choose whether to keep, replace, or insert items. A node source supplies candidates; it shouldn't also determine the local listen address, system proxy, or LAN access settings. After merging, check the default proxy mode, final rules, group references, DNS paths, and external controller address. Don't stop at seeing both subscriptions in the UI.

After remote content updates, the client may show a successful download even though the core still uses an old configuration, or may fall back to its previous state after a load failure. Verify separately that the input updated, the final configuration was generated, and the running core reloaded it. Then select a candidate from each source and create a new connection, noting the group name and matched rule. If one unavailable source leaves a group with no candidates, fix the source or reduce the dependency. Don't silently change a sensitive service's fallback action to direct.

Share a Common Base Across Devices, Keep Device-Specific Settings Local

Rule lists and node naming conventions can be shared across devices; working directories, listen ports, virtual interface capture, and system proxy permissions should be managed on each device. Don't sync control secrets, URLs containing subscription credentials, or client runtime caches. Protect backups with appropriate access controls. Before sharing configuration snippets for troubleshooting, remove source URLs and node credentials. If you plan to sync a complete configuration, check the local fields offline on the second device first to avoid overwriting an active configuration.

For long-term maintenance, keep at least the most recent working base configuration and override file, and compare changes before and after updates. To roll back, first stop the problematic auto-refresh, then restore matching versions of both layers. Restoring only the main configuration while keeping an incompatible override can trigger the same error again. For a comparison of direct subscription use, remote configurations, and backup options, see how to sync configurations between desktop and mobile.

External Controller

Separate the Management Interface from the Traffic Entry Point

The external controller lets you read runtime status and allows an authorized panel to switch policies, trigger reloads, and perform other actions. It serves a different purpose from the proxy ports used by apps for HTTP or SOCKS requests. For a single desktop, bind it to the local loopback address and prefer the client’s integrated panel. If you only need local management, you don't need to enable LAN proxy access, change the system proxy, or bind the controller to every network interface just to connect the panel.

FieldPurposeHow to verify
external-controllerSets the controller's listen addressCheck the response with a local read-only request
secretSets credentials for controller accessConfirm that unauthenticated requests are rejected
external-uiSets the directory containing local panel files served by the controllerCheck the working directory and panel home page
mixed-portProxy listen port shared by HTTP and SOCKS5Start a test connection from an approved app

The example below only shows the listen settings; its sample secret isn't suitable for everyday use. For a live configuration, set a unique, strong random value locally. Don't put it in subscriptions, screenshots, tickets, or public documentation. If the client manages ports and credentials itself, use the configuration it actually passes to the core. After reloading, compare the active address and port; don't assume the values saved in the UI have taken effect.

mixed-port: 7890
allow-lan: false
external-controller: 127.0.0.1:9090
secret: "example-only-do-not-use"

Verify the Read-Only Endpoint Before Connecting the Panel

First, send a read-only request from the local machine without credentials. The command below should return an unauthorized status. If the connection is refused, the port isn't listening, the address is wrong, or the core hasn't loaded this configuration. After entering the local address and actual credentials in the client's integrated panel, check runtime information and proxy groups. You don't need to put real credentials on the command line or trigger a configuration reload to prove that access control works.

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

If the panel itself won't open, first distinguish between static files failing to load and the API being unreachable. If the core serves the local panel, check that external-ui points to the correct directory and that the home page is at the right level. If the page loads but the proxy list is empty, check the controller address, port, and authentication status entered in the panel. A page that loads doesn't prove it's connected to the right core. If two clients are running on the same machine, compare the proxy groups shown in the panel with the active configuration.

Same-Origin and Remote Management Boundaries

When an external web page and the local controller are on different origins, browsers also enforce cross-origin and mixed-content restrictions. Serving a trusted local panel from the core can often reduce cross-origin configuration. Don't disable authentication, allow any origin, or open a public port just to fix a browser error. Origin permissions and access authentication are separate controls: allowing an origin doesn't authorize it to use the controller, and neither replaces system firewalls or network access controls.

For management across devices, prefer an organization-approved, controlled management channel. Specify which devices and operators can access it, and restrict reachability to management use. Don't expose the controller and the proxy entry point for regular users to the same open network. If an automated task only needs to check status, prefer the client's built-in read-only status feature. If a single controller credential grants full access, any task holding it must not be treated as read-only.

Record Runtime Status Before Handoff

Check four things before wrapping up: the client loaded the intended configuration, the controller is listening only on the expected address, unauthenticated read-only requests are rejected, and a new connection uses the selected exit after switching policies in the panel. If credentials were shared or the interface was exposed unintentionally, first restrict access and rotate the credentials, then check the configuration and policies for unexpected changes. After recovery, repeat all four checks rather than just confirming that the panel opens.

Record the fields changed, the targets used for retesting, and where to find a recoverable configuration in a local note. If you run into connection issues in everyday use, return to the user guide to recheck import, traffic capture, and the first request, then come back to this guide for the relevant section. If the issue comes from client feature differences rather than the configuration itself, see the client comparison guide and confirm the required traffic entry method and platform support before switching clients.