Running Xray on a Router or Bypass Router: Deployment Options Compared

Compare ways to run Xray on a main router or bypass router, including hardware demands, transparent proxying, and maintenance overhead.

At a glance

For readers with an existing main router who are considering OpenWrt or a dedicated mini PC to manage proxying. First, distinguish where the service runs from how client traffic reaches it. Then validate throughput, DNS, and recovery behavior with a single-device pilot. Centralized management doesn't require replacing the default gateway for the entire network.

Main Router vs. Bypass Router: Where Does Traffic Go?

Xray handles inbound connections and selects outbound routes according to its rules, but starting the core does not mean it takes over network traffic. With an explicit proxy, an app connects directly to the proxy port. With a transparent proxy, the gateway redirects selected traffic from the forwarding path into Xray. A TV app with only an “HTTP proxy” setting and one with no proxy settings need different solutions; a working browser connection does not prove that the whole device is covered.

Three Connection Options Compared

Run an Explicit Proxy on a Bypass Router

Recommended

Keep the main router in charge of internet access, DHCP, and the default gateway. Enter the bypass router's address and listening port only in apps that support proxies. If the service stops, only apps pointing to it are affected; remove the proxy setting to restore normal access. Apps without proxy settings continue using their existing route.

Best for: First-time setup or routing a few computers or apps through a proxy

Use a Bypass Router for Per-Device Transparent Proxying

Send selected devices' test traffic through the bypass router, for example by manually setting the IPv4 gateway on one device. The main router still provides the internet connection, while the bypass router must handle both proxy traffic and forwarding for traffic that isn't intercepted. For a single-interface setup on the same subnet, verify that return traffic follows the intended path; changing the default gateway alone does not guarantee that traffic is intercepted in both directions.

Best for: Devices that don't support explicit proxies, when you want to limit the impact to selected devices

Run the Transparent Proxy on the Main Router

Devices already route through the main router, so you usually don't need to change their gateways one by one. The tradeoff is that Xray shares resources with services such as the firewall, Wi-Fi management, and WAN connection. A bad firewall reload can disrupt both regular internet access and proxy traffic, so schedule updates during a maintenance window.

Best for: Networks with a stable gateway management process that need centralized traffic interception

Bottom line: Start with an app-level pilot

First, test an explicit proxy on the bypass router with the same app you plan to use. If that meets your needs, keep the existing gateway. Only test transparent proxying on a single device if the target app can't be configured to use a proxy.

OpenWrt Pilot: Check Addresses, Ports, and Services

The values below are examples for a reproducible test, not defaults or benchmark results. Assume the main router and bypass device share an IPv4 subnet, the main router assigns addresses, and the bypass device uses a reserved address with its own DHCP service disabled. Expose proxy inbound ports only to trusted devices on the LAN—never forward them from the internet or expose them to a guest network.

192.168.50.1
Example main router address
192.168.50.2
Example bypass device address
1080
Example SOCKS listening port

Single-Device Pilot Steps

  1. Document the Existing Network

    On an OpenWrt main router using LuCI, go to Network → Interfaces → LAN → Edit and note the interface address and subnet mask. Under DHCP Server on the same page, check the address pool. Reserve an unused address for the bypass device; don't pick one that's already leased. First, make sure the test computer can open the main router's admin page.

  2. Confirm the Core Is Running

    Choose a build that matches the device's processor architecture and operating environment. Run xray version to record the installed version. If using a single configuration file, validate it before startup with xray run -test -config /etc/xray/config.json, replacing the path with the one the service actually reads. After validation, check the service logs to confirm the process started and is listening.

  3. Test the Explicit Proxy

    In a test computer's app proxy settings, select SOCKS5, set the address to 192.168.50.2 and the port to 1080, and leave the default gateway unchanged. In the same app, visit a LAN target and a test target expected to use the proxy. Check Xray's access logs to confirm the latter uses the expected outbound. If the LAN target should bypass the proxy, check the app's proxy exceptions or Xray's direct routing rules.

  4. Test Recovery from Failure

    Stop the Xray service on the bypass device and retry. Confirm that when the app proxy fails, other devices without proxy settings can still access the network. Then remove the proxy setting from the test app and verify that its regular connection works again. If you later test transparent proxying, record the test device's original gateway and DNS settings so you can restore both.

Transparent Proxying: Policy-Based Routing, DNS, and IPv6

