Official Manual · Configuration Guide

Shadowrocket Rules and Configuration Guide

After selecting Config in Global Routing, the first matching rule in the active configuration usually determines how a request is routed. Before editing rules, check the current mode and active file.

New to Shadowrocket on iPhone or iPad? Follow the Quick Start to import a configuration and connect for the first time. This guide is a reference: follow the file structure and matching order, or use the contents to jump straight to syntax and troubleshooting. Interface labels refer to iPhone and iPad; check the options available on your platform.

Check exceptions before the fallback
[Rule]
DOMAIN,example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT

The main domain matches DIRECT; its subdomains match PROXY. Requests that match no earlier rule use DIRECT.

01 · File structure

The four configuration sections

[General]: Start with name resolution

A configuration file is not a server list. A subscription or server details you import provide the address and parameters needed to connect; a configuration file defines how requests are resolved, matched, and assigned a policy. These can change independently: switching configurations does not mean switching servers, and updating a subscription does not switch the rules file in use. Before making changes, check the active file in Config and keep an untouched copy. Test small changes in a duplicate. If filenames look similar, don’t rely on their position in the list to tell which one is active.

[General]
dns-server = system

This snippet tells the configuration to use system DNS. If a hostname won’t load, first check whether it resolved to an address, then whether a connection could be established to that address. Wi-Fi and mobile networks may return different addresses; changing DNS can also change which IP rules match. When checking rule order, leave the original DNS settings in place so you don’t change both the input to name resolution and the outcome of the rules. For a comparison of system DNS, custom DNS, and DNS over HTTPS, see the DNS configuration notes.

[Rule]: One match condition per line

[Rule]
DOMAIN-SUFFIX,example.com,PROXY
GEOIP,CN,DIRECT
FINAL,PROXY

The first line matches a domain suffix, the second classifies the destination IP by region, and the last line specifies a fallback policy without a match condition. Usually, write one rule per line, with fields separated by English commas. Don’t copy typographic punctuation from a webpage or combine two rules on one line. Hostname values should not include a protocol, port, or path. To merge rules from another file, find the existing [Rule] section and insert the relevant lines, then check how they interact with the rules around them. Don’t paste an example with its section heading into the middle of a section.

[Host]: Override name resolution for specific hostnames

[Host]
lab.example.com = 192.0.2.10

This example maps a test hostname to a reserved documentation address; it illustrates the format and is not a reachable service. A common issue appears after testing: an old mapping remains in the duplicate file, so the hostname still points to the old address and a new rule seems ineffective. To troubleshoot, search for the hostname in [Host], note its mapped address, and compare it with the destination address in the actual request. A mapping changes name resolution; it does not replace the connection policy set in [Rule] or automatically make a server certificate valid for that hostname.

[URL Rewrite]: Rewrite recognized URLs

[URL Rewrite]
^http://old\.example\.com/guide$ http://new.example.com/guide 302

This example matches only the specified HTTP URL and full path, then returns a temporary redirect. The escaped dot in the regular expression matches the literal dot in the domain; the end anchor prevents longer paths from being rewritten. Unlike [Rule], which selects a connection policy, URL rewriting operates on URLs. A domain match does not mean an HTTPS path can also be identified: ordinary encrypted connections don’t expose the full path, and a browser may upgrade an HTTP URL to HTTPS. To verify behavior, first confirm the request that was actually sent, then check rewriting and routing separately.

Read the four sections by purpose; there’s no need to add empty sections just to fill out the structure. If your configuration has other sections, keep them intact and replace only the lines you can verify for this change.

02 · Domain matching

Three domain rules

DOMAIN: Match one exact hostname

DOMAIN is useful for an exception on a single host—for example, routing a site’s status host directly while leaving its other subdomains under the existing policy. Use the full hostname as the value. status.example.com and www.status.example.com are two different hostnames; two page paths on the same host are not. The page URL in the address bar may not identify the host behind a failed request: the page could load images, sign-in state, or API data from another domain. Check the destination in the failed request before choosing a precise rule. Don’t use a page title, full URL, or pre-redirect address as the rule value.

DOMAIN-SUFFIX: Match a domain and its subdomains

