Wednesday, June 01, 2011

How to Configure Squid Proxy Server in Ubuntu [Guest Post]

By Dr. Muhammad Saleem, PHD
Pakistan Center for Advanced Studies in Engineering

Squid is a popular proxy and web cache server. It is used for a variety of purposes e.g. increase in speed of a web server through caching of most recently accessed pages, security through packet filtering. It was designed to support HTTP and FTP protocols. However, it now also includes support for TLS, SSL and HTTPS. Squid is available for all Unix-like operating systems as well as Windows. The Squid is an excellent solution ranging from small offices to large enterprise networks. Remember, PC reserved for Squid must have large amount of physical memory because it maintains an in-memory cache for higher performance. One more thing: it can threat the privacy of clients because it can log URLs, date and time of access, requester’s identification etc. 


Squid Proxy Server 3.1: Beginner's Guide


Detailed configuration of Squid is beyond the scope of this article. Therefore, in this article, we only mention few basic things to bring up the Squid proxy server. First step is to get it installed on your Ubuntu machine if not done already. Assuming that your machine is connected to Internet, open the command terminal and enter: 
Sudo apt-get install squid

Configuration of Squid

Like most Linux applications, Squid is also configured through a ‘conf’ file called ‘squid.conf’. This file is located in ‘/etc/squid/’ directory. This configuration file contains several directives i.e. keywords that are used to feed different information to Squid during startup. Before editing this file, we recommend you to keep a backup of this file. For instance, you can simply copy it to another file using ‘cp /etc/squid/squid.conf /etc/squid/squid.conf.unmodified. Remember editing files in ‘/etc/’ directory require ‘root’ access. Let us now get to real business. Open the file in your favorite editor and change few lines as described below.
  • Proxy servers listen incoming connections on a specific port. To configure this port for Squid, locate line containing ‘http_port’, uncomment it, and specify the port e.g. ‘http_port 8080’. IP address of the machine running Squid can also be provided on this line e.g. ‘http_port 192.168.1.121:8080’ 
  • You can give name to your proxy server – not necessarily be the computer name itself. Here is the way to do this.

visible_hostname myproxyserver

Access Control

Ubuntu 8 Server Administration and Reference
Let us now turn to an important configuration question: who is allowed to access this proxy server and when? To allow the subnet ‘192.168.1.0’, locate the ACL section, edit / add the following lines at the BOTTOM of the section. 

acl allowed_networks src 192.168.1.0/24
acl allowed_hours time MTWHF 9:00-17:00

Number after ‘/’, on the first line, refers to netmask which in this case will be 255.255.255.0 (24 leftmost bits are 1). For detailed information on netmasks, follow this link: (http://unixwiz.net/techtips/netmask-ref.html). Second line specifies the days and time of access. Now to make it effective, add the following line at the TOP of http_access section. 

http_access allow allowed_network allowed_hours

Instead of specifying the entire subnet address, one can also use specific IP addresses using the ‘src’ keyword. Here is the example. 

acl allowed_machines src 192.160.10.10 192.160.10.20
http_access allow allowed_machines
http_access deny !allowed_machines

Another variation might be to allow the clients to use the service at different time. Here is an example. 

acl hosts1 src 192.160.10.10
acl hosts2 src 192.160.10.20
acl morning time 09:00-12:00
acl lunch time 12:30-13:30
http_access allow host1 morning
http_access allow host1 lunch
http_access allow host2 lunch
http_access deny all

Host1 enjoys two timings, morning and lunch. Squid can also block certain sites or sites containing a specific word. Here is an example. 

acl banned_sites url_regex abc.com
http_access deny banned_sites 

For a specific keyword, you can use:
acl banned_sites url_regex porn
http_access deny banned_sites


All sites containing the word ‘porn’ will be blocked. Oops!! 
Once you are done with the access control list, save your changes and start/restart Squid using: 

sudo /etc/init.d/squid startrestart

or

sudo /etc/init.d/squid restart

That’s all folks. Happy Squidding !!!!!!

Editor's NoteDr. Muhammad Saleem has a PhD from the Center for Advanced Studies in Engineering, Islamabad, Pakistan. He spends his spare time writing as a freelance writer. He is also the author/co-author of several research publications in the area of Ad Hoc networks. You can view more about his work over at:


The article above does not reflect the opinions, observations and recommendations of Dannybuntu.com and are the sole views of the author. Always confirm information before you do something with your computer. 

No comments:

Post a Comment

EventId's in Nostr - from CGPT4

The mathematical operation used to derive the event.id in your getSignedEvent function is the SHA-256 hash function, applied to a string rep...