Arrange Shadowrocket rules with specific exceptions first, broader conditions later, and FINAL at the end. Then select Config under Global Routing and test your setup. This guide is for users with an existing provider and subscription who want to edit a configuration file. Learn the rule fields and policies, check matching behavior with domain and IP examples, and distinguish between a rule not matching, a DNS failure, and an outbound connection failure.
1. Select Config before testing your rules
A correctly written rule is not necessarily in use. In Config, confirm that the intended configuration file is selected, then return to Home and check Global Routing. Select Config to route traffic according to the configuration file. If Global Routing is set to Proxy or Direct, the results won't tell you whether an individual configuration rule is working.
- Proxy: Routes traffic through the global proxy. Don't use it to test individual rules in Config.
- Direct: Connects directly. Being able to reach a destination directly doesn't mean your proxy policy is configured correctly.
- Config: Routes traffic according to the rules in the selected configuration file. This is the mode used for testing in this guide.
- Scene: Uses the configured scene conditions. When troubleshooting, switch to Config explicitly to reduce variables caused by scene changes.
Settings → On Demand controls automatic connections based on conditions; it doesn't replace rule matching. If Shadowrocket disconnects and then reconnects automatically, check On Demand before removing FINAL. Keep the network, configuration file, and routing mode unchanged during testing. Change one condition at a time to make issues easier to reproduce.
2. Rule syntax: separate match conditions from policies
A standard rule typically contains a type, a match value, and a policy, separated by English commas. FINAL has no match value; it takes only a type and a policy. Add rules to the [Rule] section of the configuration, not to [General] or a section containing proxy entries.
[Rule]
DOMAIN,example.com,DIRECT
DOMAIN-SUFFIX,example.org,PROXY
DOMAIN-KEYWORD,tracking,REJECT
IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,PROXY
| Policy | What it does | What to check |
|---|---|---|
DIRECT | Connects directly to the destination without using a proxy outbound. | Whether the destination is reachable directly on the current network. |
REJECT | Rejects matching connections. | Whether the match is too broad and could block domains a page depends on. |
PROXY | Hands traffic to the policy named PROXY. | Whether a policy with that name exists and the outbound currently selected by its policy group is available. |
A rule name and a proxy protocol are different things. Using Shadowsocks, VMess, VLESS, Trojan, Hysteria2, or WireGuard for an existing outbound doesn't change what DOMAIN-SUFFIX matches. Protocols handle connections; rules decide which policy handles them. Also distinguish between updating an outbound list and updating configuration rules when refreshing a subscription; they are not the same operation.
3. DOMAIN rules: exact domains, suffixes, and keywords
Domain rules don't include https://, a page path, or a port. To handle https://api.example.com:8443/account, use api.example.com as the DOMAIN match value—not the full URL. The /account path and 8443 port aren't part of the domain field.
| Rule | Matches | Doesn't match |
|---|---|---|
DOMAIN,example.com,DIRECT | example.com | www.example.com |
DOMAIN-SUFFIX,example.com,DIRECT | example.com、api.example.com | notexample.com、example.com.other.test |
DOMAIN-KEYWORD,example,PROXY | example.com、myexample.net | Requests whose domain doesn't contain example, even if the page path includes that word. |
DOMAIN-SUFFIX matches domain names by label, not arbitrary strings at the end of a hostname. For example, example.com matches its subdomains but not notexample.com. If only one login endpoint should use a proxy, prefer DOMAIN. Use DOMAIN-SUFFIX when the entire domain and its subdomains need the same policy.
[Rule]
DOMAIN,login.example.com,PROXY
DOMAIN-SUFFIX,example.com,DIRECT
FINAL,PROXY
With the rules in this order, the login domain matches the first rule, while other subdomains fall through to the second. Move the suffix rule to the top and the login domain will also be routed DIRECT before its exact rule can match. DOMAIN-KEYWORD is usually harder to scope. Before adding one, list unrelated domains that might contain the same string, and avoid assigning a common keyword directly to REJECT.
4. IP-CIDR and GEOIP: match IP addresses and networks
IP-CIDR checks whether a destination IPv4 address belongs to a specified network. 192.168.0.0/16 covers addresses from 192.168.0.0 through 192.168.255.255, while 192.168.1.10/32 matches a single address. Use the corresponding IP-CIDR6 rule for IPv6 networks; don't put IPv6 addresses into an IPv4 example.
[Rule]
IP-CIDR,192.168.1.10/32,DIRECT,no-resolve
IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,PROXY
- IP-CIDR: Useful for known LAN addresses or destination networks. Enter the actual network range; the example isn't a complete list of all LANs.
- GEOIP: Uses an IP geolocation database to determine where an address is registered.
GEOIP,CN,DIRECTdoesn't mean “connect Chinese-language websites directly,” and it doesn't match domain suffixes. - no-resolve: Prevents a domain from being actively resolved just to check this IP rule. If a request has only a domain name and no available destination IP, this rule may be skipped.
Address-based rules generally need a usable destination IP to evaluate a domain request. A DNS failure may prevent subsequent IP checks from working as expected, so not every missed match means the GEOIP data is inaccurate. A domain served through a CDN may resolve to different addresses depending on the DNS response or address family.
5. Rules are checked top to bottom: put FINAL last
In a standard rule chain, requests are checked from top to bottom. The first matching rule determines the policy; later rules aren't checked for a “more specific” match. Specific rules take priority because you place them earlier—not because the app automatically sorts rules by specificity.
- Put exact domains, individual IPs, and explicit reject rules that need priority first.
- Next, add domain suffixes, carefully scoped keywords, and destination networks.
- Then add broader conditions such as GEOIP. Place them before or after other rules based on your needs.
- Finish with a FINAL rule to define how all remaining requests are handled.
FINAL doesn't check domains or IP addresses, so placing FINAL,PROXY at the top leaves no opportunity for later standard rules to match. FINAL isn't a fallback for errors: if an earlier rule matches but its connection fails, traffic won't automatically move to FINAL and use another route.
[Rule]
DOMAIN,api.example.com,PROXY
DOMAIN-SUFFIX,example.com,DIRECT
DOMAIN-KEYWORD,tracking,REJECT
IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
GEOIP,CN,DIRECT
FINAL,PROXY
With this example, api.example.com uses PROXY, www.example.com uses DIRECT, and other domains containing tracking are REJECTED. A request matched by a domain rule won't switch policies just because its destination IP also matches GEOIP. Only requests that haven't matched any earlier rule reach FINAL.
6. Rules not working? Check the configuration, match, and outbound
Save a copy of the current configuration before making changes. After editing, confirm the selected file in Config, return to Home, make sure Global Routing is set to Config, and create a new test connection. Existing long-lived connections may retain their previous state, so refreshing a page that keeps its connection open isn't enough to conclude that a rule isn't working.
- Check the file: Make sure you're editing the configuration currently in use, not a backup with the same name. After updating a remote configuration, check whether your manual changes are still there.
- Check the syntax: Verify the English commas, rule section, and policy names—especially that PROXY actually exists in the current configuration.
- Check the destination: Look at the actual domain or IP in the request log. A page often uses separate domains for login, images, and API calls; the browser's address bar shows only one of them.
- Check the match: Compare the policy and rule details in the log. Look for an earlier DOMAIN-SUFFIX, GEOIP, or FINAL rule that may have matched first.
- Check the outbound: If the expected policy matched but the connection still failed, check DNS, the destination port, and the connection settings for the existing outbound. Don't keep broadening the domain rule.
Error: Connection refused
Cause and fix: The destination or an intermediate device may have actively refused the connection; this doesn't necessarily mean the rule syntax is wrong. Check the actual policy in the log, then verify the destination address, listening port, and existing outbound settings. For a LAN service, make sure the service is running on that port.
Error: Connection timed out
Cause and fix: The connection didn't complete in time. Possible causes include the network path, an unreachable destination, or an outbound failure. Confirm which policy matched, then check the existing service's connectivity on the same network. Don't assume a timeout means DOMAIN-SUFFIX is wrong.
These are possible connection-layer error messages, not guaranteed messages for every failure. If a request is blocked by REJECT, first check whether that matches your intent. If it was blocked by mistake, add a narrower exception before the reject rule instead of routing all traffic DIRECT.
7. FAQ and post-edit checklist
Why does a subdomain still use a proxy after I add DOMAIN-SUFFIX?
First, confirm Global Routing is set to Config on Home, then check the selected file in Config. Next, see whether an earlier DOMAIN or other rule matched the subdomain, and confirm that the actual request domain in the log belongs to the specified suffix.
Should FINAL use DIRECT or PROXY?
Choose based on how you want unclassified traffic handled. Use FINAL,PROXY to send remaining traffic through an existing proxy policy, or FINAL,DIRECT to connect directly. For the former, confirm that PROXY exists and is available. Put either rule at the end.
Will my custom rules disappear when I update a subscription?
First, identify what's being updated. Updating an outbound subscription is different from updating a remote configuration. Fetching a complete remote configuration again may replace local edits. Save a copy before updating, then check the rule section and policy names in Config afterward.
Can I use a rule to proxy only port 443 for a domain?
DOMAIN and DOMAIN-SUFFIX don't distinguish ports, so appending :443 to a domain isn't valid syntax. The examples here route by domain or address. For a port-based condition, check the supported rule types and syntax separately; changing the domain field won't do it.
- The intended configuration is selected, and Global Routing is set to Config.
- Domain rules don't include a protocol, path, or port. Separate fields with English commas.
- Specific exceptions come before broad rules, and FINAL comes last.
- Policies such as PROXY have a matching entry in the current configuration.
- After reconnecting, the actual matched policy is the one you expected.
- A recoverable copy of the configuration is saved, and the changes and test target are documented.