English
English
Theme
English
English
Theme
TProxy (Transparent Proxy) is a module in the Linux kernel that transparently proxies TCP and UDP traffic. The main feature of a transparent proxy is that the client is unaware that its traffic is passing through a proxy server, which makes it very useful in certain application scenarios, such as load balancing, security monitoring, and network optimization. Here is a detailed introduction to TProxy:
TProxy works at the network layer of the Linux kernel and transparently redirects traffic to the proxy server for processing by modifying the destination address of the IP packet. The specific steps are as follows:
The following are example steps to configure TProxy to transparently proxy TCP and UDP traffic:
modprobe xt_TPROXY
modprobe nf_tproxy_core
iptables -t mangle -N DIVERT
iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT
iptables -t mangle -A PREROUTING -p udp -m socket -j DIVERT
iptables -t mangle -A DIVERT -j MARK --set-mark 1
iptables -t mangle -A DIVERT -j ACCEPT
iptables -t mangle -A PREROUTING -p tcp -j TPROXY --tproxy-mark 0x1/0x1 --on-port 12345
iptables -t mangle -A PREROUTING -p udp -j TPROXY --tproxy-mark 0x1/0x1 --on-port 12345
ip rule add fwmark 1 lookup 100
ip route add local 0.0.0.0/0 dev lo table 100
Suppose you have an HTTP proxy server running on port 12345 locally, you can use the following configuration to transparently proxy HTTP traffic:
iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1/0x1 --on-port 12345
iptables -t mangle -A PREROUTING -p tcp --dport 443 -j TPROXY --tproxy-mark 0x1/0x1 --on-port 12345
Advantages:
Disadvantages:
TProxy is a powerful transparent proxy tool suitable for various scenarios that require transparent proxy and processing of network traffic. By combining with iptables and iproute2, TProxy can flexibly capture and redirect TCP and UDP traffic to achieve functions such as load balancing, security monitoring and network optimization. Despite the complex configuration, its powerful functions and flexibility make it an important tool for network administrators and developers.