How To Install Squid in Ubuntu Linux

http://e-healthexpert.org/node/431

Squid is a caching proxy for the Web supporting HTTP, HTTPS and FTP

Home: http://www.squid-cache.org/

After installing and configuring Squid you must configure your system to use a proxy cache. Change relevant Internet user applications to access the Internet through the proxy: localhost:8080.

The following procedure describes How To install the Squid software package in Ubuntu Linux (8.04 LTS)

1. Install & Configure Squid

a) install:

sudo apt-get install squid
b) configure:

sudo cp /etc/squid/squid.conf /etc/squid/squid.conf-backup
sudo gedit /etc/squid/squid.conf
change squid port: from http_port 3128 to http_port 8080
find the http_access section, uncomment the following 2 lines and add your own networks (for instance 10.10.10.0/24): # acl our_networks src 192.168.1.0/24 192.168.2.0/24 10.10.10.0/24 # http_access allow our_networks
change hostname in the visible_hostname section after: #Default: # none add: visible_hostname localhost # or any other valid hostaname
c) restart squid: sudo /etc/init.d/squid restart

note - to see only the lines that aren't blanks or don't start with a # use: sudo grep "^[^#]" /etc/squid/squid.conf

2. Configure system and applications to use proxy

For Ubuntu > 8.x:
On the Ubuntu Menu open "System > Preferences > Network Proxy"
Select the "Proxy Configuration" folder
Choose "Manual Proxy configuration"
Choose "Use the same proxy for all protocols"
Set "HTTP Proxy:" to localhost and "Port:" 8080 # or to the port that you choose above
3. Configure Squid as Transparent Proxy (Squid version >= 2.6)

sudo gedit /etc/squid/squid.conf
change from: http_port 3128 to, either: http_port 3128 transparent or: ** http_port 192.168.x.x:3128 transparent
add line: always_direct allow all
add this line to iptables:
iptables -t nat -A PREROUTING -i eth0 -p tcp - -dport 80 -d ! 192.168.0.0/255.255.0.0 -j REDIRECT - -to-port 3128

  1. -i eth0 - adjust to the interface where it will be listening
  2. -d ! 192.168.0.0/255.255.0.0 - excludes this address range from caching

save the new iptables: sudo iptables-save
Reference: http://www.ubuntugeek.com/how-to-setup-transparent-squid-proxy-server-in-ubuntu.html