最近不想用Tun了,但是OpenClash的转发也不是全走的TProxy,TCP走Redirect,UDP走TProxy

这次修改一下防火墙来达到两个协议都用TProxy

 1
 2iptables -t mangle -N clash_tproxy
 3
 4iptables -t mangle -A clash_tproxy -p udp -m udp --sport 500 -j RETURN
 5iptables -t mangle -A clash_tproxy -i lo -j RETURN
 6iptables -t mangle -A clash_tproxy -m set --match-set localnetwork dst -j RETURN
 7
 8iptables -t mangle -A clash_tproxy -p udp -m udp --dport 53 -j RETURN
 9
10iptables -t mangle -A clash_tproxy -d 198.18.0.0/16 -p udp -j TPROXY --on-port 7895 --on-ip 0.0.0.0 --tproxy-mark 0x162
11iptables -t mangle -A clash_tproxy -d 198.18.0.0/16 -p tcp -j TPROXY --on-port 7895 --on-ip 0.0.0.0 --tproxy-mark 0x162
12
13iptables -t mangle -A clash_tproxy -p udp -j TPROXY --on-port 7895 --on-ip 0.0.0.0 --tproxy-mark 0x162
14iptables -t mangle -A clash_tproxy -p tcp -j TPROXY --on-port 7895 --on-ip 0.0.0.0 --tproxy-mark 0x162
15
16iptables -t mangle -N clash_tproxy_output
17
18iptables -t mangle -A clash_tproxy_output -p udp -m udp --sport 500 -j RETURN
19iptables -t mangle -A clash_tproxy_output -d 198.18.0.0/16 -p udp -m owner ! --uid-owner 65534 -j MARK --set-xmark 0x162
20iptables -t mangle -A clash_tproxy_output -d 198.18.0.0/16 -p tcp -m owner ! --uid-owner 65534 -j MARK --set-xmark 0x162
21
22iptables -t mangle -A PREROUTING -j clash_tproxy
23iptables -t mangle -A OUTPUT -j clash_tproxy_output

然后修改OpenClash的系统脚本

 1#!/bin/sh
 2. /usr/share/openclash/log.sh
 3. /lib/functions.sh
 4
 5# This script is called by /etc/init.d/openclash
 6# Add your custom firewall rules here, they will be added after the end of the OpenClash iptables rules
 7
 8LOG_OUT "Tip: Start Add Custom Firewall Rules..."
 9
10// 删除NAT的端口转发,默认这条规则在10下标位置
11iptables -t nat -D PREROUTING 10
12
13// 删除原本的UDPTProxy代理转发
14iptables -t mangle -D PREROUTING 2
15iptables -t mangle -D PREROUTING 2
16
17// 同上
18iptables -t mangle -D OUTPUT 2
19iptables -t mangle -D OUTPUT 2
20
21exit 0