DOMAIN-SUFFIX matches at domain-label boundaries. The value example.com matches the domain itself and api.example.com, but not every name that happens to end with those characters: notexample.com is not a subdomain. You don’t need an asterisk or leading dot. To apply a policy only to a documentation subdomain and its descendants, narrow the suffix to docs.example.com rather than covering the whole domain and adding exceptions for unrelated hosts. Choose suffixes based on operational boundaries, not superficial name similarity.

DOMAIN-KEYWORD: Assess the impact of a substring match

DOMAIN-KEYWORD checks whether a hostname contains a string; the string does not have to be a standalone label. This can match targets across different domains that share a naming marker, but it may also catch unrelated hosts. A generic term such as api could match hosts outside the intended service. An easy-to-remember word isn’t necessarily a good long-term condition. Before using a keyword, list at least one hostname that should match and one that should not. If you can only name a positive example, prefer an exact hostname or a sufficiently narrow suffix.

[Rule]
DOMAIN,status.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
DOMAIN-KEYWORD,team-preview,PROXY
FINAL,DIRECT
Target hostnameFirst matching ruleWhy it matches
status.example.comDOMAINThe exact exception comes before the suffix rule.
example.comDOMAIN-SUFFIXThe suffix rule includes the base domain.
team-preview.example.netDOMAIN-KEYWORDThe first two rules don’t match; the hostname contains the specified substring.
notexample.comFINALNeither a subdomain of the specified suffix nor a match for the keyword.

Read both the “First matching rule” and the final policy in the table. If both the suffix and keyword rules result in PROXY, whether the page loads won’t tell you which rule matched. The two samples may behave differently after you change either rule. Example domains illustrate matching; they aren’t guaranteed to host reachable services. For a real test, use a hostname you can access as a positive example and a similar-looking hostname managed by a different rule as a negative example. Record your predictions alongside the request logs.

Distinguish between a “name included in the request” and an “address looked up afterward.” If an app connects directly to an address, the client may not have the original hostname needed for a domain rule to match; the hostname can’t always be inferred from the address. Another common case: an app contacts an initial host, then switches to a different API host. The rule hasn’t stopped working—the input for the later request has changed. When a domain rule seems to match inconsistently, identify the exact request and destination first, then decide whether to add a domain or IP rule. For more syntax examples, see How rule keywords match.

03 · IP matching

IP and geolocation rules

IP-CIDR: Specify a verifiable address range

[Rule]
IP-CIDR,192.0.2.10/32,DIRECT
IP-CIDR,192.0.2.0/24,PROXY
IP-CIDR6,2001:db8::/32,DIRECT
GEOIP,CN,DIRECT
FINAL,PROXY

For an IPv4 range, the number after the slash in IP-CIDR is the prefix length—not a port number or number of addresses. 192.0.2.10/32 matches a single address, while 192.0.2.0/24 covers 192.0.2.0 through 192.0.2.255. When two rules overlap, put a single address before the subnet to preserve its policy. Don’t apply the routing-table principle of “longest prefix wins” to a configuration read from top to bottom. After writing the rules, test one address inside the range, one at its boundary, and one outside it. These addresses are examples of syntax only.

Base address ranges on a clear network plan, not on a subnet that happened to contain the address returned for a host once. Shared services may put unrelated hostnames in the same range, and a site may use different addresses as the network changes. When a target can be identified reliably by hostname, use a domain rule for service-specific exceptions and IP rules for connections without a name; this usually makes issues easier to diagnose. For devices that need a specific IP rule, start with a narrow prefix and expand it only when adjacent addresses serve the same purpose.

IP-CIDR6: Verify IPv6 separately

IPv4 and IPv6 are separate address spaces. An IP-CIDR range does not automatically cover a service’s IPv6 address. Use IP-CIDR6 for IPv6 ranges and /128 for a single IPv6 address. When testing a dual-stack service, check the address family actually attempted in the connection log, rather than relying on the first result from a lookup tool. A request may try IPv6 first and fall back to IPv4; looking only at the successful attempt can hide an earlier failure.

