Xray Routing Engine: Build a Zero-Leak, High-Performance Proxy System in Minutes | Brav

Xray Routing Engine: Build a Zero-Leak, High-Performance Proxy System in Minutes

Table of Contents

TL;DR

  • Master Xray’s split-second routing engine and split tunneling for bandwidth savings.
  • Configure multiple inbounds/outbounds for fault tolerance and privacy.
  • Block ads at the proxy level with geosite and catch-all rules.
  • Secure DNS traffic and avoid leaks with encrypted DNS outbound.
  • Quick steps to test, monitor, and keep the configuration up to date.

Why This Matters

I once had to keep my office’s finance portal working while evading a deep-packet inspection firewall that flagged all my traffic as a single fingerprint. The result? Every request was logged, and my ISP knew I was hitting a banking site, even though I was technically inside the corporate VPN. That pain point—consistent encrypted traffic to a single endpoint 24x7 appears as a pattern, not a person Xray — Routing Engine Overview (2023) Cloudflare — Next-Gen Firewall DPI Overview (2023).

The reality is that single tunnel fingerprinting by DPI is a fast way for deep-packet inspection firewalls to identify you, and DNS leaks expose visited sites ExpressVPN — What is a DNS Leak? (2023). These are the very issues that Xray is built to solve: split tunneling for bandwidth, ad blocking without heavy performance hit, and DNS privacy.

Core Concepts

Xray’s routing engine is like a traffic director in a busy city.

  • Inbounds are the city’s entry points (socks, http, etc.).
  • Outbounds are the roads (Shadowsocks tunnels, direct link, blackhole).
  • Tags are labels on cars so the director knows where they’re supposed to go.
  • Rules are traffic lights that decide the car’s path.

Mental Model: think of each inbound tag as a “car type.” Each rule is a “traffic light” that matches on domain, IP, protocol, or port.

Domain-Based Routing

The domainStrategy setting tells Xray whether to look at the domain string (AsIs), resolve it to IP only when a rule fails (IPIfNonMatch), or resolve it before the first rule (IPOnDemand). The IPOnDemand strategy is the fastest because it avoids DNS lookups for traffic that will hit a rule early in the list.

GeoIP and Geosite

Geosite files like geosite.dat contain human-readable categories such as google.com or facebook.com. GeoIP files like geoip.dat list IP ranges per country. Xray can match traffic against these categories:

  • geosite:ads-all blocks 145,000 ad domains.
  • geosite:cn routes domestic traffic to a Chinese server.
  • geoip:private matches private IP ranges that should never leave the LAN.

DNS Outbound

DNS traffic is automatically tagged so you can route it differently from HTTP. A secure, encrypted DNS outbound (e.g., Cloudflare 1.1.1.1) eliminates leaks.

The Catch-All Rule

The catch-all rule (***outboundTag: "direct") is the default path when no rule matches. It must be the last rule; otherwise, more specific rules are never reached.

ParameterUse CaseLimitation
inbound tagIdentifies source traffic and links to outbound via routing rulesMust match a rule, otherwise falls to catch-all
outbound tagLabels the destination proxy; only one tag per outboundToo many tags can increase memory usage
rule orderDetermines which rule fires first (first match wins)Overlap can lead to unexpected routing
catch-all ruleProvides a default path when no rule matchesIf placed too early, it overrides specific rules
DNS strategyControls when domain names are resolved (IPOnDemand is fastest)Wrong strategy can cause latency or leaks

Xray — Routing Engine Overview (2023)

How to Apply It

Below is a step-by-step recipe that turns the theory into a running Xray server with two Shadowsocks outbounds, DNS protection, ad blocking, and split tunneling.

1. Install Xray and 3x-UI

# On Ubuntu
sudo apt update
sudo apt install -y wget
wget https://github.com/XTLS/Xray-core/releases/latest/download/xray-linux-64.zip
unzip xray-linux-64.zip
sudo mv xray /usr/local/bin/

Download 3x-UI for the web UI:

wget https://github.com/MHSanaei/3x-ui/releases/latest/download/3x-ui-linux-amd64.tar.gz
tar -xzf 3x-ui-linux-amd64.tar.gz
sudo mv 3x-ui /usr/local/bin/

Run 3x-UI and set an admin password. The panel will automatically generate a JSON configuration that you can export and tweak.

