Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 just setup a squid proxy server. The server have two interfaces. eth0 connects to the router and eth1 is connected to a switch where all the other machines connect. The server also have a DHCP server. I have setup Squid3 on the machine and when I configure my browser to use that proxy (I network settings if I set the IP and the port), things work. But I need it as a transparent proxy where I don't have to setup the browser and all the requests will pass through the proxy.

It can be done by just setting the IPtable rules right? Some articles talk about changing sysctl.conf. I have tried the Iptable rules from a lot of tutorials and none worked. Please give me a working rule to add. Thank you.

PS : The server is Ubuntu 12.10

PS2 : If you can, please tell me how to add those rules for ufw

share|improve this question

You should change the following to match your configuration:

eth1 : LAN interface
eth0 : WAN interface
Squid PORT : 8028

Below are the settings for Squid in transparent mode.

iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT

# Redirect
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 8028 -j REDIRECT --to-port 80 
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j DNAT --to IPaddress:8028
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8028
share|improve this answer

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.