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 ( -, -, - 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 -j RETURN 
iptables -t nat -A PUBPROXY -m iprange --dst-range -j RETURN 
iptables -t nat -A PUBPROXY -m iprange --dst-range -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
this will not work, because socks is an application based protocol. –  user55518 Mar 18 '14 at 14:06

Your Answer


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

Browse other questions tagged or ask your own question.