The 3x-UI web panel lets you export inbound parameters and view the underlying configuration 3x-UI Xray Configuration DeepWiki (2023).

2. Configure Inbounds

Two inbound sockets are enough for most setups: a socks5 listener for LAN devices and an http listener for local web apps.

"inbounds": [
  {
    "port": 1080,
    "listen": "0.0.0.0",
    "protocol": "socks",
    "settings": {}
  },
  {
    "port": 1081,
    "listen": "0.0.0.0",
    "protocol": "http",
    "settings": {}
  }
]

The GUI automatically tags these as socks-inbound and http-inbound.

3. Configure Outbounds

The Shadowsocks encryption method is chacha20-ietf-poly1305, the strongest AEAD cipher available in Xray Shadowsocks — Encryption Methods Quick Guide (2023).

"outbounds": [
  {
    "tag": "ShadowDE",
    "protocol": "shadowsocks",
    "settings": {
      "servers": [
        {
          "address": "de.example.com",
          "port": 8388,
          "method": "chacha20-ietf-poly1305",
          "password": "examplepass"
        }
      ]
    }
  },
  {
    "tag": "ShadowNL",
    "protocol": "shadowsocks",
    "settings": {
      "servers": [
        {
          "address": "nl.example.com",
          "port": 8388,
          "method": "chacha20-ietf-poly1305",
          "password": "examplepass"
        }
      ]
    }
  },
  {
    "tag": "direct",
    "protocol": "freedom",
    "settings": {}
  },
  {
    "tag": "block",
    "protocol": "blackhole",
    "settings": {}
  }
]

4. Secure DNS

"dns": {
  "servers": [
    {
      "address": "1.1.1.1",
      "port": 53,
      "domains": ["geoip:private"],
      "tag": "dns-proxy"
    }
  ],
  "strategy": "IPOnDemand",
  "useIPv6": false
}

The dns-proxy outbound ensures that all DNS queries go through Cloudflare and never leak to the local ISP.

5. Build Routing Rules

"routing": {
  "domainStrategy": "IPOnDemand",
  "rules": [
    {
      "type": "field",
      "domain": ["geosite:ads-all"],
      "outboundTag": "block"
    },
    {
      "type": "field",
      "domain": ["geosite:cn"],
      "outboundTag": "ShadowDE"
    },
    {
      "type": "field",
      "domain": ["geosite:global"],
      "outboundTag": "ShadowNL"
    },
    {
      "type": "field",
      "protocol": ["http", "tls", "quic"],
      "port": "53",
      "outboundTag": "dns-proxy"
    },
    {
      "type": "field",
      "sourceIP": ["10.0.0.0/8"],
      "outboundTag": "direct"
    },
    {
      "type": "field",
      "inboundTag": ["socks-inbound", "http-inbound"],
      "outboundTag": "direct"
    }
  ]
}

The ad blocker rule should be placed at the top to catch ad traffic early Xray — Routing Engine Overview (2023). The catch-all rule should be last in the routing rule set Xray — Routing Engine Overview (2023).

6. Launch and Test

sudo systemctl start xray
sudo systemctl enable xray

Test with curl:

curl -x socks5://127.0.0.1:1080 https://example.com

Check the access log (/var/log/xray/access.log) for blocked domains. To verify DNS protection, visit a DNS-leak-testing site while the VPN is active. The IP should match the DNS server, not your ISP.

7. Keep Geosite Updated

Xray ships with geosite.dat and geoip.dat. To keep them current:

sudo xray -update-geosite
sudo xray -update-geoip

Or automate with a cron job:

0 2 * * * /usr/local/bin/xray -update-geosite && /usr/local/bin/xray -update-geoip

8. Monitoring

Enable access logs in the config:

"log": {
  "access": "/var/log/xray/access.log",
  "error": "/var/log/xray/error.log"
}

These logs let you spot unexpected routing or blocked traffic in real time.

Pitfalls & Edge Cases

