Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want all outgoing to traffic that is directed to a private IP (10.0.0.0 - 10.255.255.255, 172.16.0.0 - 172.31.255.255, 192.168.0.0 - 192.168.255.255) to be untouched. I want all other traffic redirected to localhost:6666 (where I am running a socks5 proxy).

I'm not sure what I need to do to not touch the private IP traffic but for the public traffic do I:

sudo iptables -t nat -A PREROUTING -p tcp -i <interface> -j REDIRECT --to-ports 6666

am I on the right track?

UPDATE: This did the trick:

echo "Flushing previous rules..."
iptables -t nat --flush

echo "Deleting and recreating the PUBPROXY chain..."
iptables -t nat -X PUBPROXY
iptables -t nat -N PUBPROXY

echo "Setting iptables to ignore traffic directed to private ips..."
iptables -t nat -A PUBPROXY -o lo -j RETURN 
iptables -t nat -A PUBPROXY -m iprange --dst-range 10.0.0.0-10.255.255.255 -j RETURN 
iptables -t nat -A PUBPROXY -m iprange --dst-range 172.16.0.0-172.31.255.255 -j RETURN 
iptables -t nat -A PUBPROXY -m iprange --dst-range 192.168.0.0-192.168.255.255 -j RETURN 

echo "Redirecting other traffic to socks5 proxy running at localhost:6666"
iptables -t nat -A PUBPROXY -p tcp -j REDIRECT --to-port 6666
share|improve this question
2  
this will not work, because socks is an application based protocol. –  user55518 Mar 18 at 14:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.