darkk / redsocks

transparent TCP-to-proxy redirector
http://darkk.net.ru/redsocks
3.28k stars 860 forks source link

Is redsocks able to redirect udp traffic by tproxy (not only for dns )? #173

Open pizeroTT opened 2 years ago

pizeroTT commented 2 years ago

I have seen https://github.com/darkk/redsocks/commit/778340243e09c53e73573e5e08268b9b75abfce0 for redirecting udp traffic, but that not work for me?

my iptables rules:

ip route add local 0.0.0.0/0 dev lo table 100
ip rule add fwmark 1 table 100
iptables -t mangle -N REDUDP
iptables -t mangle -A REDUDP -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A REDUDP -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A REDUDP -d 100.64.0.0/10 -j RETURN
iptables -t mangle -A REDUDP -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A REDUDP -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A REDUDP -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A REDUDP -d 198.18.0.0/15 -j RETURN
iptables -t mangle -A REDUDP -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A REDUDP -d 240.0.0.0/4 -j RETURN
iptables -t mangle -A REDUDP -p udp -j TPROXY --on-port 10053 --tproxy-mark 0x1/0x1
iptables -t mangle -A REDUDP -p tcp -j TPROXY --on-port 12345 --tproxy-mark 0x1/0x1
iptables -t mangle -A PREROUTING -p udp -j REDUDP
ge9 commented 5 months ago

Yes, it worked for me. Unless more tricky iptables settings are applied, PREROUTING is not applied to packets generated in the machine where tproxy is running.