Shadowrocket Rule Syntax: How DOMAIN-SUFFIX, GEOIP, IP-CIDR, and FINAL Work

Learn what DOMAIN, DOMAIN-SUFFIX, DOMAIN-KEYWORD, GEOIP, IP-CIDR, and FINAL match, how rule order works, and see examples you can compare with your configuration.

At a glance

This guide is for users who have imported their own configuration into Shadowrocket and want to adjust their routing rules. First, make sure Global Routing is set to Config. Then distinguish domain-based conditions from IP-based ones, and order rules from specific exceptions to broader matches, with FINAL at the end. The examples explain syntax and contain no usable connection details; replace the test targets with ones you are authorized to access.

Check when rules take effect

Rules determine the policy used for a connection; they do not create servers or determine whether a server is available. Home is for selecting a server and managing connections, Config is for managing configuration files, and Settings is for app preferences. After editing a file, make sure it is the currently selected configuration. Saving a file that is not enabled will not change the rules in use.

In Home → Global Routing, select Config to apply the routing rules in the current configuration as described here. Proxy routes all traffic through the proxy, while Direct connects directly. For Scene, check the configured scene conditions; seeing Scene in the menu alone does not mean a particular ruleset is active. When troubleshooting, select Config first to eliminate variables caused by scene changes.

6 types
This guide covers DOMAIN, DOMAIN-SUFFIX, DOMAIN-KEYWORD, GEOIP, IP-CIDR, and FINAL
3 fields
A standard conditional rule has a type, a match value, and a policy
1 rule
The minimal example uses one FINAL rule for connections not matched above

Takeaway: confirm the active configuration first

Before testing, note the current configuration name and Global Routing selection. If either is unclear, do not add rules yet; otherwise, you will not know whether a change came from switching files or from the match condition.

Rule syntax and policy names

In the [Rule] section of a configuration, a standard conditional rule usually has three fields separated by English commas: rule type, match value, and policy. Do not enter a full web address in a domain field: domain conditions do not include https://, paths, query parameters, or ports. The two lines below mean “connect directly to the specified domain” and “use a proxy for all other connections.”

[Rule]
DOMAIN,example.com,DIRECT
FINAL,PROXY
Field or policyMeaningWhat to check
DOMAINRule type; matches a full domain name.Not a protocol type or server name.
example.comThe match value used by this rule.Do not enter a URL with a path.
DIRECTConnect directly to the destination.The connection still depends on the current network, DNS, and destination reachability.
PROXYUse the proxy policy.Check which default server is selected in Home.
REJECTReject matching connections.If access fails after a match, that may be the rule's intended result.

If your configuration uses a custom policy group name, the rule must refer to a name that actually exists in the configuration. For initial tests, use DIRECT and PROXY. Do not add a policy group, change DNS, and reorder rules all at once. The examples below are snippets. If your configuration already has a [Rule] section, edit that section instead of repeatedly adding another one with the same name.

How the three domain conditions differ

Use DOMAIN for an exception on a single host, DOMAIN-SUFFIX for a domain and its subdomains, and DOMAIN-KEYWORD to match a specified string anywhere in a domain name. These conditions match domain information, not page titles, page content, or URL paths.

Example ruleMatchesDoes not match
DOMAIN,example.com,DIRECTexample.comapi.example.com
DOMAIN-SUFFIX,example.com,DIRECTexample.com、api.example.comnotexample.com、example.com.test
DOMAIN-KEYWORD,example,DIRECTapi.example.com、notexample.comDomains other than example.org that do not contain this string, such as sample.test

For DOMAIN-SUFFIX, enter example.com as is; there is no need to add *.. It matches suffixes at domain boundaries rather than performing a simple string-ending comparison. By contrast, DOMAIN-KEYWORD,example,DIRECT has a much broader scope and may match unrelated domains. If you only want to match one family of sites, prefer a specific suffix condition.

What GEOIP and IP-CIDR match

GEOIP checks the geographic classification of the destination IP in a geolocation database. For example, GEOIP,CN,DIRECT sends destination IPs classified as CN by the database to DIRECT. It does not check domain suffixes, page language, or a company's place of registration, and it cannot guarantee that all IP addresses returned for a domain belong to the same region.

IP-CIDR specifies an IPv4 address range directly. The number after the slash is the prefix length: /32 represents a single IPv4 address, while /24 covers 256 addresses. The examples below use address ranges reserved for documentation; they are not usable service addresses.

