Shadowrocket On Demand Setup: Automatic VPN Connections by Wi-Fi, Cellular, and Domain

Learn how On Demand can connect or disconnect based on Wi-Fi names, cellular networks, or domain lookups, with example setups for home and commuting.

At a glance

This guide uses an iPhone or iPad. Use Settings → On Demand to choose when the VPN tunnel starts or disconnects, and Home → Global Routing to control traffic after the tunnel connects. Verify a manual connection first, then test home Wi-Fi, cellular, and domain conditions separately. Change only one setting at a time while testing.

1. On Demand vs. Global Routing

On Demand controls the VPN tunnel’s connection state. The system can evaluate conditions such as the current network interface or Wi-Fi name, and it also supports domain-based connection evaluation. Global Routing controls how traffic routed through Shadowrocket exits. Even when the system shows VPN as connected, a request matching DIRECT won’t be sent to a proxy server. Conversely, adding a PROXY rule to a configuration won’t start the VPN automatically when the tunnel is disconnected.

Network conditionsSystem evaluationTunnel connectionRouting matchTraffic egress

The diagram shows traffic flowing through an on-demand tunnel with rule-based routing. When you select Config under Home → Global Routing, check which configuration file is selected in Config. Proxy and Direct apply their respective global policies, while Scene routes traffic according to the selected scene. This guide uses Config throughout routing tests; don’t switch modes during testing.

2 layers
Check whether the VPN connects first, then how traffic is routed
4 cases
Global Routing:Proxy / Direct / Config / Scene

Check in order: connection status first, then traffic routing

If the system doesn’t establish a VPN tunnel when a condition is triggered, check the On Demand conditions and verify the manual connection baseline first. Don’t start by changing FINAL in Config.

2. Establish a manual connection baseline

  1. Pause automatic triggers first. Go to Settings → On Demand and temporarily turn off On Demand. On Home, select an imported node. Get nodes and subscriptions from your service provider. Keep the same node and configuration throughout testing, and don’t update subscriptions during the test.
  2. Connect manually and test access. Turn on the connection switch on Home. If prompted the first time, allow the system to add a VPN configuration. Confirm the VPN status, then open a website you normally use. If it doesn’t load, first check that the network is online, the node settings are correct, and no routing rule is matching unexpectedly. Continue setup only after those checks.
  3. Go back to Settings → On Demand and set the conditions. Note the full SSID of the current Wi-Fi network, then configure the required actions using the conditions available in your current interface. The table below is a checklist for setup and verification, not a set of rules to paste into Config.
  4. Let the system evaluate the conditions again. After saving and enabling On Demand, switch to the target network and make a new request. Record the network, VPN status, and page result. Whether a page loads by itself can’t tell you if the connection was direct, proxied, or served from cache.

3. Home and commute: Set conditions for Wi-Fi and cellular

At home, you can set your home SSID as a disconnect condition so the tunnel established during your commute doesn’t stay connected. For commuting, you can set cellular as a connect condition and handle frequently used Wi-Fi networks with clearly identifiable names separately. Here, Home-Lab and Commute-WiFi are example SSIDs. Use the full names shown on your device.

ScenarioNetwork conditionActionHow to verify
Arriving homeWi-Fi with SSID Home-LabDisconnect VPNSwitch from cellular to your home Wi-Fi and confirm that the existing tunnel disconnects.
Leaving homeCellular networkConnect VPNTurn off Wi-Fi in system settings, confirm cellular data works, then make a new request and check the VPN status.
Regular commute Wi-FiWi-Fi with SSID Commute-WiFiConnect if neededJoin the network. If it requires a web login, complete authentication before testing again.

If you configure both a specific SSID and a condition covering all Wi-Fi networks, make sure the exception for your home SSID takes precedence over the general condition. If conditions can be reordered, place specific conditions before general ones. If you can’t confirm how they’re evaluated, remove the general Wi-Fi condition for now and test only the non-overlapping home SSID and cellular conditions.

An SSID is a broadcast network name, not an authentication credential. Guest networks or hotspots with the same name may also match. If your home’s main and guest networks have different names, check each one separately. To test cellular conditions on an iPad, the device must have cellular data and it must be enabled. If you’re using a Wi-Fi-only iPad connected to a phone hotspot, test it as a Wi-Fi scenario.

4. Domain triggers vs. DOMAIN-SUFFIX

The system evaluates domain-based On Demand conditions; the VPN won’t necessarily start every time you open a URL in a browser. On iOS and iPadOS, EvaluateConnection can send matching domains for connection evaluation. For example, ConnectIfNeeded uses DNS resolution on the current network to determine whether a tunnel is needed. If the domain resolves on a regular network, the VPN not starting isn’t necessarily an error. Also, don’t treat a previously visited domain as a condition for disconnecting the VPN.

  1. First check whether the interface offers a domain-based condition. If it’s available under Settings → On Demand, enter the hostname you want to test, such as docs.example.com. Don’t enter https://, a port, or a page path in the domain field.
  2. Isolate other automatic connection conditions. Temporarily disable general conditions that connect the VPN directly on the test network, then make a new request while disconnected. Don’t just refresh an already open page: cached content or a reused connection may not trigger a new system DNS lookup.
  3. Choose the feature that matches your goal. If the current interface doesn’t offer domain-based triggers, don’t use the routing rules below as a substitute. You can establish the tunnel using network conditions, then use Config to decide whether requests should be proxied based on their domain.

For example, these two entries illustrate routing rules in the [Rule] section of Config. The first matches example.com and its subdomains; the second handles traffic that didn’t match an earlier rule. Before testing, check whether a rule earlier in the list already matches the target domain. Don’t add a new rule after FINAL.

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

5. Troubleshooting automatic connections

Why does the VPN stay connected after I get home and join Wi-Fi?

Check the current SSID in system Wi-Fi settings, then go to Settings → On Demand and confirm that its condition is set to disconnect. Temporarily remove any condition covering all Wi-Fi networks, then switch from cellular back to your home Wi-Fi. Get this condition working by itself before adding others.

Why doesn’t the VPN connect over cellular when I turn off Wi-Fi?

First confirm the device has working cellular data and that the test app is allowed to use it, then make a new request. If the VPN still doesn’t connect, pause On Demand and connect manually from Home using the same cellular network and node. If manual connection also fails, troubleshoot the network or node first. If it works, check the cellular condition again.

Why is this website using a direct connection while the VPN is connected?

Check that Home → Global Routing is set to Config, then go to Config and verify the selected file and the first rule that matches the target hostname. A website page and the hostnames it uses to load images or video may differ. Check the specific request that’s having trouble, not just the address bar.

How can I temporarily stop the VPN from reconnecting after I disconnect manually?

First turn off On Demand in Settings → On Demand, then disconnect from Home. Disconnecting only from Home doesn’t remove the automatic trigger conditions; the system may reestablish the tunnel the next time a connection condition is met. Before turning On Demand back on, verify the conditions.

Download Shadowrocket