Configuration Guide / MIHOMO
Clash From Beginner to Advanced: Rule-Based Routing Configuration Guide
New to Clash? Start with the install, import, and verification steps in Getting Started. If you’re already connected or want to understand why each step works, jump to the relevant section of this guide.
Core Concepts: From App Request to Egress
The Client Provides the UI; the Core Handles Connections
A desktop or mobile client mainly imports configuration, displays proxies and logs, and enables the system proxy or creates a virtual network interface. The core does the actual work: parsing configuration, evaluating rules, and opening outbound connections. mihomo is one common core in the Clash ecosystem, but clients may use different cores and expose different settings. If a guide uses different names from the client UI, check the core listed on the About page first, then determine whether the option is controlled by the UI or the config file. Ultimately, a config is active only if the running core has loaded it—not merely because the editor can open the file.
Think of a connection in three stages: ingress, matching, and egress. The browser sends a request to a local listening port according to the system proxy settings—that’s ingress. The core decides whether to evaluate rules based on the current mode—that’s matching. The selected rule then determines whether traffic goes direct, gets rejected, or uses a proxy—that’s egress. A page loading successfully doesn’t prove it went through the proxy or that a particular rule matched. To check whether traffic reached the core, find the new connection for the target domain on the Connections page and inspect its rule and policy. If the client doesn’t show those details, use whatever the logs provide; a successful page load alone isn’t evidence.
Configs, Proxies, and Proxy Groups Are Different Things
A config is the complete set of instructions loaded by the core. It may include listening ports, proxies, proxy groups, rules, and DNS settings. A proxy defines the outbound connection parameters: where and how the core connects. A proxy group organizes proxies, other groups, or built-in policies under a selectable name. Rules usually point to that name, so changing the selected proxy in a group doesn’t require rewriting every rule that uses it. A subscription URL is a source for refreshing configs or proxies; it is neither a proxy nor a system proxy address. Pasting a subscription URL into your operating system’s proxy settings doesn’t import the config into the client.
Two kinds of direct connection are easy to confuse. If a request never reaches the core, the app connects directly through the system network. If it reaches the core and matches DIRECT, the core connects directly to the target. Neither uses a remote proxy, but DNS resolution, log visibility, and local network behavior may differ. Similarly, REJECT means the core actively blocks a matching connection; it doesn’t mean a proxy is unreachable. When troubleshooting, first check whether the connection appears in the logs, then why a policy was applied, and only then test the actual egress.
DNS resolution is part of this process, but it doesn’t always happen in the same place. Some apps pass the domain to the core along with the proxied request; others resolve it first and pass only the IP address to the system network stack. The core may therefore see different target information even when two apps visit the same service. If one app matches a domain rule and another falls through to the catch-all, don’t start by changing proxies or reinstalling the client. Check whether the log shows a domain or an IP address. If only an IP is available, adding another variation of the same domain rule won’t help. First identify the app’s ingress and DNS path, then choose a matching condition that fits its traffic.
Choose a Client: Platform, Maintenance, and Config Support
Start with Your Device, Then Check the Features You Need
For a first desktop client, consider Clash Plus on Windows, macOS, Android, or iOS, and Clash Verge Rev on Linux. If you already have a config, don’t choose based only on whether the app name includes “Clash.” Note the protocols, remote rule sets, and ingress methods your config needs, then check whether the client can import that config type, switch modes, show connection details, and enable the required features on your platform. If you only need the system proxy for a browser, there’s no need to choose a more complex setup for advanced options you’ll rarely use. For command-line tools or multiple apps, include proxy ports, virtual network interfaces, and diagnostics in your requirements.
| Platform | Available Clients | What to Consider |
|---|---|---|
| Windows | Clash Plus, Clash Verge Rev, FlClash, Clash Nyanpasu; Clash for Windows is archived | System architecture, system proxy integration, service permissions |
| macOS | Clash Plus, Clash Verge Rev, FlClash; ClashX Meta is archived | Apple silicon or Intel, system permissions |
| Android | Clash Plus、Clash Meta for Android、FlClash、Surfboard | System architecture, connection permissions, background operation |
| iOS | Clash Plus | System connection permissions, config compatibility |
| Linux | Clash Verge Rev、FlClash | Distribution package format, desktop environment, runtime permissions |
Desktop clients often show configs, proxies, and logs together, but the UI layout doesn’t determine compatibility. The same file may work in one client and show unknown fields in another because the clients use different cores or transform the config during import. Even if the file loads, check that proxy groups and rule lists are still there. For complex rules, remote rule sets, or less common outbound protocols, test a copy first and verify the results for a few known targets before moving your daily config. A successful launch isn’t enough to confirm migration: some issues appear only when a relevant rule matches or a remote file refreshes.
When to Use Archived Clients or a Standalone Core
Clash for Windows and ClashX Meta are no longer maintained. Their archived downloads are useful for inspecting an old setup, identifying legacy config, or preparing a migration. The fact that an existing installation still launches doesn’t mean it’s suitable for a new OS, newer config fields, or long-term use. Before migrating, note the current mode, system proxy status, and selected egress in each group. Export or back up your personal config, then quit the old client and confirm its ports and ingress settings are released. Import and test a copy in the new client, then verify your everyday apps before removing the old version. If both clients compete for the same port or system proxy, a successful launch won’t tell you which one is actually handling traffic.
Running mihomo standalone is a better fit for servers or routers where you need to manage the config directory, startup method, logs, and permissions yourself. Downloading and running the core doesn’t provide a GUI or decide which apps should use it. For a desktop setup focused on importing subscriptions and switching policies, a GUI client is easier to verify. If you need a terminal deployment, get a minimal config working in an environment you can easily roll back before setting up autostart. On a device managed by someone else or by an organization, confirm what you’re allowed to install before changing network settings they maintain.
Once you’ve chosen a client, visit the Download Center to find installers and system architectures. Still comparing options? See the client comparison. Keep a repeatable acceptance checklist: the client launches, imports and activates a config, switches policies, shows a test connection, and restores network settings when closed. On mobile, also test reconnecting after switching from Wi-Fi to cellular. The checklist checks everyday usability; it isn’t a speed ranking, and clients on different platforms don’t need identical interfaces or implementations.
Installation: Confirm the Core Is Running Before Routing Traffic
Distinguish Installation, Startup, and Network Capture
Before installing, check your OS and processor architecture in system settings. On Windows, don’t assume the architecture from the OS name alone. On macOS, check the chip or processor listed in About This Mac. On Linux, choose a package format and architecture supported by your distribution. For phones, check the OS version, device architecture, and any system permission prompt that appears on first connection. A client opening only confirms that the GUI launched; it doesn’t prove the core loaded a config or enabled the system proxy. On first launch, leave autostart, LAN access, and the virtual network interface disabled so you can easily undo changes.
If the system blocks installation or startup, work out whether the issue is an incompatible architecture, insufficient permissions, or a device management policy. Check the platform-specific download instructions and the message from your OS; disabling system security isn’t a general-purpose installation step. After installing a desktop client, check whether its status page shows the core and whether the logs report a config read or port binding error. On mobile, if another app is already connected through the system VPN interface, disconnect it before trying the new app. Note the original app and settings so you can restore them later.
Minimal Startup Check for a Standalone Core
These commands are for environments where you can run mihomo from a terminal, using config.yaml in the current directory. You can start with the complete local example in the Rule-Based Routing section. Quote paths that contain spaces. The first command tests the specified config; if it passes, use the second to run in the foreground, inspect the terminal output, and stop it with the terminal’s interrupt key. In a GUI client, check its built-in logs for the same config load and listener details. Don’t launch another core on a port already used by the client, and don’t overlap a test run with an existing instance using that port.
mihomo -t -f ./config.yaml
mihomo -f ./config.yaml
A successful config test doesn’t guarantee the core will start. Another process may already be using the listening port, or the GUI client may override the port in the config. If the address is in use, identify the process before deciding whether to stop an old instance or change the current config; don’t terminate an unknown system process. After changing mixed-port, update the system proxy and any apps configured to use that port. See how to troubleshoot a port conflict. If the port is unchanged but no connections appear, check whether the client has actually enabled an ingress method.
Before routing traffic, note the OS’s existing proxy settings: manual addresses, auto-config URLs, or settings applied by device management. On desktop, first test with one app explicitly configured to use the local proxy port. Once that works, enable the system proxy and retest with an app that follows system settings. When you quit the client, check that the system proxy has returned to its original state. If the OS had existing settings, restore the values you recorded rather than turning the proxy off by default. This lets you verify the local ingress and shutdown behavior even without a subscription, without troubleshooting the port, system permissions, and remote service all at once.
Subscriptions: Import, Activate, and Update
Check What the Subscription Returns
A subscription is a source for retrieving config, and its URL should come from the config provider or your organization’s admin. It may return a complete Clash-compatible config, a list of proxies, or even a web page that requires browser sign-in. In the client’s config page, find the import-from-URL option, paste the full address, and wait for the result. If the provider specifies a Clash or mihomo format, select it. If the client says the format isn’t supported, ask the provider what the URL returns; don’t paste it into an unfamiliar conversion site. Subscription URLs often contain access credentials, so remove the full URL from screenshots, diagnostic reports, and shared files.
A complete config may include rules, remote rule sets, and DNS settings as well as proxies. For an unfamiliar source, check which addresses it listens on, whether it enables LAN access, and whether it downloads additional resources. A subscription containing only proxies may need a client template or local config to provide rules and proxy groups; seeing only a proxy list after import isn’t necessarily an error. If you expected a complete config with rules but the rules page is still empty, first confirm that you imported the full config. Verifying the content is more useful than repeatedly renaming files or blindly switching clients.
An Imported Subscription Isn’t Necessarily Active
Confirm the new entry appears in the config list, then set it as the active config using the client’s controls. On the proxy page, check that the groups and proxies come from the new file; on the logs page, look for errors during loading. Some clients keep running the old config if the new one fails to load, so connections may appear normal even though the groups, rules, and test results are still from the old file. To spot this, use a distinctive config name and a test rule that produces a different result. For the first activation, select one known proxy manually and test with a small number of requests; there’s no need to run parallel tests against every candidate.
When updating, distinguish three stages: the client downloads the subscription, the core loads the new content, and existing test connections are re-established. A successful refresh confirms only that the download completed. New proxies in a group show that the updated content was received; to confirm they work, open a new connection and check the actual egress. If the selected proxy disappears from a group after an update, check whether the client switched it to a default option. On a device in active use or on a call, schedule config replacement or core restarts for a quiet period. For the relevant UI pages, see a quick tour of the proxy, config, and log pages.
If updates keep failing, check which layer the logs point to. A connection timeout or DNS failure means the source can’t be reached; an authorization error calls for checking the URL and permissions with the provider; a parse error means the returned format may be unexpected. Another possibility is a dependency loop: updates require a proxy, but the current config is broken. Keep the last working local config and test access to the source over a known-good network path. Don’t repeatedly clear the cache and working config. As long as the old file still loads, you can troubleshoot the update separately from the current connection. See Troubleshooting for common symptoms.
Proxy Modes: Rule, Global, and Direct
Check the Ingress Switch Before Changing Modes
Modes affect connections that reach the core; they don’t determine which apps get routed into it. Switching to Global won’t make an app that ignores system proxy settings connect through the core. Conversely, leaving the system proxy or virtual interface enabled while switching to Direct doesn’t fully disconnect the client. On desktop, start with an app that lets you specify a proxy address, then switch modes and observe the result. On mobile, check that the system connection is active and whether the client excludes the test app. Until ingress is verified, identical results across modes don’t point to a proxy failure.
| Mode | How Routed Traffic Is Handled | Best for |
|---|---|---|
| Rule | Matches rules in the active config, in order | Everyday use; check the matched rule and policy for a target |
| Global | Uses the global egress selection instead of checking each rule | Temporarily rule out routing decisions as the cause of a difference |
| Direct | The core connects directly to the target without a remote proxy | Compare results with and without a remote proxy |
Rule mode is suited to everyday use because one config can handle local services, specific domains, and other traffic differently. Before testing, make sure the client hasn’t stayed in Global or Direct mode from a previous session, then check the current group selection. A rule may point to a proxy group that selects another group or Direct; follow the entire selection chain to confirm the actual egress. A group’s name alone doesn’t show whether traffic is proxied. For targets not covered by explicit rules, check the fallback rules at the end. To debug a rule, compare the match for the same new request—not whether the whole page loaded or an external IP check returned a result.
Compare All Three Modes with the Same Request
Global mode can help determine whether a problem is limited to rule selection. Note the matched rule and actual egress in Rule mode, switch to Global, explicitly select the egress you want to compare, close the existing test session, and make the request again. If it works only in Global, return to Rule mode and check whether the target matched a different rule, went Direct by mistake, or was rejected. If both modes select the same egress and fail in the same way, changing rule order is unlikely to help; check DNS resolution, remote connectivity, and protocol errors instead. Switch back to Rule mode when you’re done so other apps don’t share the temporary egress selection.
For a Direct comparison, choose a target that should be reachable on your current network. If it works with Direct enabled but fails only through a particular proxy, the issue may be on that egress path; one test doesn’t prove every proxy is broken. If the target also fails in Direct mode, temporarily disable ingress and try again over the system’s normal connection. If that works, focus on the client’s DNS behavior and local routes. If it still fails, check the underlying network, target service, or app. Requests that never reach the core can’t be used to compare the three modes.
Browsers reuse connections, systems cache DNS results, and apps retry automatically, so behavior before and after a mode switch may overlap briefly. Don’t use a long-open browser tab to judge a new mode. Note when you switch, close the test session, and make a fresh request. If a page loads from several domains, compare the main request with the specific failed resource. A log showing a match for the main domain doesn’t mean images, APIs, and other dependencies used the same policy. To trace page resources, check each failed target separately; don’t leave the whole config in Global mode just to get a single green result.
Rule-Based Routing: Match Order and Policy Targets
Test a Minimal Config Before Adding Your Own Rules
Rules are evaluated from top to bottom, and usually the first match determines the policy for that connection. Domain suffixes work for a domain and its subdomains; exact-domain rules target one hostname. Keywords may appear in unrelated names, so avoid short strings. If you need an exception under a domain, put the exact rule before the suffix rule. For example, to route a subdomain differently, add its exact match first, then the general rule for the entire domain. Put the catch-all last: placed earlier, it prevents later rules from ever matching.
mixed-port: 7890
allow-lan: false
bind-address: 127.0.0.1
mode: rule
log-level: info
rules:
- DOMAIN,blocked.example,REJECT
- DOMAIN-SUFFIX,example.com,DIRECT
- MATCH,DIRECT
This is a complete local test config that doesn’t depend on a subscription or remote proxies. First confirm the port is free, then start it as described in the Installation section. The first rule demonstrates rejecting a reserved domain, the second demonstrates suffix matching, and the last sends all other ingressed requests directly. The commands below send two test requests through the same local proxy port; the empty argument means no proxy exceptions from the environment are used. Public requests still depend on your network being able to resolve and reach the test domain. Even if the page request fails, the core logs can show whether a rule rejected it, the target was unreachable, or the request never reached the local port.
curl --noproxy "" --proxy http://127.0.0.1:7890 https://example.com/
curl --noproxy "" --proxy http://127.0.0.1:7890 http://blocked.example/
Check Policy Definitions in the Active Config
DIRECT and REJECT are built-in policies, but PROXY in common examples isn’t a universal proxy that exists automatically. For a rule to target that name, the active config must define a usable proxy or proxy group with the same name. Before adding a rule, copy a group name from the config that’s actually active and check its capitalization and spacing; then check the selected leaf proxy in the client. With a remote subscription, the provider may change a group’s name while a local override still refers to the old one. In that case, update the target reference rather than changing the domain. A group selection can affect multiple rules, so check what else uses the group before changing it.
IP-based conditions and domain-based conditions aren’t interchangeable. If ingress provides only an IP address, a domain rule may have nothing to match. If the target is a domain but a later rule needs to match its IP address, DNS resolution may be involved. For IP-based rules that support no-resolve, this option prevents the rule from triggering a DNS lookup just to match; it can’t supply a missing target IP or stop an app from resolving the domain before ingress. For rules that rely on geolocation data, distinguish whether the data file can be read from whether the target is covered by that data. Before changing this layer, compare against a rule that doesn’t depend on geolocation data.
When merging configs, keep the structure in mind: a file should have one top-level rules list, with new entries added to that list. Don’t append another top-level key with the same name and expect the core to merge it. Use spaces for indentation and keep new list items at the same level as the other rules. For rule sets split by purpose, decide which one should handle exceptions first, then define the shared fallback. If a connection matches an unexpected rule, work backward from the first match in the logs and check for a broader domain suffix, a similar rule bundled with the subscription, or an override inserted during loading. The effective order matters more than any one source file in the editor.
TUN: Virtual Interfaces, System Routes, and DNS
Enable TUN Only If You Need to Manage System Routes
The system proxy is mainly for apps that honor its settings. Consider a virtual network interface when apps ignore those settings or when you need to handle traffic that a standard proxy listener doesn’t receive. TUN uses a virtual interface and routes to send eligible traffic to the core, where it’s still handled according to the current mode. It isn’t a remote proxy and doesn’t guarantee that every app or protocol will work. If a remote proxy doesn’t support a particular type of outbound traffic, enabling TUN won’t add that support. On mobile, the client and OS manage the system connection; don’t copy desktop YAML or service setup steps verbatim.
Before enabling TUN on a desktop for the first time, use your usual setup to open a known-reachable target and note the selected proxy group, current network, and system proxy state. Close competing proxy or virtual interface apps, then enable TUN in the client where you can access the device locally. The OS may request network permissions or installation of a helper service; follow the client and OS prompts. Don’t change the default route on a device controlled only through a remote session. To check whether the virtual interface works, first establish a baseline, then temporarily turn off the separate system proxy switch and test with TUN alone. Don’t change proxies or rules at the same time as this first test.
Check the Limits of Automatic Routing and DNS
This is a mihomo top-level config snippet for testing traffic capture on a supported desktop setup. Merge it into your existing config rather than adding a duplicate tun key. auto-route tells the core to try adding routes to capture traffic; auto-detect-interface attempts to identify the outbound interface; and stack selects the protocol stack used by the core. A GUI client may generate or override this section. On devices with multiple network adapters, other virtual networks, or container bridges, check the outbound interface and existing subnets separately; success on one device doesn’t guarantee the same setup will work everywhere.
tun:
enable: true
stack: system
auto-route: true
auto-detect-interface: true
First use the basic snippet to verify the interface and routes, then decide whether you also need to capture DNS. If the client uses dns-hijack to send certain traditional DNS requests to the core, confirm that core DNS is enabled and has a reachable upstream. Capturing traditional DNS traffic doesn’t mean the core can resolve encrypted DNS requests from apps. Browser-level DNS, corporate internal domains, and LAN names may also take different paths. Test public domains and internal services that normally work, and note whether only domain lookups fail or all connections fail. For DNS modes and upstream selection, see the Clash DNS configuration guide.
If the whole machine loses internet access after you enable TUN, turn it off first and return to the baseline you recorded. Don’t keep layering on DNS, rules, or interface changes. If connectivity returns, check the logs for permission errors next, then look for conflicts with another virtual route. If only LAN devices are unreachable, test a known LAN address and its domain separately to distinguish a routing issue from changed DNS resolution. If the problem appears after switching Wi-Fi networks or waking from sleep, check whether the automatically detected outbound interface updated. Once you’ve narrowed it down, record the smallest set of conditions that reproduces the issue; don’t combine failures from different network environments.
Maintenance: Updates, Logs, and Rollbacks
Handle Four Types of Updates Separately
The client, core, subscription content, and rule data are separate update targets. A GUI update can change menus or permissions; a core update can change support for config fields; a subscription refresh can change proxies and groups; and geolocation data or remote rule-set updates can change match results. Don’t change all four at once and then start testing, or you won’t know which layer caused a problem. Before updating, keep the last working config and personal overrides, and note the current mode, listening port, and group selections. If the components can be updated separately, change one at a time and run the same connection checks before moving on.
A successful startup after refreshing rule data doesn’t prove that routing still behaves the same. Test a few targets you use daily: a local service that should go direct, a common domain that should use a particular group, and a test target covered by a reject rule. Open a new connection for each and record the matched rule and final egress. If you use rules such as GEOIP that depend on geolocation data, check the logs for data load errors. For custom remote rule sets, confirm whether this refresh actually completed or whether the core is still using its previous cache. Don’t rely solely on an enabled update button or a “running” status in the UI.
Use Logs to Diagnose Problems—Don’t Reinstall Repeatedly
For routine checks, start with info to see key config loading and connection details. Use warning to reduce routine output if desired, but this level may omit the normal details needed to confirm a rule match. During troubleshooting, switch briefly to debug, reproduce the issue once within a clear time window, collect the relevant lines, then restore the original level. When sharing logs, keep only the necessary timeline, error type, and rule name; remove subscription URLs, identity details, internal domains, and sensitive connection information. More output doesn’t necessarily mean more failures. Start with the first error related to your request, then check any subsequent retries.
If an app has no connection entry, first check the system proxy, manual port, virtual interface, or whether the app is excluded. If the connection reaches the core but uses the wrong policy, check the rule order and the active config. If the policy is correct but the connection still fails, look at DNS resolution, the proxy handshake, and the target service response. A browser working while a command-line tool fails often means they use different ingress methods—not that the same target suddenly got a different rule. To describe the issue to someone else, you can simply say which type of app fails, whether the same request works through another ingress method, and what the first related error says. For more comparisons, see Troubleshooting FAQs.
A rollback should restore a known-working setup, not reset every option to its default. First undo the most recent change. If you changed an override or subscription, switch back to the previous local config and confirm it’s active. If ingress caused the problem, restore the original system proxy or virtual interface setting, then test again. After a core upgrade, also confirm that the rolled-back core can read the current config; don’t just replace the program while leaving new config fields in place. Once restored, test a normal shutdown and confirm the system network still works. Keep a short record of the symptoms, cause, fix, and verification. Retesting that path before the next upgrade can save repeated troubleshooting.
Advanced Setup: Reproducible Configs and Deployments
Separate Config Responsibilities Before Adding Automation
Once your manual rules work reliably, maintain each part according to its role: let the provider manage frequently changing proxy sources, put relatively stable domain or IP collections in rule sets, and keep a small number of local exceptions in the main config. In mihomo, proxy-providers supply proxy candidates and rule-providers supply match conditions; they aren’t interchangeable. Groups must explicitly reference proxy sources, and the rules list must reference rule sets through the appropriate entries. During migration, replace one part at a time: first check that the cache loads, then confirm it updates when due. Keep a local fallback config so you can still test local ingress if an external source is unavailable.
Proxy groups can evolve from manual selection to automatic health checks or failover. Keep a manual group when you need to reproduce a specific connection reliably. Use a test group to select candidates based on health, or a fallback group to try candidates in order. One test target only shows whether that target is reachable; it doesn’t prove every service will work. Overly frequent tests also create extra connections, making mobile network behavior and intermittent failures harder to interpret. After switching to an automatic policy, check whether it switches back when a candidate recovers and how the switch affects new connections versus existing long-lived sessions.
Separate Single-Machine Testing from Always-On Deployment
Before running a standalone core on Linux or another always-on device, identify the config, data, and log directories. Once foreground startup works, you can consider managing it as a system service. The service user, working directory, and file permissions may differ from a manual run, and relative paths may resolve somewhere else. If manual startup works but the service doesn’t, check which config it actually reads, whether the working directory exists, and whether the service user can access rules and cache files. Before enabling a persistent service, make sure you can stop it locally and know how to restore the previous config and network settings.
A router or secondary gateway affects other devices’ gateways and DNS, so problems can have a wider impact than on a single machine. Start with the OpenWrt and secondary gateway deployment overview. Test ingress with one device in a controlled environment instead of changing the whole LAN at once. Check both the routed device’s access and the existing network on a device that isn’t routed. Keep the management interface within its intended access scope; don’t expose local proxy or management ports to networks that don’t need them. Before changing the gateway, keep an independent management path and a copy of the original config so you can recover without relying on the network you’re fixing.
A short acceptance checklist is more useful than continually adding rules. For each test, record the ingress method, target, expected rule, expected egress, and actual result. Also cover state changes such as restarting the client, switching networks, refreshing the subscription, and quitting. Using the same targets each time makes it easier to tell whether a change came from rules, DNS, or ingress. If you share a config, include the supported clients, permissions users must confirm, and shutdown and rollback steps. Keep example configs minimal and separate from personal subscriptions. When something unexpected happens, check ingress, matching, and egress in order; that’s usually faster than adding more exceptions to a large config.