· Advanced · About 7 min read

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

Learn how to set On Demand rules for Wi-Fi networks, cellular connections, and domains, including rule order and common configuration mistakes.

At a Glance

This guide uses an iPhone or iPad that can already connect manually. In Settings → On Demand, set the home Wi-Fi network to disconnect and cellular to connect, then test domain-based triggers separately. Testing each step helps distinguish misconfigured conditions, a tunnel that did not connect, and traffic that was not routed as expected.

On Demand vs. Global Routing

On Demand determines when the system establishes or disconnects the VPN tunnel. Global Routing determines how traffic is handled once the tunnel is active. For example, requests processed by Config are matched against the rules in the current configuration; DOMAIN-SUFFIX matches domain suffixes, while FINAL handles requests that do not match earlier rules. Adding a domain to the rules in Config will not make the system start the tunnel when it is disconnected just because that domain is accessed.

Network or requestSystem evaluates conditionsTunnel establishedTraffic routing

The flow above shows only what happens when a connection is triggered. If the current network matches a disconnect condition, the process stops before the tunnel is established. An active tunnel also does not mean every request goes through the proxy; for example, requests matched by DIRECT in Config can connect directly.

2 types
Network interfaces covered here: Wi-Fi and cellular
1 rule
The system uses the first On Demand rule that matches the current network conditions
443
The default HTTPS port is not a domain trigger condition

Check VPN status first, then check where requests are routed

If the VPN does not connect after switching networks, check the network conditions in Settings → On Demand first. If the VPN is connected but requests are not routed as expected, go back to Home and check Global Routing.

Set up connections by Wi-Fi name and cellular network

In the examples below, the home Wi-Fi SSID is Home-WiFi. The SSID is the network name shown when your device connects—not the router's admin address, access point MAC address, or Wi-Fi password. If a dual-band network uses separate names such as Home-WiFi and Home-WiFi-5G, add each name as needed.

Disconnect on home Wi-Fi

Interface
Wi-Fi
SSID
Home-WiFi; replace with the name shown on your device
Action
Disconnect
Order
Place before Wi-Fi rules that do not specify an SSID

An SSID alone cannot verify an access point's identity; a network with the same name may also match.

Connect on cellular

Interface
Cellular
SSID
Leave unset
Action
Connect
Order
Place before general rules that do not specify an interface

When using a phone's personal hotspot, devices connected to it are still treated as using Wi-Fi.

  1. On Home, select a server and connect manually, confirming that the system has allowed the VPN configuration to be added. First use Connectivity Test to check the server, then open a webpage. Checking server connectivity and verifying webpage routing are two separate steps.
  2. Open Settings → On Demand, fill in the network conditions and actions for each rule, then enable On Demand. Put the home Wi-Fi exception before general Wi-Fi conditions. If you do not need rules for other Wi-Fi networks, do not add a connection condition that covers every interface yet.
  3. On a device with cellular service, turn off Wi-Fi, confirm cellular data is available, and make a new webpage request. Check whether the VPN connects. Then turn Wi-Fi back on, confirm you are connected to Home-WiFi, and check whether the VPN disconnects. On an iPad without cellular, test only the Wi-Fi condition.

Domain Triggers and Rule Order

Network conditions determine which On Demand rule the system uses. If a rule specifies both an interface and an SSID, both must match. When multiple rules match the current network, the first matching rule takes effect. If a Connect rule covering all Wi-Fi networks matches first, later exceptions for a home SSID and domain evaluation rules will not take effect.

Domain triggers evaluate connection requests. If the settings offer domain evaluation, configure it for the relevant network conditions rather than adding the domain to the traffic-routing rules in Config. The system's EvaluateConnection can evaluate whether to establish a tunnel based on a domain. ConnectIfNeeded does not force a connection just because that domain is accessed; for example, if DNS on the current network can resolve the destination, a domain match alone may not start the VPN.

  1. Test with a specific hostname, such as portal.example.com. This is an example; use a hostname whose access results you can verify. Enter only the hostname in the domain field—do not include https://, a port, path, or query parameters.
  2. Choose a test network and place domain evaluation before the general connection rule that matches it. If a higher-priority Disconnect rule already applies to that network, test on another network or temporarily adjust the conflicting condition. Do not expect a later domain condition to override a disconnect action that has already matched.
  3. Make sure the VPN is disconnected before testing. Then make a new request to the target domain and note the network, requested hostname, and VPN status. Next, visit a control domain that should not match on the same network. If the first test connected the VPN, restore the disconnected starting state before testing the control domain, so an existing connection is not mistaken for a second trigger.

Troubleshooting Network Changes and Domain Triggers

Why is the VPN still connected when I get home?

First, check the connected SSID in your system's Wi-Fi settings, including capitalization, spaces, and band suffixes. Then move the SSID-specific Disconnect rule above any condition covering all Wi-Fi networks, and test again by switching from cellular to your home Wi-Fi.

Why doesn't the VPN connect when I turn off Wi-Fi?

Make sure cellular data is enabled, then make a new request. If the VPN still does not connect, go to Home and test the same server manually. If that fails too, check the cellular connection or server connectivity first. If manual connection works, check that On Demand is enabled and that an earlier general condition is not overriding the cellular rule.

Why didn't entering a domain trigger the VPN when I opened a webpage?

First, confirm the domain is set as an On Demand condition, not as a Config rule. Then check whether the request went to a different hostname, such as from example.com to www.example.com. Test again with a new request, and distinguish between a condition that did not match and a destination that the current DNS could already resolve successfully.

Why did the VPN reconnect after I turned it off on Home?

Manually disconnecting the current tunnel does not disable On Demand. To keep it disconnected during testing, first turn off On Demand in Settings → On Demand, then disconnect from Home. Before restoring automatic connections, check for any test condition that applies to all networks.

Get Shadowrocket and setup guides

  • iPhone / iPad: $2.99 one-time purchase on the App Store. Check the App Store listing for system requirements.
  • Mac (Apple Silicon and Intel) / Windows / Android / Linux: Free. Choose your platform on the download page.

Get the app for your device first, then follow the Getting Started guide to make your first connection.

Download Shadowrocket for Free