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

Learn V2Ray domain, IP, geosite, and geoip matching, rule order, and examples for direct, proxy, and block outbound routes.

At a glance

For readers who can already connect with v2rayN and want to change the outbound route for specific sites. First, determine whether the core receives a domain or an IP address, then use specific rules to override broader ones. Use the config examples to check rule order, and troubleshoot by checking the request entry point, matching rule, and outbound route.

Domain matching: use full first, then consider domain

domain is both a rule field and a matching prefix. In the domain array, full:api.example.org matches only that hostname, while domain:example.org matches the root domain and its subdomains. Both match the domain only, not URL paths or query parameters. Don’t paste in a full URL like https://api.example.org/login.

full: Match one hostname

Recommended

full:api.example.org matches api.example.org, but not dev.api.example.org. This is the easiest rule to verify when changing the route for a single hostname.

Best for: Routing one API endpoint or test site separately.

domain: Match a domain and its subdomains

domain:example.org matches example.org and img.example.org, but not notexample.org. A bare example.org uses substring matching and is not equivalent.

Best for: Routing a domain and all its subdomains through the same outbound.

regexp: Match with a pattern

regexp:^img[0-9]+\.example\.org$ matches img12.example.org, but not img.example.org. In a JSON string, write each \. as \\. so the regex received by the core retains its backslash.

Best for: Matching a group of hostnames with numbered labels.

Test exceptions against neighboring domains

After adding an exception for one endpoint, test another endpoint under the same domain. The first should use the new outbound; the second should keep its original route. Testing only the exception won’t reveal whether the rule is too broad.

IP, geosite, and geoip: Know what each one matches

The ip array accepts a single address or a CIDR range. For example, 192.0.2.10/32 covers one IPv4 address, while 192.0.2.0/24 covers the entire example subnet. Choose based on whether you need to match one host or a range of addresses. These documentation-only addresses can’t be used to test public reachability.

FieldMatch valueWhat it matches
domaingeosite:cnDomain patterns in the cn group in the current geosite.dat.
ipgeoip:cnIP ranges in the cn group in the current geoip.dat.
ip192.0.2.10/32A specific destination IP, without relying on geographic data files.
port"443"The destination port, not the local proxy listening port. It cannot identify the application protocol on its own.

The fact that both groups are named cn doesn’t mean they’re equivalent. A site can appear in the domain group but be served by a CDN address that isn’t in the corresponding IP group. The same CDN address may also serve multiple domains. To route a specific site, use a domain rule; use CIDR or geoip when you need to match an address range. If adding a list prevents the core from starting, check the filename and group name in the error, then confirm that the data file loaded by the current core contains that group.

Rule priority: the first match wins

The core checks rules in the order they appear in the routing.rules array; it won’t automatically move more specific rules to the top. Within a rule, any matching item in the domain array satisfies the domain condition. But if that rule also specifies port, the port must match too. Likewise, putting domain and ip in the same object does not mean “either one.” To route on either condition independently, use two rules.

1
In this example, the block rule is checked first
443
Destination port specified by rule 4
/32
Rule 3 matches a single IPv4 address

This is the routing section of a complete configuration, not a subscription link. First, confirm that the actual config has outbound tags named direct, proxy, and block. In a hand-written V2Ray or Xray config, direct routing usually uses freedom, blocking uses blackhole, and proxy routing references an existing node outbound. A tag is a name, not a protocol. If your client uses different tags, use the ones in your config.

{
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "domain": ["full:ads.example.test"],
        "outboundTag": "block"
      },
      {
        "type": "field",
        "domain": ["domain:example.test"],
        "outboundTag": "direct"
      },
      {
        "type": "field",
        "ip": ["192.0.2.10/32"],
        "outboundTag": "direct"
      },
      {
        "type": "field",
        "domain": ["domain:example.org"],
        "port": "443",
        "outboundTag": "proxy"
      },
      {
        "type": "field",
        "network": "tcp,udp",
        "outboundTag": "direct"
      }
    ]
  }
}

domainStrategy: When to resolve a destination domain to an IP

If geoip doesn’t match as expected, first check what destination the routing stage sees. An app may pass a hostname to the local proxy, or resolve it first and pass only the destination IP. Unless the entry point obtains a usable domain through traffic sniffing or another method, a request containing only an IP can’t match domain rules. Conversely, receiving a domain doesn’t mean it will necessarily be resolved during routing.

Before changing anything, decide whether to route by the hostname being accessed or by the address it resolves to. For hostnames, start with AsIs and specific domain rules. For IP addresses, check the strategy, DNS results, and rule order together. Don’t infer routing from whether a page loads: a successful page load only means at least some connections worked.

Edit and test a routing rule in v2rayN

  1. Record the current setup

    From the main window, open “Settings” → “Routing Settings.” Note the active profile, its first rule, and its last rule; keep a backup if you have one. Subscription updates refresh nodes—they’re not where you edit local routing rules.

  2. Add a specific exception

    Edit the routing profile currently in use. Enter a known, reachable test hostname in the domain condition, such as full:example.org, and choose the intended outbound. Place the rule before any group rule or catch-all that covers the hostname. The UI edits rule fields; don’t paste a complete core JSON config into the domain field.

  3. Apply and verify

    After saving, return to the main window and confirm that the edited profile is still selected. Check the core log for load errors. The edit button may be in a different place in different versions. With a full custom config, don’t assume the profile selected in the UI overrides routing defined in that config.

  4. Start a new connection

    Test the exception domain first, then a domain that should use the default route. If you have a local SOCKS entry point, use the command below to send the hostname to the proxy explicitly. 10808 is only the listening port in this example; use the value from your current local config. If access logging is enabled, match the outbound tag to the request time and destination. Review the results before changing another rule.

curl.exe --socks5-hostname 127.0.0.1:10808 -I https://example.org/

This command uses Windows curl.exe. --socks5-hostname sends the domain through the SOCKS entry point, making it useful for testing domain matching. With --socks5, the command-line tool generally resolves the domain first, changing what you’re testing. Getting an HTTP response doesn’t prove the request used the proxy outbound; check the core log too. The same applies when testing a block rule: an error alone can’t tell you whether the request was blocked, DNS resolution failed, or the destination was already unreachable.

FAQ: Why didn’t my routing rule match?

I made the full rule more specific. Why is traffic still using the old outbound?

Check for an earlier rule covering the same hostname, such as domain:, geosite:, or a TCP/UDP catch-all. Move the full: exception above those rules, save, start a new connection, and check the access log. Existing connections won’t switch outbounds when you change rule order.

The address is in the range. Why didn’t geoip match?

Use the same test program to submit a domain and a numeric IP separately, then check the destination recorded in the log. With AsIs, it’s normal for the IP to match while the domain doesn’t. If neither matches, check the actual data group and any earlier rules. Don’t replace your entire DNS setup just to test one rule.

Why won’t the config start after I changed the geosite data file?

Find the reported group and filename in the startup log. If the new file lacks that group, restore the original data or replace the rule temporarily with a few specific full: or domain: entries, then confirm the core starts before adding the list again. A file loading successfully doesn’t guarantee that a group with the same name has exactly the same contents as in an older version.

The command-line test works, but nothing changes in the browser. Why?

First confirm that browser requests are reaching the same local entry point, then test with a new connection. Check whether the destination hostname appears in the log. If only other hostnames appear, open the browser’s “Network” panel in developer tools and check the destinations requested by redirects and subresources. Troubleshoot each request, not the page as a single domain.

View client downloads