Ubuntu – Iptables rule for squid transparent proxy block http requests

iptablessquidUbuntu

I have some iptables rules in a linux gateway (ubuntu server 12.04) and all works good. I configured a transparent squid proxy and works too. I'm using this rule.

$IPT -t nat -A PREROUTING -p tcp --destination-port 80 \
-j REDIRECT --to-ports 3128 

But I must use this server for web development testing and demos, and is rejecting all http requests from internet (eht0). I can access without problems from local network (eth1).

When I comment the rule above. All works again. Why this rule is blocking the http requests from wan network?

Best Answer

Actually, this rule is not blocking http traffic from Wan, but redirects this traffic to your Proxy.

In other words, your actual rule redirects both incoming and outgoing http traffic to your gateway on port 3128.

I would suggest to specify source/destination interfaces :

# Traffic from LAN to Internet is redirected to your Proxy
$IPT -t nat -A PREROUTING -p tcp -i eth1 -o eth0 --destination-port 80 -j REDIRECT --to-ports 3128

# Traffic from Internet is redirected to your gateway on port 80
$IPT -t nat -A PREROUTING -p tcp -i eth0 --destination-port 80 -j REDIRECT --to-ports 80