SQUID PROXY SERVER

Squid is a proxy server for caching and filtering web content . Squid proxy is used by various organisation and internet providers to reduce bandwidth and to increase response time.

Squid proxy service will cache the requested web-content and re-using it for the further request of the same content.

squid-proxy-server

In the above diagram, squid proxy will cache the webcontent of chaulv8x.com from the ISP during the first request and it will deliver the cached content for the further requests of chaulv8x.com without requesting from ISP. This will reduce bandwidth and will increase response time as the content is delivered from the local network.

Install squid proxy on centos 6:

Update yum repositories and packages by typing the below command

[root@localhost ~]# yum update

Step 1 » Install squid package and dependencies using the below command

[root@localhost ~]# yum install squid

» By default squid configuration file “/etc/squid/squid.conf” will contains recommended minimum configuration  and squid caching feature will work without making any changes . Recommended minimum configuration will looks like the below

#
# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src127.0.0.1/32::1
acl to_localhost dst127.0.0.0/80.0.0.0/32::1
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src10.0.0.0/8    # RFC1918 possible internal network
acl localnet src172.16.0.0/12 # RFC1918 possible internal network
acl localnet src192.168.0.0/16# RFC1918 possible internal network
acl localnet src fc00::/7      # RFC 4193 local private network range
acl localnet src fe80::/10     # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port443
acl Safe_ports port80         # http
acl Safe_ports port21         # ftp
acl Safe_ports port443        # https
acl Safe_ports port70         # gopher
acl Safe_ports port210        # wais
acl Safe_ports port102565535 # unregistered ports
acl Safe_ports port280        # http-mgmt
acl Safe_ports port488        # gss-http
acl Safe_ports port591        # filemaker
acl Safe_ports port777        # multiling http
acl CONNECT method CONNECT
#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager
# Deny requests to certain unsafe ports
http_access deny!Safe_ports
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT!SSL_ports
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on “localhost” is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost
# And finally deny all other access to this proxy
http_access deny all
# Squid normally listens to port 3128
http_port3128
# We recommend you to use at least the following line.
hierarchy_stoplist cgibin?
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256
# Leave coredumps in the first cache dir
coredump_dir/var/spool/squid
# Add any of your own refresh_pattern entries above these.
refresh_pattern^ftp:          1440   20%    10080
refresh_pattern^gopher:       1440   0%     1440
refresh_patterni(/cgibin/|?)0    0%     0
refresh_pattern.              0      20%    4320
Step 2» Now start squid service

[root@localhost ~]# service squid start

and type this below command to start squid service automatically while booting.

[root@localhost ~]# chkconfig --levels 235 squid on

Step 3 » Setup your web browser to access Internet through proxy server on port 3128 .

IE : Tools » Internet options »Connections » LAN settings » Choose “Use a proxy server for your LAN” » Type your Proxy server ip (192.168.1.11 ) and port no 3128

Firefox : Options / Preferences » Advanced » Network » Settings » Choose “Manual proxy configuration ” » Type your Proxy server ip (192.168.1.11 ) and port no 3128

Step 4 » Browse some sites and check the access log file on proxy server

[root@localhost~]# cat /var/log/squid/access.log
1343759484.331  1828192.168.1.15TCP_MISS/2007005GET http://www.krizna.com/ – DIRECT/216.172.163.231 text/html
1343759484.645   265192.168.1.15TCP_MISS/304477GET http://platform.twitter.com/widgets.js – DIRECT/23.64.79.144 application/javascript
1343759484.681   309192.168.1.15TCP_MISS/304839GET http://apis.google.com/js/plusone.js – DIRECT/173.194.36.36 –
1343759485.005   178192.168.1.15TCP_MISS/200495GET http://www.google-analytics.com/__utm.gif? – DIRECT/74.125.236.142 image/gif
1343759502.763 20292192.168.1.15TCP_MISS/2001898CONNECTsstatic.ak.facebook.com:443DIRECT/23.64.66.110
1343759502.765 20292192.168.1.15TCP_MISS/2001898CONNECTsstatic.ak.facebook.com:443DIRECT/23.64.66.110
1343759723.040240567192.168.1.15TCP_MISS/2002904CONNECT plusone.google.com:443DIRECT/173.194.36.41
1343759933.642   958192.168.1.15TCP_MISS/304394GET http://www.krizna.com/ – DIRECT/216.172.163.231 –
1343759934.518   459192.168.1.15TCP_MISS/200495GET http://www.google-analytics.com/__utm.gif? – DIRECT/173.194.36.8 image/gif
1343759943.131  2186192.168.1.15TCP_MISS/2008343CONNECT www.facebook.com:443DIRECT/66.220.146.94
1343759943.266 10616192.168.1.15TCP_MISS/2002790CONNECT apis.google.com:443DIRECT/74.125.236.128
1343759943.267 10615192.168.1.15TCP_MISS/2002228CONNECT ssl.gstatic.com:443DIRECT/74.125.236.143
1343759950.875  2596192.168.1.15TCP_MISS/20032219CONNECT www.facebook.com:443DIRECT/66.220.146.94
1343759961.388 20443192.168.1.15TCP_MISS/2001911CONNECTsstatic.ak.fbcdn.net:443DIRECT/23.64.77.177

Configure squid proxy as web filter:

You can restrict user access to particularwebsites or keywords using access control lists (ACLs) .

Restricting Access to specific web sites:

For example , we can see how to block facebook.com and gmail.com .

Step 1 » create a file ( /etc/squid/blockedsites.squid ) and add the site names one per line.

root@localhost ~]# cat /etc/squid/blockedsites.squid
#blocked sites
www.facebook.com
www.gmail.com

Step 2 » Open the /etc/squid/squid.conf and create a new acl ” blocksites” and acl type “dstdomain” in the acl section like the below.

and add the following line “http_access deny blocksites” to http_section to deny the access to the acl “blocksites” .

Step 3 » Now restart squid service

[root@localhost ~]# service squid restart

Step 4 » Try to access facebook.com in your browser . you could see the blocked page as below .

and check the log file you can see the facebook request is denied .

squid-proxy-server-block-facebook

That’s it , hope this article will help you to learn little things about configuring squid proxy on centos 6.