If a connection works on Wi-Fi but occasionally fails on mobile, compare the rules matched and address families on both networks, as well as basic reachability. Reconnect on each network using the same hostname, configuration, and policy, and record which address family was used. If the difference is limited to one family, check whether its rule is missing or the request falls through to the fallback. Don’t change DNS behavior for the entire network just to make the two logs look alike; the actual issue may be that a rule doesn’t cover the destination you expected.

GEOIP: Classification is based on the IP address, not the hostname

GEOIP,CN,DIRECT selects a policy based on the destination IP’s geographic classification—not the site’s language, your location, account region, or characters in the domain name. With nearby routing or shared services, different networks may resolve a site to different addresses, and classifications may change as address databases are updated. If you already know the policy for a service, put its domain rule before the geolocation rule. Reserve geolocation matching for targets without a specific exception. Geolocation is a routing condition, not proof of where a host is physically deployed.

IP rules also depend on how the address is obtained. If the target is already an IP, you can check the range directly; when the target is a domain, whether and when it is resolved depends on the rule parameters and current settings. For address rules that support no-resolve, this parameter prevents that rule from actively resolving a hostname. It does not disable DNS system-wide or replace checking whether the request already has a usable address. First handle known targets with explicit domain rules. Adjust this parameter only when you need to distinguish between an existing address and one that needs resolution, then test hostname requests and direct-IP requests separately.

When troubleshooting IP routing, keep at least two pieces of evidence: the destination address actually used and the first rule that matched. A DNS lookup alone can’t prove which address the app ultimately connected to.

04 · Requests and fallback

Request identifiers and fallback rules

USER-AGENT: Match a visible request field

[Rule]
USER-AGENT,ExampleClient*,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT

USER-AGENT relies on the User-Agent visible in a request; it does not match an app’s system name, process, or app identifier. ExampleClient in this sample is a fictional field prefix, and the asterisk allows the text after it to vary. Ordinary encrypted traffic does not expose this header directly, and other connection types may not include it. Not every request from the same app will necessarily match this rule; knowing which app made a request isn’t enough to predict a match. For reliable routing by destination, consider a domain or IP condition instead.

The example puts the request identifier before the suffix rule, so a request with that identifier uses DIRECT even if its destination is also under example.com. If your intent is to route that domain through PROXY regardless of who made the request, put the suffix rule first. These two rules are not conditions that must both be met. To test overlapping rules, use the same destination with different visible request identifiers, then use the same identifier with different destinations. This checks both whether the field is available and whether the priority is as intended.

FINAL: Set a destination for every unmatched request

Place FINAL at the end of [Rule], without a domain, IP, or request-identifier field. FINAL,DIRECT sends only explicitly listed traffic through other policies and connects directly for everything else. FINAL,PROXY sends all other traffic through the proxy, while explicitly listed requests use other policies. These choices have opposite effects on rules you forget to add: the first may send an omitted service directly, while the second may proxy a target that should have connected directly. Choose based on the default behavior you need; neither is right for every network.

A dedicated setup that must reject unknown traffic may use FINAL,REJECT. This affects every unmatched request, not just the app you just tested. A page loading normally doesn’t mean sign-in, attachments, messages, or background refreshes will work. To verify this configuration, list essential dependencies in a duplicate file and record each test result. If many requests suddenly fail in production, check whether they hit a reject fallback before replacing existing servers. Don’t loosen the entire default policy just to clear one error.

“No match” is not the same as “connection failed”

A request reaching FINAL means no earlier rule matched it in the active config. It is not a fallback after a connection fails. For example, if a domain matches PROXY but the selected server is unreachable, the client will not continue down the list and try FINAL,DIRECT. Keep the rule intact and check the selected connection. If the log shows FINAL, verify the target hostname, visible request fields, and rule order.

Another easy-to-miss mistake is pasting a source file’s FINAL into the middle when merging two rule sets. Rules added later then sit below the fallback, so many requests reach it early. Keep one clearly explained fallback at the end and put merged exceptions above it. Verify with two minimal samples: one that should match a specific rule and one that meets no conditions and should reach the fallback. If both use the same policy, check the actual matching line—identical connection results don’t prove the order is correct.

A request-identifier rule needs a visible field; a fallback rule doesn’t. First check whether the field can be evaluated in a real request, then test the fallback separately with an unrelated destination.

