At a glance

For anyone editing V2Ray or v2rayN routing rules and wondering why traffic takes the wrong route. First check whether the core sees a domain or an IP, then choose the right match type. A subdomain exception and an expected-results table help you separate rule-order, DNS resolution, and category-data issues.

V2Ray domain rules: match a domain and its subdomains, or one host

Routing chooses an outbound for a connection. domain checks the hostname, not the full URL in the browser's address bar. For example, if the URL is https://docs.example.com:443/guide, use docs.example.com as the domain condition. To match port 443, add a separate port condition. The path /guide is not part of this match.

Domain and subdomain match: domain:

Recommended

domain:example.com matches both example.com and docs.example.com, but not notexample.com. No asterisk prefix is needed.

Use it when a site and its subdomains should share an outbound.

Exact hostname match: full:

full:docs.example.com matches only this hostname, not img.docs.example.com. To route one host separately from a broader domain rule, place this rule above it.

Use it for a single service hostname or a one-host exception.

Substring match: bare string or keyword:

A bare example matches hostnames containing that text, such as notexample.com. Xray also supports keyword:example. Don't treat bare example.com as an exact match.

Use it only when you need to match a shared string across domains and can verify the scope for unintended matches.

Regular expression match: regexp:

A regular expression describes a set of hostnames. In JSON, "regexp:^cdn[0-9]+\\.example\\.com$" matches cdn12.example.com, but not cdn.example.com. Each period has two preceding backslashes because the JSON string itself requires escaping.

Use it when hostnames follow a fixed numbering pattern that's cumbersome to list individually.

V2Ray IP and geoip rules: address ranges and when DNS resolution happens

ip checks the connection's destination IP. Use 192.0.2.10 for a single address, or CIDR notation for a range of consecutive addresses, with the number after the slash specifying the network prefix length—for example, 192.0.2.0/24. geoip:cn references a set of address ranges in the current GeoIP data. It does not match domain suffixes, and its label does not guarantee that every server's actual location matches.

/32
IPv4 single-address prefix, for example, 192.0.2.10/32
256
Number of addresses in an IPv4 /24 range; not the number of assignable host addresses
/128
IPv6 single-address prefix, for example, 2001:db8::10/128

The addresses above are documentation examples. In practice, routing may see different destinations when you access the same service by hostname versus IP. Whether the core resolves a hostname to an address for routing depends on routing.domainStrategy:

Bottom line: Don't change the IP range to work around a DNS-resolution issue

If a rule routes a raw IP as expected but not the corresponding hostname, first check whether the hostname reaches the routing stage, whether the strategy allows IP resolution for routing, and whether the resolved address falls within the range. Adjust the CIDR only after checking all three.

V2Ray geosite syntax: use category tags in domain

geosite is a tag in the domain-category data, not a JSON field alongside domain. For example, geosite:cn refers to the category named cn in the domain data. It does not mean every .cn domain and does not check DNS results. By contrast, geoip:cn refers to an IP category, so the two can produce different matches.

{
  "type": "field",
  "domain": ["geosite:cn", "full:docs.example.com"],
  "outboundTag": "direct"
}

This snippet is a rule for routing.rules, not a complete configuration. Any item in the domain array can satisfy the domain condition. If the same rule also has an ip field, both the domain and IP conditions must match. To express “match the domain category or fall within the specified IP range, then go direct,” use two separate rules that point to the same outbound tag.

V2Ray rule priority: put specific exceptions before broad rules

The core checks routing.rules in array order and selects the outbound for the first matching rule. It won't move full: ahead of domain: just because it's more specific. The examples below use two sample tags; in a real configuration, both proxy and direct must match a tag defined in outbounds.

{
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "domain": ["full:docs.example.com"],
        "outboundTag": "proxy"
      },
      {
        "type": "field",
        "domain": ["domain:example.com"],
        "outboundTag": "direct"
      },
      {
        "type": "field",
        "ip": ["192.0.2.0/24"],
        "outboundTag": "direct"
      }
    ]
  }
}
Match results based on the sample configuration; not tested against a live connection
Destination seen by routingMatching ruleSelected outbound
docs.example.comRule 1: exact hostnameproxy
img.docs.example.comRule 2: domain and subdomainsdirect
192.0.2.10Rule 3: destination IP is in rangedirect
notexample.comNo match; IP is not resolved for routing eitherDefault outbound in the configuration

If you move Rule 2 above Rule 1, docs.example.com will use direct. If no rules match, the core uses the first entry in outbounds, not the last routing rule. When checking a v2rayN configuration, distinguish the core's default outbound from an explicit fallback rule generated by the client—they may use different tags.

v2rayN routing settings: verify the active profile after saving

  1. Check which core is running

    In the v2rayN main window, confirm the selected server, apply the configuration, then check the core startup details in the main-window log. This article covers V2Ray-style JSON. If you're using Xray, check the generated core configuration instead.

  2. Open routing settings

    From the main window, go to Settings → Routing Settings and open the profile currently in use. Note the existing rule order and outbound selections before making changes. In the graphical interface, enter each item in its corresponding domain or IP field; don't paste a whole JSON block into the domain field.

  3. Change one rule at a time

    Replace the example domains with two hostnames you can access: use one as a full: exception and the other as a comparison under the same parent domain. Assign different outbounds to the exception and parent-domain rules, and place the exception first.

  4. Save and reconnect

    After saving, make sure the client has enabled the profile you just edited. Disconnect the test app's existing connections, then make two new requests. Check the destination and outbound tag in the core access log; whether a page loads can't tell you which outbound the connection used.

If neither request appears in the core access log, first make sure access logging is enabled, then confirm the test app's connections are reaching the client. The system proxy affects only apps that use it; connections that never reach the core won't use these routing rules, even if they're configured correctly.

V2Ray routing rules not working? Troubleshoot by symptom

Why does routing one page through the proxy affect the whole site?

Check whether the rule matches only the domain of the page. /guide and /status on the same host can't be distinguished with domain. If the service has a dedicated subdomain, use full: to match it. If both pages use the same hostname and port, these routing rules can't split them by path.

Why does traffic still match the broad rule when I added a full: exception?

Make sure the exception comes before the broad rule and any catch-all that could match first. Then check the access log to confirm the request actually uses that hostname. A page matching the exception doesn't mean its images, scripts, or redirect targets use the same domain.

Why does the core fail to start after I add a geosite tag?

Check the first configuration error in the log. If the category isn't found, verify the tag and the domain data currently in use. If a file can't be read, check the data directory used by the client and whether the relevant file is readable. Temporarily replace the entry with a known full: match to see whether the issue is limited to category data.

Why doesn't an IP range match when I access the same service by hostname?

Check routing.domainStrategy. With AsIs, a request that has only a hostname won't resolve an IP for range matching. With IPIfNonMatch, check whether another rule matched in the first pass. Also verify whether the core resolves the destination to IPv4 or IPv6; an IPv4-only range won't cover an IPv6 address.