Run Xray on a Router or Bypass Router: Hardware, Transparent Proxying & Traffic Routing

Run Xray directly on a router or bypass router so devices across your home network need no separate client. Covers hardware, transparent proxying, configuration files, and common pitfalls.

At a glance

First verify Xray's outbound connection on one device. Then configure the bypass-router gateway, DNS, and transparent traffic interception before adding other devices. Using OpenWrt and the Linux networking stack as examples, this guide covers hardware budgets, core configuration, and firewall rules. It's for readers with a working node who want to move from a single-device proxy to their local network. Addresses and ports are illustrative, not defaults for every firmware.

1. Choose Hardware: Check the Architecture and Available Memory First

Xray is a core engine for handling connections, protocols, and routing—not router firmware, and it doesn't include a general-purpose router management interface. A device running Linux can't necessarily run any Xray binary: the CPU architecture, instruction set, system environment, and writable storage must all match. Before downloading, check the architecture with uname -m, then use free -m and df -h to check available memory and storage.

These are deployment budget recommendations, not minimum operating requirements or throughput guarantees. Resource needs vary with concurrent connections, rule-set size, encryption overhead, and log volume. The wireless speed printed on a device's packaging is not a measure of proxy throughput.

Existing Main Router

First confirm that the firmware supports installing a package built for the device's architecture. If the device has only 128 MB of memory and also handles Wi-Fi, the WAN connection, and other services, check how much memory remains available. Loading or updating rules can use significantly more resources than an idle system.

Best for: A small number of devices, supported firmware already in place, and networks where brief outages during maintenance are acceptable.

Dedicated Bypass Router

Recommended

For a first deployment, start with a 64-bit dual-core device, 1 GB of memory, and at least 1 GB of writable storage. A separate device makes rollback easier and lets you adjust the proxy service without restarting Wi-Fi or WAN services on the main router.

Best for: Home networks where you want to test with one device first and expand coverage gradually.

Always-on Linux Host

If you already have a mini PC or virtual machine, you can run the core separately. For a VM, check the virtual network adapter's bridge mode, the host firewall, and startup order—not just the configuration inside the VM.

Best for: Linux users who want to manage services, retain logs, and troubleshoot each part of the network path.

Takeaway: Keep a Separate Rollback Path

Use a bypass router for the first deployment, and keep a way to connect test devices directly to the main router. If something goes wrong, changing the test device's gateway and DNS back to the main router is more manageable than repairing the firewall after the whole network goes offline.

2. Main Router vs. Bypass Router: Map the Traffic Path First

The main router typically handles the WAN connection, NAT, DHCP, and the default gateway. A bypass router is an additional forwarding device on the local network; plugging it in doesn't automatically route traffic from every device through it. Devices must send the relevant traffic to the bypass router, or the main router must forward it there using policy-based routing, before Xray can process the connections.

On a same-subnet setup, also consider whether return traffic bypasses the bypass router and whether ICMP redirects change the device's route. Whether to use source NAT depends on the topology and connection-tracking requirements; “a bypass router must use NAT” is not a universal rule. Start with one device and use ip route or your system's route viewer to confirm its default gateway.

3. Transparent Proxying: Traffic Interception Is Not a Proxy Protocol

Transparent proxying describes how traffic is intercepted; it isn't a replacement for protocols such as VLESS or VMess. Devices don't need to enter an application proxy address: the gateway redirects traffic or uses policy-based routing to send it to the core. Support for TCP, UDP, and IPv6 depends on the Linux network configuration, inbound settings, proxy outbound, and server working together.

MethodWhere Traffic Is InterceptedKey Limitations
Explicit SOCKS ProxyApplications connect directly to a local proxy portUseful for testing the core, but doesn't automatically cover every application on the network
REDIRECTFirewall redirects connections to a local inboundCommonly used for TCP; TCP rules can't simply be reused to intercept UDP
TPROXYTransparent sockets combined with policy-based routingRequires the kernel module, traffic marks, and local routes to work together
TUNA virtual network interface receives IP packetsDepends on the implementation and routing setup; desktop toggle names don't necessarily apply

A common Linux approach for transparent proxying with Xray uses a dokodemo-door inbound with followRedirect to read the original destination. TPROXY also requires the corresponding streamSettings.sockopt.tproxy setting. Adding these JSON fields alone won't create firewall rules or policy routes, or enable system forwarding.

OpenWrt 22.03 and later generally use firewall4 and nftables. Older iptables guides written for firewall3 can't be applied as-is; check the firmware, modules, and compatibility layer in use. The TUN toggle in desktop v2rayN is not a single field you can copy directly into a router's Xray configuration. See the TUN configuration guide for details.

4. Configuration and Services: Test an Explicit Proxy First

The startup command determines which configuration file is used, not its filename. /etc/xray/config.json is a common convention, but a package or management interface may use a different directory or generate runtime files under /var. Changes to generated files are often overwritten the next time settings are saved or the system restarts, so first find out where the configuration comes from.

  1. Record Network Settings

    In OpenWrt LuCI, go to Network → Interfaces and note the LAN address, upstream gateway, and interface names. Export a configuration backup under System → Backup / Flash Firmware. Don't change the DHCP settings distributed to the whole network yet.

  2. Check the Startup Command

    Run xray version to verify that the core runs. On a system using systemd, check ExecStart in systemctl cat xray. On OpenWrt, inspect /etc/init.d/xray and the configuration it reads to confirm the actual file path.

  3. Validate the Configuration

    If the configuration is at this common path, run xray run -test -config /etc/xray/config.json. Fix syntax errors, unknown fields, and rule-file read errors before starting the service. A successful configuration test doesn't mean the remote node is reachable.

  4. Test Locally

    Start with the SOCKS inbound listening only on 127.0.0.1:10808. Test the connection with curl --proxy socks5h://127.0.0.1:10808 https://example.com/ and check the logs to see which outbound was selected. A page loading successfully alone doesn't prove that traffic used the proxy.

  5. Intercept Traffic for One Device

    Once the explicit proxy and the actual node both work, enable transparent rules for one test device. Test DNS, TCP, UDP, and IPv6 separately, confirm the management interface remains accessible, and only then expand the source address range.

