Avoid infinite network loops with TUN
mainSince Xray-core connects to its uplinks at the network level, routing all traffic (0.0.0.0/0) through the xray0 interface will cause Xray to try to reach its own uplink through the proxy, creating an infinite loop.
To prevent this, use one of these approaches:
Approach 1: Static Routes for Uplinks
Add a precise static route for your Xray upstream server so it always goes through your physical internet gateway.
# Example: routing the VLESS uplink through the provider gateway
ip route add 123.123.123.123/32 via <provider_internet_gateway_ip>
ip route add 0.0.0.0/0 dev xray0Approach 1-b: Specific Network Routing
Instead of a default gateway, only route specific destination networks through the xray0 device using IP sets or routing daemons.
Approach 2: Separate Routing Tables (Recommended for Linux)
Use separate routing tables to isolate Xray traffic. You can configure the xray0 interface to act as the default gateway in a separate table (e.g., table 1001) and use ip rules to funnel specific traffic into that table. This allows you to enable/disable proxying by simply toggling the IP rules.
# Approach 1 example
ip route add 123.123.123.123/32 via <provider_internet_gateway_ip>
ip route add 0.0.0.0/0 dev xray0