Time for action – redirecting HTTP traffic to Squid

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.

  1. 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 ...

Get Squid Proxy Server 3.1 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.