Practical V2Ray Routing Strategies: A Guide to Fine-Grained Traffic Splitting by Domain and IP
1. Overview of V2Ray Routing Strategies
V2Ray's routing functionality is one of its most powerful features, allowing users to direct data packets to different outbounds (e.g., direct connection, proxy, or specific nodes) based on traffic characteristics such as target domain, IP address, port, or protocol. With proper routing configuration, you can achieve the classic split-tunneling pattern: "direct for domestic traffic, proxy for foreign traffic." This reduces unnecessary proxy overhead while ensuring access speed and privacy.
2. Domain-Based Traffic Splitting
Domain-based splitting is the most common strategy, suitable for distinguishing traffic by website domain. V2Ray supports multiple domain matching methods:
- Exact domain match: Use
domain:example.comto match a specific domain exactly. - Subdomain match: Use
domain:google.comto matchgoogle.comand all its subdomains. - Keyword match: Use
keyword:googleto match any domain containing "google". - Regex match: Use
regex:.*\.googlevideo\.comto match domains matching a regular expression.
Configuration Example
"routing": {
"rules": [
{
"type": "field",
"domain": [
"domain:google.com",
"domain:youtube.com",
"keyword:facebook"
],
"outboundTag": "proxy"
},
{
"type": "field",
"domain": [
"domain:baidu.com",
"domain:qq.com"
],
"outboundTag": "direct"
}
]
}
3. IP-Based Traffic Splitting
IP-based splitting is useful when domain-based matching is not feasible, such as when applications communicate using fixed IPs or when you need to bypass specific IP ranges. V2Ray supports CIDR notation and individual IP matching.
Configuration Example
"routing": {
"rules": [
{
"type": "field",
"ip": [
"geoip:cn",
"10.0.0.0/8",
"192.168.0.0/16"
],
"outboundTag": "direct"
},
{
"type": "field",
"ip": [
"geoip:us",
"8.8.8.8"
],
"outboundTag": "proxy"
}
]
}
geoip:cn is a built-in IP database that includes all Chinese IP ranges, greatly simplifying domestic IP identification.
4. Combined Strategies and Best Practices
In production, it is recommended to combine domain and IP rules, and pay attention to rule order: V2Ray matches rules from top to bottom and stops at the first match. Therefore, place more specific rules first.
Recommended Strategy
- Direct for domestic domains: Use
domainrules to match common domestic websites. - Direct for domestic IPs: Use
geoip:cnto match all domestic IPs. - Proxy for foreign domains: Use
domainrules to match foreign websites that need proxying. - Proxy for remaining traffic: Set the default outbound to proxy, ensuring unmatched traffic goes through the proxy.
Complete Configuration Example
"routing": {
"domainStrategy": "IPOnDemand",
"rules": [
{
"type": "field",
"domain": ["domain:baidu.com", "domain:qq.com"],
"outboundTag": "direct"
},
{
"type": "field",
"ip": ["geoip:cn"],
"outboundTag": "direct"
},
{
"type": "field",
"domain": ["domain:google.com", "domain:youtube.com"],
"outboundTag": "proxy"
},
{
"type": "field",
"network": "tcp,udp",
"outboundTag": "proxy"
}
]
}
5. Common Issues and Debugging
- Rules not working: Check rule order; ensure no earlier rule matches the target traffic.
- DNS pollution: Consider using DNS resolution strategies like
domainStrategy: "IPIfNonMatch"or"IPOnDemand". - Performance optimization: Avoid excessive regex rules; prefer
domainandgeoipfor efficiency.
With fine-grained routing configuration, V2Ray becomes a powerful tool for network acceleration and secure access.
Related reading
- V2Ray Configuration in Practice: From Basics to Advanced, Building a Stable and Reliable Proxy Environment
- The Evolution of V2Ray Protocols: Balancing Performance and Security from VMess to VLESS
- VLESS Practical Deployment Guide: Building High-Performance Encrypted Tunnels in Restricted Network Environments