IP-CIDR,192.0.2.7/32,DIRECT
IP-CIDR,198.51.100.0/24,PROXY
GEOIP,CN,DIRECT
FINAL,PROXY

Some IP conditions support no-resolve, for example IP-CIDR,192.0.2.0/24,DIRECT,no-resolve. This prevents DNS resolution from being triggered solely to evaluate that rule; it does not disable DNS globally. If no destination IP is available at the time, the rule cannot match by resolving the domain. When troubleshooting, keep the relevant options in the existing configuration unchanged; do not add or remove them in bulk.

Match rules in order; put FINAL last

For the standard rules covered here, checks run from top to bottom. The policy on the first matching line is used; a later, “more specific” condition does not override it. Rule type names do not establish priority: DOMAIN does not automatically take precedence over a DOMAIN-SUFFIX rule above it.

[Rule]
DOMAIN,api.example.com,PROXY
DOMAIN-SUFFIX,example.com,DIRECT
IP-CIDR,192.0.2.0/24,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,PROXY
  1. For a request to api.example.com, the first line matches, so PROXY is used.
  2. For a request to www.example.com, the first line does not match, but the second does, so DIRECT is used.
  3. If the destination IP is 192.0.2.8 and no earlier domain rule matches, the example subnet rule can match.
  4. Other connections continue to GEOIP; if that still does not match, FINAL,PROXY handles them.

If you swap the first two lines, api.example.com will match the suffix rule first, disabling the single-domain exception you wanted to preserve. Likewise, FINAL is an unconditional fallback and belongs at the end of the ruleset; ordinary rules after it cannot change a result that has already been decided. Do not try to fix an ordering mistake by adding a second FINAL rule.

Takeaway: put exceptions before broader rules

To apply a different policy to a subdomain, place its DOMAIN condition before the relevant DOMAIN-SUFFIX rule. After saving, test that subdomain and another ordinary subdomain separately to confirm they take different routes.

Edit and verify in five steps

The steps below assume you already have your own server or subscription and can establish a basic connection. Configuration files and the server list in Home serve different purposes: updating server information does not mean the rules file being edited has been selected. Likewise, changing routing rules cannot fix invalid connection credentials.

  1. Back up the configuration

    Open Config, make a copy of the current configuration, and note the name of the file in use. For a remote configuration, check whether a future update will overwrite local changes.

  2. Confirm the routing mode

    In Home → Global Routing, select Config and make sure the intended test file is selected in Config. Also check which default server is selected in Home.

  3. Change one thing at a time

    In Config, open the editing option for the target configuration, enter text editing, and locate [Rule]. Add just one DOMAIN rule for a known target, or change a single rule's position, then save.

  4. Reconnect

    After saving, reconnect the VPN and have the test app make a new request. Existing long-lived connections may continue using the previous route, so repeatedly refreshing the same page may not create a new connection.

  5. Compare the results

    Check the visible destination, policy, and error details in the connection log against the expected result. Connectivity Test can help verify basic connectivity, but it cannot by itself prove which rule matched a website.

If a rule matches but access fails

A rule match only means a route was selected; it does not guarantee that the route can reach the destination. First check whether the intended policy was selected, then whether that route is available. The system error messages below may appear during connection diagnostics; they are not fixed errors from the rule parser. Where they appear and their full wording may vary by connection type.

Error: Connection refused

Cause: The destination or an intermediate device actively refused the connection. The service may not be listening, or the port may be incorrect. This does not prove that the DOMAIN syntax is wrong.

Fix: First check the actual connection destination in the log. If the route uses PROXY, verify the address and port of your existing server. If it uses DIRECT, check whether the destination service allows access on that port.

Error: Operation timed out

Cause: The connection did not complete before the timeout. This can happen if the server is unreachable, the destination does not respond, or the network drops packets. A timeout alone cannot identify which rule caused the problem.

Fix: First check the final policy, then test basic connectivity on the same network. Keep the configuration unchanged and check one item at a time; avoid changing DNS, the server, and rule order simultaneously.

No error, but the policy is not what you expected

After testing, remove the temporary rules or narrow them to the scope you actually need, then save a backup. A useful minimal test record includes the domain, actual destination IP, expected policy, actual policy, and exact error message. This information helps distinguish among matching boundaries, rule order, and network connectivity issues.

Verify Shadowrocket on the App Store