Skip to content

环境

adb
iptables
Nox模拟器(root)
ipt2socks

普通的基于android vpn的代理 有些UDP代理不到 尝试很多app都不太行 下面给出解决方案

创建文件myiptables.sh

shell

socks5_server="192.168.2.12" #本人的socks5服务器 可以替换成自己的
socks5_port="2802"
tproxy_port="60080"  #itp2socks默认的侦听端口



iptables -t mangle -D PREROUTING -j DIVERT
iptables -t mangle -F DIVERT
iptables -t mangle -X DIVERT
iptables -t mangle -D OUTPUT -j LOCAL_DIVERT
iptables -t mangle -F LOCAL_DIVERT
iptables -t mangle -X LOCAL_DIVERT


#把所有PREROUTING中的流量转发到 ipt2socks监听的端口中去 
iptables -t mangle -N DIVERT
iptables -t mangle -A DIVERT -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A DIVERT -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A DIVERT -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A DIVERT -d 100.64.0.0/10 -j RETURN
iptables -t mangle -A DIVERT -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A DIVERT -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A DIVERT -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A DIVERT -d 172.17.0.0/12 -j RETURN
iptables -t mangle -A DIVERT -d 192.0.0.0/24 -j RETURN
iptables -t mangle -A DIVERT -d 192.0.2.0/24 -j RETURN
iptables -t mangle -A DIVERT -d 192.88.99.0/24 -j RETURN
iptables -t mangle -A DIVERT -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A DIVERT -d 198.18.0.0/15 -j RETURN
iptables -t mangle -A DIVERT -d 198.51.100.0/24 -j RETURN
iptables -t mangle -A DIVERT -d 203.0.113.0/24 -j RETURN
iptables -t mangle -A DIVERT -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A DIVERT -d 240.0.0.0/4 -j RETURN
iptables -t mangle -A DIVERT -d 255.255.255.255/32 -j RETURN
iptables -t mangle -A DIVERT -p tcp -j TPROXY --on-port ${tproxy_port}
iptables -t mangle -A DIVERT -p udp -j TPROXY --on-port ${tproxy_port}
iptables -t mangle -A PREROUTING -j DIVERT


#转发所有流量到 PREROUTING链中去
iptables -t mangle -N LOCAL_DIVERT
iptables -t mangle -A LOCAL_DIVERT -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 100.64.0.0/10 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 172.17.0.0/12 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 192.0.0.0/24 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 192.0.2.0/24 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 192.88.99.0/24 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 198.18.0.0/15 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 198.51.100.0/24 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 203.0.113.0/24 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 240.0.0.0/4 -j RETURN
iptables -t mangle -A LOCAL_DIVERT -d 255.255.255.255/32 -j RETURN

#给流量设置23标记
iptables -t mangle -A LOCAL_DIVERT -p tcp -j MARK --set-mark 23
iptables -t mangle -A LOCAL_DIVERT -p udp -j MARK --set-mark 23
iptables -t mangle -A OUTPUT -j LOCAL_DIVERT


#设置检查规则 转发标记23的包到2233表中去  2233表全部转发到本地
ip rule add fwmark 23 table 2233
ip route add local 0.0.0.0/0 dev lo table 2233


#启动转发
chmod +x ipt2socks-x86_64
./ipt2socks-x86_64 -s ${socks5_server} -p ${socks5_port} -l ${tproxy_port}

保存下面代码为install.bat

bat
adb shell mkdir /data/local/sk5
adb push myiptable.sh /data/local/sk5/
adb push ipt2socks-x86_64 /data/local/sk5/

adb shell chmod +x /data/local/sk5/myiptable.sh
adb shell chmod +x /data/local/sk5/ipt2socks-x86_64
adb shell iptables-save iptables.bak

参考