· Routing · About 10 min read

V2Ray Routing Rules: Use geosite and geoip for Direct Connections in China and Proxy Routing Abroad

Learn how domainStrategy and geosite:cn and geoip:private rules work, and configure v2rayN to route traffic in mainland China directly, proxy traffic abroad, and block ads.

At a glance

This guide is for users who can already connect through a server and want to configure traffic routing in v2rayN. It explains domain and IP rule sets, how to choose a routing strategy, outbound tags, and rule order, then shows how to verify direct connections in mainland China, private network access, and ad blocking in the logs. The JSON snippets are core configuration fragments, not complete node configurations you can import as-is.

1. Check traffic flow and outbounds first

Routing takes place after traffic reaches the core. Rules won't affect an app that doesn't use the system proxy or connections not covered by the active proxy mode. Select a working server, confirm your browser is using the local proxy provided by v2rayN, then adjust the routing rules. The system proxy mainly serves apps that respect the system proxy settings; it does not capture every connection on the device.

In a rule, outboundTag identifies an outbound; it is not a protocol name. In this guide, proxy points to a configured server, direct to a freedom outbound, and block to a blackhole outbound. Tags are case-sensitive and must match the configuration exactly.

10808
Local proxy port example; replace it with your configured port
3
Outbound tags: proxy / direct / block
4 rules
Basic routing rules; unmatched traffic uses the default outbound

2. What geosite and geoip match

geosite:cn represents a domain set and is useful for matching categorized sites in mainland China. geoip:cn represents IP ranges and can handle direct IP connections or add IP-based routing after domain resolution. Both rely on rule data; neither reflects a site's business, actual server location, or current reachability. A domain associated with mainland China may use infrastructure abroad, while an overseas service may resolve to an IP in mainland China.

Domain set rules

Field
domain
China set
geosite:cn
Ad set
geosite:category-ads-all
Data files
geosite.dat

The destination domain must be available to the router, and the data file must include the specified category.

IP set rules

Field
ip
China set
geoip:cn
Private network set
geoip:private
Data files
geoip.dat

IP destinations can match directly. For domain destinations, resolution depends on the routing strategy.

Putting both domain and ip in one rule does not mean “match either the domain or the IP.” Different condition fields generally all need to match; multiple entries in the same array are alternatives. To avoid ambiguity, use separate rules for domains in mainland China and IPs in mainland China.

3. How domainStrategy affects IP-based rules for China

domainStrategy belongs inside the routing object, alongside rules. It determines whether domains are resolved to IPs for routing decisions; it does not decide whether an app uses a proxy and is not a complete DNS configuration. Outbound resolution settings with similar names belong to a different scope and are not interchangeable.

AsIs

Route using the destination as received, without resolving domains specifically for IP rules. Destinations that are already IP addresses can still match IP rules.

Best for: setups that rely mainly on domain lists and aim to minimize resolution during routing.

IPIfNonMatch

Recommended

If a domain doesn't match during the first round of rule checks, try resolving it and checking it against IP rules. This preserves the order used here: domain rules first, followed by IP rules for China.

Best for: everyday routing that sends domains in mainland China directly, with IP-based matching as a fallback.

IPOnDemand

Try to resolve a domain as soon as a routing rule requires an IP. The placement of IP rules has a more direct effect on when resolution happens and where traffic goes.

Best for: configurations that need earlier IP-based matching and have a deliberate DNS setup and rule order.

4. Order rules: ads, domains in China, private IPs, then IPs in China

Rules are checked from top to bottom; the first match determines the outbound. Put the ad category before the China domain set so domains categorized as both aren't allowed through first. Then handle domains in mainland China, private IPs, and IPs in mainland China; send everything else to the proxy by default. The snippet below shows only the routing section and must be merged into an existing complete configuration.

{
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "type": "field",
        "domain": ["geosite:category-ads-all"],
        "outboundTag": "block"
      },
      {
        "type": "field",
        "domain": ["geosite:cn"],
        "outboundTag": "direct"
      },
      {
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "direct"
      },
      {
        "type": "field",
        "ip": ["geoip:cn"],
        "outboundTag": "direct"
      }
    ]
  }
}

These rules require the corresponding outbounds to exist. Keep the existing node's authentication, transport, and security settings, and set its outbound tag to proxy; don't rewrite the node parameters just to match this example. The following two objects only demonstrate direct and block outbounds. Add them to the existing outbounds array after the proxy outbound.

[
  {
    "tag": "direct",
    "protocol": "freedom",
    "settings": {}
  },
  {
    "tag": "block",
    "protocol": "blackhole",
    "settings": {}
  }
]

5. Apply the rules in v2rayN and check the generated configuration

The v2rayN routing editor generates the core configuration, while subscriptions mainly provide node details; they serve different purposes. Menu labels may vary slightly between desktop releases. The steps below assume a UI with a “Settings” → “Routing Settings” menu. If yours differs, check the generated routing and outbounds sections.

  1. Back up your current rules

    Go to “Settings” → “Routing Settings.” Save your existing rules or export the current configuration, and note the routing scheme in use so you don't overwrite existing exceptions.

  2. Create a separate scheme

    In “Routing Settings,” create or copy a routing scheme. Set the domain strategy to IPIfNonMatch, then add separate rules for ads, domains in mainland China, private IPs, and IPs in mainland China. Don't paste the full core JSON into a single rule's domain field.

  3. Check outbound mappings

    Check the proxy, direct, or block outbound assigned to each rule. The UI may show localized labels, but each generated outboundTag must correspond to an actual outbound definition. Also check that the default outbound is the selected server.

  4. Enable and reload

    Save the scheme, set it as the active route, then restart the service or core. If you only save the scheme without enabling it, the previous routing rules may remain in effect.

  5. Check the proxy entry point

    Go to “Settings” → “Parameter Settings” and check the local listening port. This guide uses 127.0.0.1:10808 as a test entry point; use the port and inbound protocol in your actual configuration. Then check the system proxy status from the tray menu.

6. Use logs to tell rule issues from DNS issues

Change one condition at a time during testing. First visit a domain confirmed to be in the China set, then one outside it, and finally a private network address you need to reach. Temporarily enable access logs; if needed, increase error log verbosity. Check the destination and final outbound tag, then restore your usual log level when you're done.

Test the setup: check rule matches first, then troubleshoot resolution

Verify domain rules
  • A domain in the China set should use the direct outbound.
  • A test domain in the ad set should show block.
  • If the log shows only an IP, check whether the app resolved the domain itself.
  • Close existing connections and make a fresh request to avoid results from reused connections.
Verify IP rules and the default outbound
  • Confirm that private network destinations use direct.
  • Check the resolution result when a domain doesn't match the domain sets.
  • An IP match in the China set should use direct.
  • Other connections should use the first proxy outbound, not go direct unexpectedly.

The outbound shown in the log is a clearer indicator that a rule is working than whether a page loads; connectivity also depends on DNS, the server, and the destination service.

If an app resolves a domain before sending its IP to the local proxy, geosite can't see the original domain directly. Inbound sniffing may recover recognizable domain information from some HTTP or TLS traffic, but it doesn't support every protocol or encryption method. Check the current core's sniffing settings before enabling it, and don't treat sniffing as a substitute for DNS configuration.

DNS needs to be configured separately: DNS queries used for routing decisions aren't necessarily sent through the proxy automatically. If results look wrong, first check which DNS servers the core uses and how it connects to them, then decide whether to keep the IP fallback for mainland China. Before sharing troubleshooting logs, remove subscription URLs, credentials, and personal browsing records.

Download clientsv2rayN / v2rayNG