Custom V2Ray Routing Rules: Domain, IP, GeoSite Syntax and Priority

Learn how domain, full, regexp, IP, GeoSite, and GeoIP rules work, how rules are matched from top to bottom, and how to resolve common conflicts.

At a glance

This guide is for readers configuring routing in v2rayN or reviewing Xray and V2Fly configs directly. Learn to distinguish domain names, destination IPs, and data sets, then walk through a sample config to check exceptions, outbound tags, and when DNS resolution occurs. Even if a test site won’t load, logs can show which outbound handled the request.

domain, full, and regexp: How domain rules match

In core JSON, domain is a rule field, while domain: is one of its matching prefixes. The domain field matches hostnames, not full URLs. Remove https://, ports, paths, and query parameters from your rules; these rules can’t route two pages on the same host differently.

domain: Match a domain and its subdomains

Recommended

domain:example.com matches example.com and api.example.com, but not notexample.com. Matching respects domain-label boundaries; it isn’t an arbitrary suffix match.

Best for: Sending an entire site and its subdomains through the same outbound

full: Match one exact hostname

full:api.example.com matches only this hostname. It doesn’t match example.com or v2.api.example.com. For a single host, there’s no need to write a regular expression.

Best for: Exceptions for login, API, or static asset hosts

regexp: Match a hostname pattern

The regular expression ^img[0-9]+\.example\.com$ matches img1.example.com, but not img.example.com. In JSON, escape each backslash by writing it twice: "regexp:^img[0-9]+\\.example\\.com$".

Best for: Numbered hostnames that follow a pattern, without matching the entire domain

A bare example.com string in core JSON uses substring matching, so it may also match notexample.com. If a rule matches too broadly, check whether its prefix is missing, then check that your regular expression has start and end anchors and doesn’t treat dots as wildcards. When using a client editor, also verify that the generated core config matches what you entered.

ip, geosite, and geoip: Addresses vs. data sets

ip matches the request’s destination IP, not the server address of a proxy node. Don’t use this field to route by source address. geosite: belongs in the domain array; only geoip: belongs in the ip array. Both prefixes refer to categories in local data files, not online lookups.

ItemCore syntaxWhat it matches
Single address"ip": ["192.0.2.10"]Checks one destination address; useful for testing an individual address rule.
CIDR range"ip": ["192.0.2.0/24", "2001:db8::/32"]The prefixes shown cover documentation ranges for IPv4 and IPv6; replace them with the ranges your policy actually uses.
Domain set"domain": ["geosite:cn"]Uses entries from geosite.dat; it does not match every domain ending in .cn.
IP address set"ip": ["geoip:cn"]Checks whether the destination IP falls within an address range in the corresponding geoip.dat category.

Category names and contents can vary between data file versions and sources. If the core reports that a category can’t be loaded after you import a rule, first check which file is actually loaded and whether the category name exists; changing rule order won’t help. A domain’s inclusion in a site category also doesn’t mean its current resolved address belongs to the corresponding IP category. CDNs, dual-stack connections, and changing DNS results can all account for differences.

Rule priority: Put exceptions before broad rules

routing.rules are checked from top to bottom, and the first match selects the outbound. A full: rule doesn’t automatically take precedence over domain: just because it’s more specific. Within one rule, different condition fields such as domain and ip must all match; multiple entries in the same domain array are alternatives. To match a specified domain or a specified IP, use two rules that point to the same outbound.

The Xray config below uses a local SOCKS inbound. direct and reject are custom outbound tags mapped to freedom and blackhole, respectively. These are tags, not protocol names, and can’t be replaced with a node’s display name. The example uses reserved domains and documentation addresses, so it doesn’t depend on a subscription or regional data files.

