Custom V2Ray routing rules: domain, ip, and geosite syntax and rule order

Learn how to write domain, full, regexp, IP, and geosite rules, how rules are matched from top to bottom, and when to route traffic through a proxy, connect directly, or block it.

At a glance

For users who have already connected with v2rayN and want to route traffic based on its destination. Start by distinguishing individual hosts, domain groups, and IP ranges, then place exceptions before broader rules. Finally, check the core logs to confirm that traffic reached the client and identify the outbound it selected.

Domain rules: exact matches, suffixes, and rule sets

domain is both a routing-rule field and a matching prefix used within that field. The field specifies that the rule matches on a domain; an entry beginning with domain: matches a domain suffix. Enter a hostname without a scheme, port, or path. Domain conditions cannot distinguish between two web directories on the same host.

What each domain entry matches
EntryMatches
full:portal.example.orgMatches this host only, not its subdomains.
domain:example.orgMatches the root domain and its subdomains, but not notexample.org.
regexp:^api[0-9]+\.example\.org$Matches api12.example.org, but not api.example.org. Escape each backslash when writing the value in a JSON string.
geosite:cnReferences the group named cn in the loaded geosite.dat; it does not match every domain ending in .cn.

Use full: to match a single login host. Use domain: to cover login, API, and static-asset subdomains under the same domain. Don’t use a bare string for an exact match: in standard domain rules, bare strings match substrings and can unintentionally include other hosts containing the same text. Rule sets are useful for managing large lists, but available group names and their contents depend on the data file loaded by the client.

IP rules: addresses, ranges, and resolution strategy

ip matches the connection destination—not your local network adapter’s source address or the proxy server’s address. For internal services that accept only IP addresses, route by individual address or range. When connecting by domain, the result also depends on when the core resolves the address for routing.

Rule order and outbound selection

Rules are evaluated from top to bottom, and the first rule that satisfies all its conditions determines the outbound. The system won’t move a full: entry ahead of a domain: entry just because it’s more specific. The example below shows a routing.rules array. direct, block, and proxy must match outbound tags already defined in your configuration; adding these rules won’t create the outbounds for you.

[
  {"type":"field","domain":["full:portal.example.org"],"outboundTag":"direct"},
  {"type":"field","domain":["full:retired.example.org"],"outboundTag":"block"},
  {"type":"field","domain":["domain:example.org"],"outboundTag":"proxy"},
  {"type":"field","ip":["192.168.50.0/24"],"outboundTag":"direct"},
  {"type":"field","network":"tcp,udp","outboundTag":"proxy"}
]

Move the domain rule on the third line to the top, and it will match portal.example.org and retired.example.org before the other rules. The final network condition is an explicit fallback for TCP and UDP; keep it after the exceptions. Without an explicit fallback, if no rule matches, the core typically uses the first outbound in the configuration. Don’t assume that an unmatched connection will go direct.

Connect directly to a known private network

Recommended

Start by testing a known internal service address. Direct connections still rely on your local network routing; they can’t make an otherwise unreachable private range accessible.

Best for: printers or internal admin pages your computer can access directly

Proxy selected destinations

Send the destination through the configured proxy outbound. A proxy match confirms that routing selected the intended outbound, but the connection can still fail due to DNS errors or timeouts.

Best for: services that must use the proxy outbound

Block specific destinations

Send confirmed unwanted hosts to a block outbound. Test with an exact hostname first to avoid blocking login or resource hosts that share a suffix.

Best for: decommissioned service endpoints or temporarily checking whether a rule matches

Test rule order by moving just one rule

Keep the inbounds and outbounds unchanged. Move an exact rule for the test host above the broader rule, then close the existing connection and try again. If the selected outbound changes, there’s no need to switch servers or change DNS first.

Add and test rules in v2rayN

The steps below use the routing interface commonly found in v2rayN 7.x and Xray fields as examples. Menu names may differ in other versions. A full core configuration and a single rule entered in the graphical interface use different import formats. When editing one rule, don’t paste a configuration wrapped in a routing object where a domain list is expected.

  1. Open routing settings

    In the main window, select Settings → Routing settings. Note the currently active profile and keep it as a rollback option, then select the profile you want to edit from the routing list.

  2. Add an exact-match rule

    Open the profile’s rule editor, add a full: domain rule, and select its target outbound. Replace the example domain with a host you can actually reach. If you’re testing an IP destination, enter only the IP condition.

  3. Set the order and enable the profile

    Place the new rule above any suffix, rule-set, or broad rule that would otherwise match it. After saving, return to the main window and confirm that Routing is set to the profile you edited. Saving a configuration and switching the active profile are separate steps.

  4. Start a new connection

    Visit the target host, then visit a comparison host that should use a different outbound. If the app supports manual proxy settings, point it to the local listening address shown by the client. For example, if the active configuration uses 127.0.0.1:10808, make sure the app’s selected proxy protocol matches that inbound. Don’t assume this port is the same for every installation.

  5. Check the outbound in the logs

    In the core access logs, check the destination and outbound tag for both requests, then confirm whether each connection succeeded. Browsers may reuse existing connections, so quit and reopen the browser before testing a rule change; refreshing a tab may not create a new connection.

Troubleshooting rules with logs

Why is traffic still going through the proxy after I saved the rule?

First, confirm the log shows a newly initiated connection to the intended destination, then check the active profile and rule order. If an earlier geosite entry already matches the host, move the full: exception above it. A page redirect may contact a different host, so use the actual destination shown in the logs.

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

Check the startup log to determine whether the data file is missing or the group name can’t be found. Temporarily disable the new entry to see whether the core starts, then verify which data file the current core loads and which group names it contains. For just a few hosts, use explicit domain entries instead of a group.

Why didn’t the domain rule match when the logs show only an IP?

The app may resolve the address first and pass only the IP to the client. The routing resolution strategy won’t reverse-resolve that IP to recover the original domain. Retest with an app that can send the hostname to the proxy. If the connection is initiated using only an IP, add the corresponding IP condition and check whether the address is stable.

Why does one app appear in the logs but not another?

First, make sure access logging is enabled. The system proxy affects only apps that follow that setting; other apps may connect directly. Check whether the app has its own proxy settings. If you’re using TUN, check whether traffic to the destination is entering the virtual network adapter. If traffic never reaches the core, changing rule order won’t affect the outcome.

Download v2rayN