In the existing transparent proxy configuration(**[New V2Ray vernacular tutorial on transparent proxy](https://guide.v2fly.org/app/transparent_proxy.html)** 、 **[New V2Ray vernacular tutorial on transparent proxy (TProxy)](https://guide.v2fly.org/app/tproxy.html)** 、 **[Transparent proxy(TProxy)configuration tutorial](./tproxy.md)**)tutorials, the circumvention of Xray traffic is achieved by using mark. That is, mark outbound traffics and set up iptables rules which directly connect traffics corresponding to the mark, to circumvent the Xray traffic and prevent loop back.
1. **[Inexplicable traffic into PREROUTING chain](https://github.com/v2ray/v2ray-core/issues/2621)**
2. 安卓系统有自己的 mark 机制,该方案在安卓上不可用
2. Android has its own mark mechanism and this solution is not available on Android
本教程的方案不需要设置 mark,理论性能更高,同时也不存在上述问题。
The solution in this tutorial does not require a mark setting and has a higher theoretical performance, as well as not having the problems mentioned above.
1. Modify the way you run Xray so that it runs on a user with uid 0 and gid 23333, refer to [here](#_3-configure-and-run-xray-and-configure-iptables-rules).
## 下面提供一个实现 tproxy 全局代理的完整配置过程
## The following provides a complete configuration process for implementing the tproxy global proxy
### 3. Configuring the maximum number of open files and run the Xray client
About the maximum number of open files, see: **[too many open files issues](https://guide.v2fly.org/app/tproxy.html#解决-too-many-open-files-问题)**
The current Xray server installed with the official script has the maximum number of open files automatically configured, so no further changes are required.
关于最大文件大开数问题见: **[too many open files 问题](https://guide.v2fly.org/app/tproxy.html#解决-too-many-open-files-问题)**
Change the maximum number of open files, valid only for the current terminal and to be run every time before starting Xray, this command is to set the maximum number of open files for the client.
_第二条命令:_
_The second command:_
以 uid 为 0,gid 不为 0 的用户来运行 Xray 客户端,后面加&代表放在后台运行
Run the Xray client as a user with uid 0 and gid not 0, followed by & for running in the background.
**检查最大文件大开数是否设置成功**
**Check if the maximum number of open files is set successfully**
```bash
cat /proc/Xray的pid/limits
cat /proc/"Xray's pid"/limits
```
找到 max open files 一项,应该是你设置的数值。pid 的获取方法为运行`ps`或`ps -aux`或`ps -a`
Find max open files, which should be the value you set. Xray's pid can be obtained by running `ps` or `ps -aux` or `ps -a`
服务端和客户端都要检查
Both the server and client side should be checked.
iptables -t mangle -A XRAY -d 网关所在ipv4网段1 -j RETURN
iptables -t mangle -A XRAY -d 网关所在ipv4网段2 -j RETURN
...
# 组播地址/E类地址/广播地址直连
iptables -t mangle -A XRAY -d 224.0.0.0/3 -j RETURN
# "ipv4 segment where the gateway is located" is obtained by running the command "ip address | grep -w inet | awk '{print $2}'", usually there are multiple
iptables -t mangle -A XRAY -d "first ipv4 segment where the gateway is located" -j RETURN
iptables -t mangle -A XRAY -d "second ipv4 segment where the gateway is located" -j RETURN
# If the gateway is used as the primary router, add this line, see: [Other considerations for transparent proxy of iptables](https://xtls.github.io/en/documents/level-2/transparent_proxy/transparent_proxy/#proxy-ipv6)
# The "gateway LAN_IPv4 address segment", obtained by running the command "ip address | grep -w "inet" | awk '{print $2}'", is one of the results
ip6tables -t mangle -A XRAY6 ! -s 网关LAN_IPv6地址段 -j RETURN
# If the gateway is used as the primary router, add this line, see: [Other considerations for transparent proxy of iptables](https://xtls.github.io/en/documents/level-2/transparent_proxy/transparent_proxy/#proxy-ipv6)
# The "gateway LAN_IPv6 address segment", obtained by running the command "ip address | grep -w "inet6" | awk '{print $2}'", is one of the results