The example below is a direct-connection baseline to help explain the configuration structure, not a ready-to-use configuration for a working proxy node. It has no remote server settings or transparent inbound; every connection received by SOCKS goes direct through freedom. If the service already has a working configuration, don't overwrite it.

{
  "log": {
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "tag": "local-socks",
      "listen": "127.0.0.1",
      "port": 10808,
      "protocol": "socks",
      "settings": {
        "auth": "noauth",
        "udp": true
      }
    }
  ],
  "outbounds": [
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    }
  ]
}

A subscription URL is not an Xray startup parameter. Client subscriptions may contain Base64-encoded share links or use a format specific to a management tool. Only JSON that follows Xray's configuration structure can be loaded as a configuration file. If you use a subscription manager, check the outbounds, tags, and rule files it generates—manual edits may be overwritten by the next update.

5. DNS and Traffic Routing: Check Both Paths

Reliable traffic routing requires knowing both where a connection is going and how its domain name is resolved. Xray evaluates routing.rules from top to bottom, and each rule's outboundTag must point to an existing outbound tag. If no rule matches, the first outbound is typically used. Write down the expected results for domain rules, IP rules, and the default outbound before translating them into configuration.

53
Standard DNS Uses TCP or UDP Ports
10808
Local SOCKS Test Port in This Guide
12345
Example Port for a Planned Transparent Inbound

These ports serve different purposes and aren't interchangeable. 12345 is an illustrative value for planning, not a system default that takes effect automatically. The firewall's redirect target must match the port the core listens on. Don't expose an unauthenticated SOCKS port to the public internet; if local network access is needed later, restrict the listening address and firewall sources.

Takeaway: Compare DNS and Outbound Logs for the Same Domain

First run nslookup example.com 192.168.10.2 for a test domain, provided the bypass router is actually running a DNS service. Then visit that domain and check which outbound was selected. A successful lookup confirms only that the DNS path works; the selected outbound confirms whether routing behaved as expected.

For a VLESS node, the remote address, port, user ID, transport, and security settings must match the server; running it on a router doesn't change those requirements. VMess and VLESS are proxy protocols; TCP and WebSocket are transport-related options. The protocol name alone doesn't determine device throughput. See the routing configuration reference and glossary for field definitions.

6. Troubleshooting: Narrow Down the Cause by Symptom

Keep one management device off the bypass router while troubleshooting. Compare results using the original gateway and the bypass-router gateway, then check DNS, core logs, and firewall counters. Don't change the MTU, protocol, DNS, and routing rules all at once, or it will be hard to tell which change made a difference.

Can't Reach Any Websites After Switching the Gateway to the Bypass Router?

Check Forwarding and the Upstream Path

First, try to reach the bypass router's management address from the device. Then run ip route on the bypass router to check the default route. Use sysctl net.ipv4.ip_forward to see whether IPv4 forwarding is enabled, and check the firewall's forwarding chain. Changing nodes won't help if the default route or forwarding is wrong; switch the device's gateway back to the main router to restore connectivity.

Web Pages Load, but Voice Chat and Games Won't Connect?

Check Each Step of the UDP Path

Check whether the interception rules cover only TCP, then verify that the transparent inbound, proxy outbound, and server support the required UDP forwarding. A successful HTTP request doesn't prove UDP works. If REDIRECT is used for TCP interception, don't assume the same rule handles UDP; choose a suitable interception method and test it.

The Service Is Running, but Why Are There No Interception Logs?

Check Listening Ports and Rule Matches

Run ss -lnptu to see the actual listening ports, then use nft list ruleset to check that the source subnet, interface, and ports match. If the rules have counters, check whether test connections increment them. A running service only confirms that the process exists; it doesn't prove that devices pass through this router or that policy routing sends packets to the transparent inbound.

Settings Stop Working After a Restart, or Do Logs Keep Growing During Speed Tests?

Check Persistence and Log Storage

Make sure the service is enabled at startup, and that firewall and policy-routing rules persist through firmware-supported methods rather than commands run temporarily in a terminal. After troubleshooting, restore an appropriate log level and configure rotation. Avoid keeping high-volume access logs on small flash storage. If a rule update fails, keep the last working data instead of deleting it before downloading a replacement.

7. Deployment Checklist: Expand from One Device to the Whole Network

For devices across your home network to work without separate clients, their traffic must actually pass through the configured gateway, with consistent DNS, IPv4, and IPv6 policies. Devices using a separate network, manual routes, or custom encrypted DNS may follow a different path; verify each device category separately.

If you haven't confirmed that the node works yet, test it first on desktop v2rayN or Android v2rayNG to separate node issues from gateway issues. v2rayNG uses the Xray core, while v2flyNG uses the V2Fly core; check their capabilities and configuration formats separately. After the single-device test succeeds, transfer the relevant connection settings and routing intent to the router environment instead of copying the entire client data directory.

Client Downloads by Platform