Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Ubuntu 12.04 host that has a squid proxy on it running on port 8080. I want to proxy all the web traffic from the host through squid using iptables. Is the correct method:

iptables -t nat -I OUTPUT -p tcp -d --dport 80 -j REDIRECT --to-ports 8080

This is not working. When I browse to a page it appears normally, even when the proxy is disabled. Any suggestions appreciated.

share|improve this question

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

In your rule, IPTables will only redirect traffic destined for localhost to the proxy. This rule will redirect any traffic destined for port 80. In your rule, change -d to -s and it shall work.

share|improve this answer
You can change that -A to -I to see immediate effect on the command line. – Timothy Makobu Mar 23 '13 at 11:05
I think the --dport is routing incoming traffic. – Michael Cole May 3 '15 at 12:23
@MichaelCole Yes. Incoming into the NAT table, from anywhere, including localhost. – Timothy Makobu May 4 '15 at 7:46

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.