{
  "log": {"loglevel": "info"},
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 10808,
      "protocol": "socks",
      "settings": {"auth": "noauth", "udp": true}
    }
  ],
  "outbounds": [
    {"tag": "direct", "protocol": "freedom"},
    {"tag": "reject", "protocol": "blackhole"}
  ],
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {"type": "field", "domain": ["full:api.example.com"], "outboundTag": "direct"},
      {"type": "field", "domain": ["domain:example.com"], "outboundTag": "reject"},
      {"type": "field", "ip": ["192.0.2.0/24"], "outboundTag": "reject"},
      {"type": "field", "network": "tcp,udp", "outboundTag": "direct"}
    ]
  }
}
10808
Example SOCKS inbound port
4 rules
Total sample rules, including the final catch-all
192.0.2.10
Documentation address matched by rule 3

Takeaway: Check for rule shadowing with a pair of targets

After adding an exception, test both the exception host and a regular host in the same domain. Add broader regional rules only after the two hosts use different outbounds as expected. If they use the same outbound, first check for an earlier rule with a wider match.

domainStrategy: When domain names are checked against IP rules

For requests to a literal IP, the core can compare addresses directly. For requests using a domain name, whether routing resolves it first depends on routing.domainStrategy. This is separate from the DNS lookup made to establish a connection after an outbound is selected. Changing the routing strategy doesn’t change your DNS server or guarantee that the client passes the domain to the core.

To prioritize domain rules and try IP rules only for unmatched domains, use IPIfNonMatch, remove any trailing catch-all that would match too early, and put the intended default outbound first in outbounds. Test both domain-name and literal-IP inputs before and after the change. If the app resolves the domain before passing it to the core, this setting can’t recover the original hostname from the IP.

v2rayN routing settings: Save, switch, and verify

This section uses the desktop version of v2rayN with Xray routing. The editing window and enable controls may differ between versions. The full JSON above is a standalone example: don’t paste it into a single rule’s domain field or overwrite a config generated from an existing subscription.

  1. Keep a copy of the current setup

    From the main window, open Settings → Routing settings and note the active profile and existing rule order. Before editing a profile, save a copy of its rules. If testing fails, switch back to the original profile; there’s no need to import the subscription again.

  2. Enter each condition separately

    In the rule editor for the profile you’re testing, add full:api.example.com and domain:example.com as separate rules in the domain field, not the IP field. Assign a different outbound to each and put the single-host exception before the whole-domain rule.

  3. Enable the profile you’re testing

    After saving, confirm that the test profile is active; opening its editor isn’t enough. If v2rayN generated the rules, choose an outbound in the UI instead of copying the example’s reject tag. For a hand-written config, make sure the outboundTag exists.

  4. Check the core logs

    Send two separate requests through the actual local SOCKS port. The example uses port 10808. With curl, run curl --proxy socks5h://127.0.0.1:10808 --max-time 5 https://api.example.com/, then repeat with img.example.com. Check the destination and outbound in the core access logs; whether a documentation-domain webpage loads doesn’t prove which rule matched.

Common conflicts: The rule looks right, but the outbound isn’t

Why does traffic still use the whole-domain rule after adding full?

Move the single-host rule above the whole-domain rule, and check for an earlier geosite: rule that includes the host. Save and enable the correct profile, then make a new connection and check the outbounds for both the exception host and a regular host in the same domain.

Why does a literal IP match, but its domain name doesn’t?

First check the logs to see whether the core received a domain name or an IP address. If it received a domain, check domainStrategy. With IPIfNonMatch, check whether a catch-all or another domain rule matched in the first pass. If it received an IP, verify that the address falls within the range, and make sure you aren’t comparing an IPv6 address against an IPv4 range.

Why won’t the core start after I add a GeoSite rule?

Check the startup logs to see whether the data file is missing or the category name can’t be found. Verify the geosite.dat file actually used by the current core, not a file with the same name in another config directory. As a temporary test, replace the category with an explicit domain rule that serves the same purpose and check whether the outbound and rule order work.

Why do the browser and command-line results differ?

First confirm that both use the same local inbound. With socks5h, curl passes the domain name to the SOCKS proxy. Your browser may use different proxy settings, connect directly, or reuse an existing connection. Start a new request and compare its destination and timestamp in the logs so you don’t mistake an old connection for the result of a new rule.

Download v2rayN