Transparent Proxy using Squid and Iptables in Ubuntu Dapper
Cache seems to be a must component for company with large amount of clients connected to the gateway and all of them are always online. Today, I have to install Squid as a transparent cache proxy on Ubuntu Dapper using Iptables.
Since this host is also the internet gateway, I assume that your host are currently the same thing and I will just describe the additional steps to setup a transparent proxy.
First of all, I have to redirect outgoing TCP port 80 to the proxy using below command. You may add this command to the end of firewall scripts.
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.0.2:3128
If you are running web server on this server, you have to ignore redirecting if the destination is itself.
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -d ! 192.168.0.2 -j DNAT --to 192.168.0.2:3128
Then it is about Squid. Below is my /etc/squid/squid.conf
where my network is 192.168.0.0/24 and 192.168.3.0/24.
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
hosts_file /etc/hosts
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563 # https, snews
acl SSL_ports port 873 # rsync
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 563 # https, snews
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl Safe_ports port 631 # cups
acl Safe_ports port 873 # rsync
acl Safe_ports port 901 # SWAT
acl purge method PURGE
acl CONNECT method CONNECT
cache_mem 64 MB
logfile_rotate 10
maximum_object_size 20000 KB
http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl lan src 192.168.0.0/24 192.168.3.0/24
http_access allow localhost
http_access allow lan
http_access deny all
http_reply_access allow all
icp_access allow all
visible_hostname 192.168.0.2
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
coredump_dir /var/spool/squid
cache_dir ufs /var/spool/squid 1000 16 256
And the proxy is running on 192.168.0.2. The last line is to specify a cache directory and its maximum size (1000 MB) following by sizes of L1 and L2 cache.
- sugree's blog
- 5509 reads
error running squid
You must be runnung squid
Post new comment