Advanced ⏱️ 预计阅读时间:6 分钟

Routing Rules Configuration Guide

发布日期:2025-01-15 难度:Medium 最后更新:2025-01-15

This guide will help you understand and configure routing rules in Hiddify Next, enabling precise control over how different types of traffic are handled.

📚 Understanding Routing Rules

Routing rules determine which traffic goes through which proxy server or direct connection. They allow you to:

  • Route specific websites through different servers
  • Bypass proxy for local or certain international sites
  • Optimize performance by choosing appropriate routes
  • Implement complex traffic management strategies

🎯 Rule Types

1. Domain-Based Rules

Route traffic based on domain names:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Route specific domains through proxy
domain:
  - google.com
  - youtube.com
  - twitter.com

# Route domain suffixes
domain-suffix:
  - .google.com
  - .youtube.com
  - .googleapis.com

# Route domain keywords
domain-keyword:
  - google
  - youtube
  - facebook

2. IP-Based Rules

Route traffic based on IP addresses or ranges:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Specific IP addresses
ip-cidr:
  - 8.8.8.8/32
  - 1.1.1.1/32
  - 192.168.1.0/24

# Geographic IP routing
geoip:
  - US
  - JP
  - CN

3. Application-Based Rules

Route traffic from specific applications:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Process names (Windows/Linux)
process-name:
  - chrome.exe
  - firefox.exe
  - telegram.exe

# Process paths
process-path:
  - /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
  - /usr/bin/firefox

4. Port-Based Rules

Route traffic based on destination ports:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Specific ports
dst-port:
  - 80
  - 443
  - 8080

# Port ranges
dst-port:
  - 1000-2000
  - 8000-9000

⚙️ Rule Configuration

Basic Rule Structure

Each rule consists of:

  • Type: The matching criteria (domain, IP, etc.)
  • Value: The specific pattern to match
  • Policy: The action to take (proxy, direct, reject)

Rule Priorities

Rules are processed in order of priority:

  1. Process rules (highest priority)
  2. Domain rules
  3. IP rules
  4. Geographic rules
  5. Final rule (lowest priority)

🔧 Common Configuration Examples

Example 1: Basic Proxy Setup

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
rules:
  # Direct connection for local networks
  - ip-cidr,192.168.0.0/16,DIRECT
  - ip-cidr,10.0.0.0/8,DIRECT
  - ip-cidr,172.16.0.0/12,DIRECT
  
  # Proxy for blocked sites
  - domain-suffix,google.com,PROXY
  - domain-suffix,youtube.com,PROXY
  - domain-suffix,facebook.com,PROXY
  
  # Direct for everything else
  - match,DIRECT

Example 2: Geographic Routing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
rules:
  # US traffic through US server
  - geoip,US,US-Server
  
  # Japan traffic through Japan server
  - geoip,JP,JP-Server
  
  # China traffic direct
  - geoip,CN,DIRECT
  
  # Everything else through default proxy
  - match,PROXY

Example 3: Application-Specific Routing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
rules:
  # Gaming traffic direct for low latency
  - process-name,steam.exe,DIRECT
  - process-name,epicgameslauncher.exe,DIRECT
  
  # Browser traffic through proxy
  - process-name,chrome.exe,PROXY
  - process-name,firefox.exe,PROXY
  
  # Default rule
  - match,DIRECT

Example 4: Advanced Mixed Rules

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
rules:
  # High priority: Local traffic always direct
  - ip-cidr,127.0.0.0/8,DIRECT
  - ip-cidr,192.168.0.0/16,DIRECT
  
  # Streaming services through specific servers
  - domain-keyword,netflix,Streaming-Server
  - domain-keyword,disney,Streaming-Server
  - domain-suffix,hulu.com,Streaming-Server
  
  # Social media through fast server
  - domain-suffix,twitter.com,Fast-Server
  - domain-suffix,instagram.com,Fast-Server
  - domain-suffix,tiktok.com,Fast-Server
  
  # Work applications direct
  - process-name,teams.exe,DIRECT
  - process-name,zoom.exe,DIRECT
  
  # Default proxy for everything else
  - match,PROXY

🛠️ Creating Custom Rules

Step 1: Identify Traffic Patterns

