Let's have a quick look at the configuration we need to perform. For the following, we'll assume that the IP for the Squid proxy server is 192.0.2.25
.
Working with Linux:
To redirect traffic destined to port 80, we can use
iptables
as follows:iptables -t nat -A PREROUTING -s 192.0.2.25 -p tcp --dport 80 -j ACCEPT iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.0.2.25:3128 iptables -t nat -A POSTROUTING -j MASQUERADE
In the previous list of commands, the first command prevents the redirecting HTTP traffic from the Squid server itself. If we don't have the first line in place, we'll face forwarding loops and requests will not be satisfied. The second command captures all the traffic on port 80 and redirects it to the IP address to which Squid is bound and port 3128 where Squid is listening. The last command allows Network Address Translation (NAT , for more details, please check http://en.wikipedia.org/wiki/Network_address_translation...