V2Ray Custom Routing Rules: Domain, IP, and GeoSite Matching and Rule Order

Learn how domain, full, regexp, geosite, ip, and geoip rules differ, how rules are matched from top to bottom, and how domainStrategy affects routing.

At a glance

For readers adjusting traffic routing in v2rayN or maintaining V2Ray and Xray configurations directly. First, distinguish domain conditions from IP conditions. Then test rule order with an example you can work through, and determine whether a problem lies in the match scope, DNS resolution, or a configuration that was never loaded.

Domain rules: individual hosts, domain trees, and categories

In V2Ray and Xray routing rules, domain conditions go in the domain array. The array name and a rule prefix can both be domain, but they mean different things: the former identifies the condition type, while the latter specifies the matching method. Don’t paste in a full URL. Routing matches the hostname only—not https://, a port, or a page path.

domain: a domain and its subdomains

Recommended

domain:example.com matches example.com and img.example.com, but not notexample.com. Omitting the prefix and writing example.com instead performs a substring match, which may also include the latter.

Best for routing a specific site and its subdomains.

full: exact hostname match

full:api.example.com matches only this hostname—not the root domain or v2.api.example.com. Use it to carve out a single exception from a broader rule.

Best for a single API, test environment, or specific host.

regexp: match a hostname pattern

The JSON array entry "regexp:^img[0-9]+\\.example\\.com$" matches hostnames such as img12.example.com. The anchors at both ends require a full-string match. In JSON, two backslashes represent one backslash in the regular expression, so the dots are treated literally rather than as wildcards.

Best when hostnames follow a clear pattern, such as numbered hosts.

geosite: reference a domain category

geosite:cn references the cn category in the currently loaded domain data file. It does not match every hostname ending in .cn. Whether the category exists and which entries it contains depend on the data that was actually loaded.

Best for maintaining a group of sites from an existing dataset.

Entries in a single domain array are alternatives, not a sequence of outbound actions. To send two hosts on the same site through different outbounds, write separate rules. Don’t put them in one array expecting them to take effect in order.

IP rules: individual addresses, CIDR ranges, and GeoIP categories

The ip array matches destination IP addresses. If the connection already targets an IP, there’s no need to resolve a domain first. If it targets a hostname, whether the resolved IP can be used for matching depends on the routing strategy. The numbers below are example network prefix lengths, not speed-test results.

/32
IPv4 single-address prefix
/24
IPv4 example network prefix
/128
IPv6 single-address prefix

Takeaway: narrow the category issue down to one rule

If a site starts using a different outbound after a category update, test the hostname with full: or the actual destination IP with a single-address prefix. Validate one condition at a time. Once a temporary rule matches, check the category file and category itself—there’s no need to reorder the entire rule list first.

Rule order: the first match wins

Routing checks the rules array from top to bottom and uses the first rule that matches. A full: rule isn’t automatically moved ahead of a domain: rule just because it’s more specific. If a single routing rule specifies both domain and ip, both conditions must match. To route traffic through the same outbound when either the domain or IP matches, split the conditions into two rules.

{
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "domain": ["full:api.example.com"],
        "outboundTag": "proxy"
      },
      {
        "type": "field",
        "domain": ["domain:example.com"],
        "outboundTag": "direct"
      },
      {
        "type": "field",
        "ip": ["192.0.2.0/24"],
        "outboundTag": "direct"
      }
    ]
  }
}

This is a routing snippet, not a complete working configuration. proxy and direct must match tags in the current outbounds; the tags themselves don’t create proxy or direct outbounds. The example domains and networks are for tracing rule matches, not checking whether a service is online.

domainStrategy: when domains are used for IP matching

routing.domainStrategy controls whether the routing stage resolves a destination hostname for matching. It doesn’t determine how a direct outbound connects, and it isn’t the same as the application’s DNS settings. Seeing DNS requests doesn’t prove that an IP rule matched.

StrategyWhen resolution occursEffect on rule priority
AsIsRouting does not resolve the destination hostname to find a match.Domains are matched by name; destinations that are already IP addresses can still match IP conditions.
IPIfNonMatchIf no rule matches on the first pass, the domain is resolved and matching is tried again.If a domain condition or catch-all rule matches on the first pass, there is no second pass for IP matching.
IPOnDemandResolves the hostname as needed when a match condition requires the destination IP.An earlier IP rule can match using the resolved address before a later domain rule.

For example, if you want requests without a clear domain category to be routed by IP category, check for a rule at the end that catches all test traffic when using IPIfNonMatch. If a catch-all matches on the first pass, moving the IP rule above it alone won’t trigger another pass. Depending on your needs, use on-demand resolution or prevent the catch-all from ending matching early, and check the default outbound as well.

v2rayN troubleshooting: from the active profile to a new connection

These steps use the common Chinese-language interface in v2rayN 7.x; menu locations may vary between minor releases. Built-in routing profiles generate the core configuration, while a full custom configuration should be checked in the file that’s actually loaded. Keep a copy of the original profile before making changes so you can compare one variable at a time.

  1. Confirm the core

    Go to Settings → Parameter Settings to check the core-related options, then verify the core used by the current server entry and in the startup log. The default core setting alone isn’t enough: the entry may specify a different core, or a custom configuration may be in use. The JSON in this article follows the V2Ray and Xray format and can’t be applied as-is to cores that use a different configuration format.

  2. Edit the active profile

    Go to Settings → Routing Settings and check which profile is enabled, then verify the rule order and outbound in its rule list. Start by testing one exact-host rule. Don’t change DNS, category data, and the default outbound at the same time; otherwise, it’s hard to tell which change affected the result.

  3. Check what was loaded

    Save and apply the rules, restarting the core if needed. Look for messages about configuration parsing errors, missing categories, or mismatched outbound tags. With a custom configuration, make sure you edited the file loaded by the active entry—not an old exported copy.

  4. Test with a new connection

    Disconnect existing connections, send a new request, and check the destination and outbound details available in the logs. An app may reuse a connection or resolve the hostname itself and pass the IP to the inbound. In that case, a domain rule not matching doesn’t mean the rule order is wrong. First confirm that the traffic reached the core, then check whether routing saw a hostname or an IP address.

For a full reference of the fields, see the routing configuration reference and DNS configuration reference. If only some apps behave differently, first compare how they connect and whether they use hostnames or IP addresses, then decide whether to adjust the domain strategy.

Download v2rayNView platforms and installers