Shadowrocket Rule Syntax: What DOMAIN-SUFFIX, GEOIP, IP-CIDR, and FINAL Match

Learn what DOMAIN, DOMAIN-SUFFIX, DOMAIN-KEYWORD, GEOIP, IP-CIDR, and FINAL match, with rule examples and a clear guide to top-down rule order.

At a glance

Rules are checked from top to bottom, and the first match determines the policy: place specific exceptions before broader rules and put FINAL last. This guide is for iPhone, iPad, Mac, Windows, Android, and Linux users editing a Shadowrocket configuration. The examples use Home and Config on iPhone / iPad; users on other platforms can refer to the rule syntax and the configuration currently in use.

1. Confirm which configuration is active

Check the routing mode before reviewing the rules themselves. Even a correctly written rule won’t help you diagnose a request if you edited a configuration that isn’t active, or if Global Routing is set to Proxy or Direct. In those cases, the request can’t show which line in [Rule] would match.

  1. Open Config and confirm which configuration file is selected. Keep a copy of the original, then edit the [Rule] section in a working copy. Save it and make sure the edited copy is selected; don’t stop at the editing screen.
  2. Go to Home → Global Routing and select Config. Here, Config is a routing mode; Config in the bottom bar is where you manage configuration files. Scene selects routing behavior by scenario. To test one configuration, select Config directly and avoid adding another variable.
  3. Make sure the connection is on, then send a new request. Start with a rule whose expected result is clear. Don’t change the network, configuration, and proxy server at the same time, or you won’t know which change affected the result.
App requestRouting modeRule matchingPolicy applied

2. Domain rules: exact, suffix, and keyword matches

All three domain rules inspect the hostname, not the full URL. For https://docs.example.com:443/guide?q=rules, enter docs.example.com as the rule value. Don’t include https://, port 443, path /guide, or query parameters.

Type and match valueMatchesDoes not match
DOMAIN,docs.example.comdocs.example.comexample.com、api.docs.example.com
DOMAIN-SUFFIX,example.comexample.com、docs.example.com、api.docs.example.comnotexample.com、example.com.example.net
DOMAIN-KEYWORD,mediamedia.example.net、multimedia.example.orgdocs.example.com; a /media path does not affect the match

DOMAIN-SUFFIX matches at domain-label boundaries. Use example.com to match both the domain itself and its subdomains; there’s no need to write *.example.com, and notexample.com won’t match just because it ends with the same characters. DOMAIN-KEYWORD doesn’t observe label boundaries: it can match any hostname containing the specified string, even when that string is part of a longer word.

Choose a rule based on the hostnames you need to affect

Use DOMAIN for a single hostname. Choose DOMAIN-SUFFIX only when the entire domain and its subdomains should use the same policy. Use DOMAIN-KEYWORD only when you specifically need to match a string across domains.

3. IP rules: address ranges and geographic database matches

IP-CIDR matches destination IPv4 address ranges. GEOIP matches based on how the destination IP is classified in a geographic IP database. Neither rule checks domain suffixes, device location, website language, or account region. For a request addressed to a domain, whether an IP rule matches depends on whether the destination address is available when matching occurs.

When investigating a routing mismatch, first determine whether an earlier rule handled the domain or whether the request reached an IP rule but the address didn’t match. If a destination must use a specific policy and its domain is stable, use an explicit domain rule rather than relying on a DNS result that may change.

4. Rule order and FINAL: the first match wins

The examples below show how to write a [Rule] section. For a regular rule, enter the type, match value, and policy in that order. FINAL has no match value, so enter the policy directly after it. Here, DIRECT means a direct connection, while PROXY routes traffic through a proxy. The example domains and address ranges are for illustrating rule behavior, not testing availability. To test PROXY, use a proxy configuration you already have.

[Rule]
DOMAIN,docs.example.com,PROXY
DOMAIN-SUFFIX,example.com,DIRECT
DOMAIN-KEYWORD,media,PROXY
IP-CIDR,192.0.2.0/24,DIRECT
GEOIP,CN,DIRECT
FINAL,PROXY
  1. docs.example.com matches both of the first two rules, but the first one wins, so the request uses PROXY. Swap those two lines and the same hostname uses DIRECT. Rules don’t automatically move exact matches ahead of suffix matches.
  2. media.example.com matches both the suffix rule and the keyword rule. In this order, it uses DIRECT. media.example.net doesn’t match the suffix rule, so matching continues to the keyword rule and uses PROXY. Before adding a rule, check whether an earlier line already matches.
  3. For a direct request to 192.0.2.15, this example matches IP-CIDR and doesn’t need to check GEOIP. FINAL,PROXY applies only if none of the earlier domain, address-range, or geographic rules match.
  4. FINAL isn’t a fallback route for failed connections. If the first matching rule selects PROXY but the proxy connection times out, Shadowrocket won’t try the next DIRECT rule. When troubleshooting, check separately which policy was selected and whether that policy can connect.

5. Rules are in place, but the site won’t load: identify where the error occurs

The following error codes may appear in Chromium-based browsers; they aren’t Shadowrocket interface messages. They can help narrow down the cause, but don’t prove on their own that a particular rule matched. When checking, note the actual hostname, expected policy, and result. Change one condition at a time, then make a new connection.

Error: ERR_NAME_NOT_RESOLVED

Cause: The browser couldn’t resolve the hostname. It may be misspelled, or the current DNS resolution path may not have returned a usable address.

Fix: Check the hostname in the address bar and in the rule, then use the same network to test a domain you know resolves. If only the target hostname fails, check its DNS response first. Don’t diagnose the issue just by moving the GEOIP rule.

Error: ERR_CONNECTION_TIMED_OUT

Cause: The connection timed out while waiting for a response. The selected outbound route may not reach the destination, or the destination service may not be responding.

Fix: First check Home → Global Routing → Config and the first rule that could match. If you expect the request to use PROXY, use Connectivity Test in Home to check a proxy you already have. A successful test doesn’t guarantee that the website is reachable; test the hostname that produced the error again.

6. Common questions about editing rules

How do I proxy only the login hostname and keep other subdomains direct?

Add DOMAIN,login.example.com,PROXY first, followed by DOMAIN-SUFFIX,example.com,DIRECT. Check for earlier matching rules above these lines. Test the login hostname and a regular subdomain separately to make sure the exception and default policy aren’t reversed.

The homepage loads, but images don’t. Which rule should I change?

Use your browser’s network diagnostics to find the hostname of a failed request. Images may come from different domains; a DOMAIN rule matching the homepage won’t automatically cover their hostnames. Add an exact rule for the failed hostname, then retest the image request separately.

A domain works, but entering the server’s IP address directly doesn’t. Is the rule wrong?

Not necessarily. When you enter an IP address directly, the request is no longer matched using the original domain, so check the address rules and fallback policy. With HTTPS, the certificate and site selection may also depend on the original domain. Directly entering an IP isn’t an equivalent test.

Can I temporarily move FINAL higher up to test it?

Don’t test a single hostname by moving the fallback rule higher. In a copy of the configuration, add a specific DOMAIN rule before any broader rule that overlaps it, and test only that hostname. When you’re done, remove the temporary rule or switch back to the original configuration.

Download Shadowrocket