Transparent proxying involves two routing decisions: the system first determines which packets enter Xray, then Xray selects an outbound for each connection. Xray's domain-routing rules alone won't redirect traffic that never enters the core. On Linux, TPROXY setups typically use firewall rules, packet marks, and policy-based routing to send selected traffic to an inbound that supports transparent proxying. Make sure the firmware's kernel modules, firewall backend, and management interface are compatible with the setup.

  • Define the interception scope first. Start with one test device, not an entire subnet. Exclude the router's management address, essential LAN destinations, and the route used by Xray's own outbound connections. Otherwise, proxy traffic may be redirected back into the inbound, showing up in the logs as repeated connection attempts or timeouts rather than a clear rule error.
  • Test DNS separately. Changing the IPv4 default gateway does not change DNS automatically. Check which resolver the device actually uses, and distinguish between connections made to an IP after the device resolves a hostname and lookups performed by Xray itself according to its configuration. Apps using encrypted DNS may also bypass the designated LAN resolver. If an IP is reachable but a hostname isn't, trace the DNS request and response before rearranging outbound rules.
  • Test UDP and IPv6 separately. A working web page only confirms that the tested connection works; it doesn't prove that voice calls, UDP apps, or IPv6 use the same path. Devices may still receive an IPv6 default route through router advertisements from the main router. If only IPv4 is intercepted, explicitly leave IPv6 on its existing route or configure and test separate IPv6 rules.

When a single-interface bypass router on the same subnet forwards connections that aren't proxied, the upstream main router may send replies directly to the client. Asymmetric routing doesn't always cause problems, but don't assume the bypass router's stateful firewall sees traffic in both directions. If your policy requires both directions to pass through the bypass router, consider testing on a separate subnet, configure return routes or NAT explicitly, and repeat the tests.

CPU Overhead and Maintenance: Deployment Readiness Checks

A gigabit Ethernet port specifies link speed, not proxy throughput. Hardware acceleration may help ordinary forwarding, but connections handled by Xray also incur userspace processing and protocol overhead. To find bottlenecks, check per-core load, negotiated interface speed, and proxy node performance together. Low overall CPU usage doesn't rule out a single core being saturated.

CheckHow to testWhat to look for
Forwarding baselineUsing the same wired device, run three 60-second tests of ordinary traffic and record interface speed and throughput.If the link negotiates at only 100 Mb/s, check the cable and port before blaming Xray for the performance ceiling.
Proxy throughputKeep the remote node, protocol, and test target as consistent as possible. Run Xray first on the client, then on the bypass device; record the median of three tests and the device's per-core load.If the node is unchanged, the bypass device is noticeably slower, and one core stays near full load, consider keeping the proxy on the client or upgrading the hardware.
Service recoveryTest restarting Xray, reloading the firewall, and rebooting the device separately. Check how proxy and regular traffic recover after each test.Document what happens if firewall rules are applied before the process starts. Decide whether failures should restore direct access or stop forwarding intercepted traffic.

Before upgrading, record the firmware and kernel versions, back up the service configuration and firewall settings, and keep a management path that doesn't rely on proxy rules. A bypass setup adds another device to maintain, but devices not routed through it can continue using the main router. Running Xray on the main router reduces the device count but puts proxy upgrades and home network maintenance in the same failure domain. Choose based on the downtime you can tolerate, not just the cost of the hardware.

Common Bypass Router Questions

Why do some connections bypass the router after I change the default gateway?

Check the device's IPv4 and IPv6 default routes first, then confirm whether the test target is on the local subnet: same-subnet IPv4 traffic usually goes directly to the destination without using the default gateway. For external targets, test IPv4 and IPv6 separately and check the inbound logs. If there are no corresponding entries, verify the interception scope before changing Xray's routing rules.

Why are DNS results different when my browser uses SOCKS?

Check whether the browser resolves the hostname locally and sends an IP address, or passes the hostname to the SOCKS proxy. On the same computer, compare results using a command-line tool that supports SOCKS5—for example, compare curl's --socks5 and --socks5-hostname options. Then check whether the core or the outbound handles DNS resolution on the proxy side. Don't assume system DNS lookup results reflect the app's actual route.

The bypass device is offline and one computer has lost internet access. How do I restore it?

On that computer, remove the default gateway and DNS settings pointing to the bypass device, then restore automatic configuration or the values from before the change. If you only changed the app's proxy settings, remove them in the app. Once restored, try the main router's admin address, then test DNS resolution and internet access. There's no need to reboot the main router for a problem affecting one device.

Download v2rayN