05 · Modes and policies

Policies and Global Routing

Check the overall routing mode first

Global Routing in Home determines whether this test uses configuration-based routing. To test [Rule], select Config, then check which file is active in Config. Proxy and Direct are useful for comparing connection paths, but their results don’t prove that a particular [Rule] is working. An enabled connection doesn’t necessarily mean rules are being applied. The table compares three common modes and their diagnostic uses. When testing is done, restore your usual mode and run the test again.

Interface labelHow it worksUseful for testing
ConfigRoutes traffic according to the active configuration.Rule matches, exception order, and fallback policies.
ProxyHandles intercepted requests using the proxy mode.Comparing connection results with an existing server.
DirectHandles intercepted requests using direct mode.Checking whether the destination is reachable directly on the current network.

PROXY, DIRECT, and REJECT are rule outcomes

[Rule]
DOMAIN,local-test.example.com,DIRECT
DOMAIN,blocked-test.example.com,REJECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT

PROXY sends a matching request to the currently selected proxy; it does not create a server entry in the rule. If a server has been imported but the wrong connection is selected, or the selected server is unavailable, a request can match the right rule and still fail. DIRECT connects without a proxy, but does not guarantee that the same hostname will resolve or be reachable on every network, and it does not turn off the client. REJECT actively rejects matching requests. If a test request is expected to be rejected and fails, use the logs to confirm why rather than repeatedly switching servers to make it succeed.

Don’t confuse interface labels with rule literals that differ in capitalization. Selecting Proxy in the interface changes the routing mode; writing PROXY in [Rule] assigns a policy to matching requests. Likewise, selecting Direct in the interface tests a direct-connection baseline, while a DIRECT exception affects only requests that match that rule. When asking someone to review “the change to direct mode,” specify where you changed it; otherwise, they can’t reliably reproduce the route.

Separate server-parameter issues from policy issues

If proxy tests fail in both Proxy and Config, but the same destination loads in Direct, don’t immediately reorder your rules. First confirm that you selected one of your existing servers, then check that its protocol, address, port, and required parameters are correct. WireGuard and Shadowsocks, for example, use different parameter sets; don’t enter one protocol’s fields for the other. If some requests work through the server, check whether the failure is specific to the destination rather than concluding from a single page that the whole connection is unavailable.

Connectivity Test in Home can provide clues, but the result for one test target doesn’t represent every request. If the test succeeds but a page fails, use Config to check which rule matched the page’s request, then look for additional destinations or redirects. A failed test doesn’t automatically mean all proxy destinations are unreachable: first check that its network and server selection match those used by the actual request. If you’ve confirmed an issue with an existing server connection, follow the server timeout troubleshooting checklist to narrow it down.

On Demand controls when a connection starts; it doesn’t replace Global Routing. Even when a connection starts automatically, check the routing mode used for the traffic.

06 · Order and precedence

Match order and priority

Trace an actual request from the top

To trace a request line by line, first note whether the client has a hostname, an IP address, or a visible request field. Then check [Rule] from the top down. The first rule whose conditions can be evaluated and match determines the policy; a more specific match later won’t change it. Priority comes from rule order—not keyword length or which policy seems stricter. Confirm the matching input before deciding which rule applies; this is more reliable than starting with the line you just changed.

[Rule]
DOMAIN,files.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
IP-CIDR,192.0.2.0/24,DIRECT
GEOIP,CN,DIRECT
FINAL,PROXY

Take files.example.com as an example. If the request can be matched by this hostname, the first rule selects a direct connection; its IP isn’t needed to choose a policy. For api.example.com on the same domain, the first rule doesn’t match, so the second selects a proxy—even if its IP falls within the later IP range. The third rule can’t change that outcome. Evaluate the IP range and geolocation only when earlier domain conditions don’t match and the destination address is available. This illustrates two principles: put exact conditions before broader ones that would cover them, and put hostname rules first when you want routing by name to take priority.

Check conflicts instead of adding duplicate rules