Use built-in tools to analyze your traffic:

  1. Enable Connection Logs in settings
  2. Monitor which domains/IPs you frequently access
  3. Identify applications that need special routing

Step 2: Design Rule Strategy

Consider these factors:

  • Performance: Route latency-sensitive traffic optimally
  • Security: Ensure sensitive traffic uses appropriate routes
  • Compliance: Follow local regulations and policies
  • Cost: Optimize bandwidth usage across different servers

Step 3: Implement and Test

  1. Create rules in the configuration file
  2. Test with different websites and applications
  3. Monitor connection logs for rule effectiveness
  4. Adjust rules based on performance

📊 Rule Management Best Practices

1. Organization

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Group related rules together
rules:
  # === LOCAL TRAFFIC ===
  - ip-cidr,127.0.0.0/8,DIRECT
  - ip-cidr,192.168.0.0/16,DIRECT
  
  # === STREAMING SERVICES ===
  - domain-keyword,netflix,Streaming
  - domain-keyword,youtube,Streaming
  
  # === SOCIAL MEDIA ===
  - domain-suffix,twitter.com,Social
  - domain-suffix,facebook.com,Social
  
  # === DEFAULT ===
  - match,PROXY

2. Documentation

Add comments to explain complex rules:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
rules:
  # Route gaming traffic direct to reduce latency
  - process-name,steam.exe,DIRECT
  
  # Use Japan server for Japanese content
  - geoip,JP,JP-Server
  
  # Block ads and tracking (optional)
  - domain-keyword,ads,REJECT
  - domain-keyword,analytics,REJECT

3. Testing and Validation

Regular testing ensures rules work as expected:

1
2
3
4
5
6
7
8
# Test domain resolution
nslookup google.com

# Test connectivity
curl -I https://google.com

# Check current IP
curl ipinfo.io

🔍 Troubleshooting Rules

Common Issues

1. Rules Not Working

Symptoms: Traffic not routing as expected

Solutions:

  • Check rule syntax and formatting
  • Verify rule order (more specific rules first)
  • Test with connection logs enabled
  • Restart the application after changes

2. Performance Issues

Symptoms: Slow connections or high latency

Solutions:

  • Optimize rule order (put frequent matches first)
  • Reduce complex regex patterns
  • Use more specific rules instead of broad keywords
  • Monitor resource usage

3. DNS Resolution Problems

Symptoms: Websites not loading despite connection

Solutions:

  • Configure DNS servers in settings
  • Use IP-based rules for problematic domains
  • Enable DNS over HTTPS (DoH)
  • Check for DNS leaks

Debugging Tools

1. Connection Logs

Enable detailed logging:

  1. Go to Settings > Logs
  2. Enable Connection Logs
  3. Set log level to Debug
  4. Monitor real-time connections

2. Rule Testing

Test specific rules:

1
2
3
4
# Add temporary test rules
rules:
  - domain,test.example.com,PROXY,no-resolve
  - ip-cidr,1.2.3.4/32,DIRECT

3. Network Analysis

Use system tools:

1
2
3
4
5
6
7
8
# Check routing table
netstat -rn

# Monitor network connections
netstat -an | grep :8080

# Test specific routes
traceroute google.com

📈 Advanced Features

1. Rule Sets

Import external rule lists:

1
2
3
4
5
6
7
8
9
rule-providers:
  china-domains:
    type: http
    behavior: domain
    url: "https://example.com/china-domains.yaml"
    interval: 86400

rules:
  - rule-set,china-domains,DIRECT

2. Script-Based Rules

Use JavaScript for complex logic:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
function main(params) {
    const { type, hostname, port } = params;
    
    // Custom logic here
    if (hostname.includes('work')) {
        return 'DIRECT';
    }
    
    if (port === 443) {
        return 'PROXY';
    }
    
    return 'DIRECT';
}

3. Load Balancing

Distribute traffic across multiple servers:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
proxy-groups:
  - name: LoadBalance
    type: load-balance
    proxies:
      - Server1
      - Server2
      - Server3
    strategy: round-robin

rules:
  - domain-suffix,example.com,LoadBalance

🚀 Next Steps

Now that you understand routing rules:

For advanced configurations and troubleshooting, check our FAQ page or contact support.

Routing Rules Traffic Control Advanced Configuration