Iptables to redirect outgoing traffic to loopback
Posted on 2006-04-10
I'm using squid and need to redirect outgoing port 80 traffic to the loopback 3128 port. I used
iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner --uid-owner *username* -j REDIRECT --to-ports 3128
and setting the browser proxy to 127.0.0.1:80 worked fine. However, several apps I have work through port 80 and can't be set to "proxy", and they fail. If I tell my web server to just use port 80 directly I get an error that the host "/" canot be found.
Obviously the above rule is redirecting the hosts request to squid, and thinks my local computer is google.com or whatever. Squid chokes on just a page name coming in and the whole thing fails. What I need to do is redirect the request that is going out to a port 80 so the whole request filters through 127.0.0.1:3128 as if it were a proxy.
Is there any way to do this?