If you move DOMAIN-SUFFIX,example.com,PROXY to the top, the exception for the file host below it won’t take effect. Adding another copy of the same DOMAIN rule at the end won’t fix this conflict. Narrow the earlier broad rule, or move the exception above it. Start by moving the exception: other hosts keep their existing policy, and the scope is easier to review. Narrow the broad rule only if it shouldn’t cover the whole suffix, then assign a clear policy to targets that are no longer covered.

Keywords and geolocation can cause subtler conflicts. A keyword rule near the top may route hosts early when their names happen to contain the same substring. If IP or geolocation rules come first, requests with available addresses may match earlier than expected. Before troubleshooting, search the whole file for repeated conditions and scan for broader domain suffixes, keywords, and IP ranges. After importing or reactivating another configuration, start checking from the top of the active file. Exceptions in an old configuration don’t automatically apply to the same requests in a new one.

Verify priority with positive and negative test cases

Before applying changes, record at least three outcomes: a target that should match a specific exception, one that should still match the original broad rule, and an unrelated target that should reach the fallback. The first two can differ by a single hostname label, making it easier to check how an exact rule interacts with a suffix. The third confirms that reordering hasn’t affected the default behavior. For each sample, record both the expected policy—PROXY, DIRECT, or REJECT—and the first rule expected to match. Two rules can produce the same result today, but their order may determine whether a future exception works.

After a change, test with a new connection; don’t treat an existing long-lived connection as a result from the updated configuration. A page may use multiple connections, so match each log entry to its time and destination. Don’t assume the result for the homepage also applies to a later API request. If a rule change produces two or more unexpected matches, return to the previously working copy before making another change. This helps distinguish changes to the test conditions from an unexpectedly broader rule.

Before changing rule order, write down which line would otherwise override the exception. If you can’t identify that line, don’t reorder the whole rule set yet.

07 · Reusable patterns

Common routing configurations

Proxy only selected services

[Rule]
DOMAIN,health.example.com,DIRECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT

Useful when direct connections are the default and only explicitly listed services should use a proxy you’ve already configured. List the hostnames to include, then decide whether a shared suffix can cover them. For two unrelated hosts, separate DOMAIN rules are usually easier to control than a broad keyword. The example keeps a status check as a separate direct-connection exception so it remains a comparison target if you change the service rules. Before applying this to a real service, confirm that the comparison target is reachable directly; otherwise, it can verify a match but not serve as a connection baseline.

A common report is “the entry page uses the proxy, but things stop working after sign-in.” Check whether sign-in or API requests go to another domain and fall through to FINAL,DIRECT because it wasn’t listed. Add the narrowest rule for that destination only after confirming it’s a required dependency. Don’t immediately change the fallback to PROXY when something fails. That affects every previously unrelated request and makes it hard to tell whether the fix came from adding the missing dependency or from another change.

Proxy by default, with explicit direct-connection exceptions

[Rule]
DOMAIN,workstation.example.net,DIRECT
IP-CIDR,192.168.50.0/24,DIRECT
GEOIP,CN,DIRECT
FINAL,PROXY

Use the second line only if that private subnet is actually used on your local network. If you need to reach just one management device, use its single address rather than covering a large private range that looks similar to other networks. When connecting by IP, check the IP rule; when using the workstation’s name, first check whether the name resolves. If the outcomes differ, troubleshoot name resolution and destination reachability separately. DIRECT does not grant access to local devices or make a device with the same name or address on another network become the one on your current network.

In this example, GEOIP,CN,DIRECT is a separate choice that you can keep or remove as needed. “Proxy destinations not explicitly listed by default” doesn’t require a geolocation exception. When you switch Wi-Fi networks, the same private IP may refer to different devices. Rules select a connection path; they don’t identify devices. First determine which direct-connection rules depend on the current network, then recheck the destination on the new network. If necessary, keep a separate configuration for a clearly defined purpose, rather than leaving temporary test ranges in your everyday file.

Reject only explicitly unwanted targets

[Rule]
DOMAIN,unused.example.com,REJECT
DOMAIN-SUFFIX,example.com,PROXY
FINAL,DIRECT

Start with an exact hostname; don’t reject its entire parent domain to save a line. If multiple requests go to that host, the rule rejects connections to the host—not a specific page path or type of request. Test one request that should be rejected and another under the same suffix that should work. If both fail, first check whether the reject rule is too broad, then separately check whether the proxy path is reachable. A generic network error in the app alone isn’t enough to confirm that REJECT matched.

