[Manual] Creating Transparent Proxy With squid and IPTables

For creating transparent proxy we need edit squid.conf and add iptables rules.

  1. Edit /etc/squid.conf file with your favorite editor, example vi
    vi /etc/squid.conf

    Add or change this lines.

    http_port 192.168.5.1:8888
    cache_peer [your_proxy] parent 8080 0 no-query
    cache_dir ufs /var/spool/squid 5000 16 256
    acl clients src [your clients' network, ex. 192.168.5.0/255.255.255.0]
    acl all src 0.0.0.0/0.0.0.0
    http_access allow clients
    http_access deny all
  2. Add iptables rules
    iptables -t nat -A PREROUTING -s 192.168.5.0/24 -d ! 192.168.5.1 -p tcp -m multiport --dport 80,81,82,83,88,8000,8001,8002,8080,8081 -j REDIRECT --to-port 8888
    iptables -t nat -A PREROUTING -s 192.168.5.0/24 -d ! 192.168.5.1 -p udp -m multiport --dport 80,81,82,83,88,8000,8001,8002,8080,8081 -j REDIRECT --to-port 8888
    iptables -t nat -A PREROUTING -s 192.168.5.0/24 -d ! 192.168.5.1 -p tcp -m multiport --dport 8082,8083,8091,8100,8101,8102,8103,8080,777 -j REDIRECT --to-port 8888
    iptables -t nat -A PREROUTING -s 192.168.5.0/24 -d ! 192.168.5.1 -p udp -m multiport --dport 8082,8083,8091,8100,8101,8102,8103,8080,777 -j REDIRECT --to-port 8888

[green]In this example we set up transparent proxy server with ip 192.168.5.1 listens port 8888[/green]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.