ProblemWhy It HappensFix
Single tunnel fingerprintingAll traffic to one proxy looks identical to DPIUse multiple outbounds (ShadowDE, ShadowNL) and split tunneling
DNS leaksDNS requests go to the system resolverRoute DNS through an encrypted outbound (dns-proxy)
Mis-ordered rulesA catch-all rule early in the list overrides othersKeep the catch-all rule at the bottom
Over-blockingThe geosite:ads-all rule blocks legitimate contentPlace the ad blocker after a “safe” rule if needed
Performance hitRouting all traffic through a single remote proxyUse split tunneling and a local direct outbound for LAN
Protocol supportUDP traffic (e.g., gaming) is ignored by defaultAdd udp to the network field in inbound/outbound config
Remote DNS blockedCloudflare 1.1.1.1 is blocked by local firewallSwitch to a local DNS server or a different public resolver

Quick FAQ

QA
What is Xray?Xray is an open-source proxy core that supports multiple protocols (VMess, VLESS, Shadowsocks, etc.) and offers fine-grained routing, encryption, and anti-fingerprinting.
How does Xray compare to Tor for anonymity?Xray excels at censorship circumvention but does not scramble your identity the way Tor does. For true anonymity, use Tor or a multi-hop Tor-like path.
How do I keep geosite.dat up to date?Run xray -update-geosite daily or use the cron job above; the latest geosite file is available from the Xray project’s releases.
What is the IPOnDemand DNS strategy?It resolves domain names to IPs before rule evaluation, which reduces DNS lookups for traffic that will match early rules, improving latency.
What if the remote DNS server is blocked?Configure a local DNS resolver (e.g., dnsmasq) and route DNS traffic to it; add it as a fallback server in the DNS section.
Can Xray handle UDP traffic like gaming or VoIP?Yes—add "network": ["tcp", "udp"] to the inbound/outbound settings or create separate UDP inbounds.

Conclusion

I’ve spent years wrestling with DPI, DNS leaks, and ad-blocking in corporate environments. Xray’s routing engine turns those battles into a set of declarative rules that are easy to tweak and monitor. By following the steps above, you can:

  • Keep your internal traffic out of the public eye without a heavy bandwidth hit.
  • Block unwanted ads at the proxy layer instead of on the client.
  • Avoid DNS leaks with an encrypted outbound.
  • Scale with multiple outbounds and split tunneling.

If you’re a network administrator or security engineer looking to reduce a single point of failure and keep traffic pattern hidden, Xray is the tool that turns the impossible into routine.

The goal isn’t to hide everything behind the proxy; the goal is to look like you are not hiding anything. Xray — Routing Engine Overview (2023).

References

Last updated: January 12, 2026

Recommended Articles

I Built a Plug-Flow Rainwater Generator That Lights LEDs With 6 kV – A Step-by-Step Demo | Brav

I Built a Plug-Flow Rainwater Generator That Lights LEDs With 6 kV – A Step-by-Step Demo

Learn how to harvest rainwater into electricity with a plug-flow tube and build a DIY generator that powers LEDs, ideal for makers, hobbyists, and educators.
I Built Kai: A Personal AI Infrastructure That Turned My 9-5 Into a Personal Supercomputer | Brav

I Built Kai: A Personal AI Infrastructure That Turned My 9-5 Into a Personal Supercomputer

Discover how I built Kai, a personal AI infrastructure that turns scattered tools into a single context-aware assistant. Build websites, dashboards, and more in minutes.
Mastering agents.md: Build Long-Running AI Sessions That Never Forget | Brav

Mastering agents.md: Build Long-Running AI Sessions That Never Forget

Learn how to design lightweight root agents.md files and use JIT context indexing to keep AI agent sessions long, token-efficient, and on-track.
Deploying a 3CX PBX: From Zero to Hero in 2025 | Brav

Deploying a 3CX PBX: From Zero to Hero in 2025

Set up a 3CX PBX on Windows or the cloud, configure SIP trunks, forward ports on pfSense, and use ring groups for a low-cost, scalable phone system.
How I Built a RAG Agent That Stops Hallucinations With Source Validation | Brav

How I Built a RAG Agent That Stops Hallucinations With Source Validation

Learn how to build a RAG agent with source validation using CopilotKit and Pydantic AI. Stop hallucinations, add human approval, and sync in real time.
Building a Fourth Dimension: How Quantum Hall Experiments Let Us Walk Through 4D Space | Brav

Building a Fourth Dimension: How Quantum Hall Experiments Let Us Walk Through 4D Space

Discover how the quantum Hall effect lets us simulate a fourth spatial dimension in the lab. Learn about synthetic dimensions, 4-D edge states, and their potential for quantum computing.