These three snippets show different default policies; don’t combine them with their section headings and fallback rules in one file. Start with a copy you’ve already verified, choose a default policy, and reuse one specific condition. Test it before adding more coverage or reject rules. Record each rule’s purpose—for example, “direct connection to office network management IPs” is easier to maintain than “add an IP rule.” If a rule is no longer needed, removing the obsolete exception is usually easier to troubleshoot than adding an opposing rule on top.

Reuse the structure, not the example targets. Use your own hostnames, addresses, and existing connection details. Don’t put subscription URLs, authentication fields, or real internal host lists in public notes.

08 · Verification

Validation, troubleshooting, and rollback

Establish a baseline, then change one variable at a time

Before you start, record the current configuration name, Global Routing mode, network, selected server, and test target. Run your test cases against an unchanged copy first and note which requests already fail, so you don’t blame an existing issue on a new rule. If you use an existing subscription, don’t update it during configuration testing: an update could change available connections or the current selection, making “it failed after I changed the rules” difficult to reproduce. After changing one rule, select the test copy in Config, repeat the same requests with new connections, and record the first matching rule and final result.

Choose the next check based on what happened

  1. Nothing matches expectations: check Global Routing in Home, then confirm the active file in Config. If you recently changed On Demand, distinguish whether the connection was established from whether the routing mode was correct. If you haven’t completed the system VPN permission setup, follow the Quick Start to establish a connection baseline. Don’t treat traffic that isn’t being intercepted as a missed rule.
  2. Only one target behaves unexpectedly: compare its hostname or IP with your test case. If the page redirects or loads another API, select the request that actually failed. If an earlier broad rule matched, check the order. If the request reached FINAL, determine whether the request field wasn’t visible or the condition was written incorrectly.
  3. The policy is correct but the connection fails: first check whether the hostname resolves to the expected address, then check whether the destination is reachable under that policy. For PROXY, check your existing server and its parameters. For DIRECT, check reachability on the current network. For REJECT, verify that failure is the expected result; don’t mistake an intentional rejection for a timeout.
  4. The issue appears only after switching networks: make a new connection on each network and record the address family, any redirects, and the matching rule. If only the address changes, check [Host], name-resolution settings, and IP ranges. If the policy is the same but the result differs, focus on reachability. Don’t change DNS, servers, and rules all at once.

For consistent comparisons, record “trigger, request destination, first match, result.” Make the trigger reproducible—for example, repeat a known page request instead of writing “worked this morning.” Distinguish matching differences (“different destination,” “different mode,” or “different file”) from connection issues (“no address resolved,” “connection could not be established,” or “app returned an error”). If a page makes many requests, narrow the test to one you can control. When sharing results, include only the necessary redacted destinations and policies; remove subscription URLs, authentication parameters, and session data.

Restore the original configuration and verify it works

If results keep changing, switch back to the saved original file, restore the previous routing mode, and retest the same sample with the same server and network. If it works again, investigate your recent changes one at a time. If it still fails, continue troubleshooting the network, name resolution, or existing server status; a recent rules change doesn’t prove rules are the only cause. When you retry, start with a single exact rule and widen the scope only after it works. For connection or acquisition questions, browse the FAQ by topic rather than searching the rules file for unrelated settings.

Get the app and prepare configuration details

To reproduce a test on another device, choose the right version from the downloads for all platforms page. Get Shadowrocket for iPhone or iPad from the App Store product page for a one-time purchase of $2.99 on the US storefront; actual pricing and system requirements are as listed on the App Store page. Versions for Mac (Apple silicon or Intel), Windows, Android, and Linux are free; download their installers from this site at /dl/. Verify the developer, Shadow Launch Technology Limited, and app ID 932747118 on the product page. Transfer only the configuration details needed for testing; don’t assume every device displays the same options or automatically uses the same active file.

A one-time app purchase is not a connection plan. This site provides the app and official manual; it does not provide, sell, or recommend proxy servers or subscriptions. To use proxy policies, use your existing subscription or server details.