Skip to main content

How to install squid proxy on centos 6

Squid proxy :

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 krizna.com from the ISP during the first request and it will deliver the cached content for the further requests of krizna.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
» Restricting Access to specific web sites
» Restricting Access to specific keywords
» Restricting Access to specific ipaddress
» Allow Full access to specific ipaddress
» Changing squid proxy port number
» Restricting download size
» Configure squid as transparent proxy

» Install squid proxy on centos 6 :

In this article we can see how to install and configure squid proxy on centos 6 .  After installing Centos 6 (Centos 6 installation step by step screenshots ) and configuring network (How to setup network in centos 6)
Update yum repositories and packages by typing the below command

[root@leela ~]# yum update

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

[root@leela ~]# 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

Step 2» Now start squid service

[root@leela ~]# service squid start

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

[root@leela ~]# 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

Troubleshooting :

If you not able to browse using proxy settings , Disable the firewall ( iptables ) and selinux service on your squid proxy server .
Disable firewall ( Iptables ) »
[root@leela ~]# service iptables stop
[root@leela ~]# chkconfig iptables off

Disable Selinux  » open the file /etc/selinux/config and find the line
SELINUX=enforcing

and replace with
SELINUX=disabled

now reboot the server and try step 4.

Configure squid proxy as web filter:

You can restrict user access to particular websites 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@leela ~]# 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@leela ~]# service squid restart

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

squid proxy server block

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

» Restricting Access to specific keywords :

Step 1 » create a file ( /etc/squid/blockkeywords.squid ) and add the keywords one per line.
[root@leela ~]# cat /etc/squid/blockkeywords.squid
#blocked keywords
sex
porn
xxx

Step 2 » Open the /etc/squid/squid.conf and create a new acl “blockkeywords” and acl type “url_regex” in the acl section

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

» Restricting Access to specific Ipaddress :

Step 1 » create a file ( /etc/squid/blockip.squid ) and add the ip adresses one per line.
[root@leela ~]# cat /etc/squid/blockip.squid
#blocked ips
192.168.1.20
192.168.1.21

Step 2 » Open the /etc/squid/squid.conf and create a new acl “blockip” and acl type “src” in the acl section

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

» Allow Full access to specific Ipaddress :

You can allow specific ip address to gain full access without blocking sites and keywords . just create a file “/etc/squid/allowip.squid ” and add the ip address one per line and create an acl “allowip”  and acl type “src” in the acl section

and add the “allowip” in the http_access as below

» Changing squid proxy port number:

You can change squid proxy port number , by default it uses 3128 port .

Just find the below line in “/etc/squid/squid.conf”

http_port 3128

and replace with

http_port 8000 # whatever port number you want

» Restricting Download size :

You can restrict download file size  using reply_body_max_size .

Add the below line at the bottom of the http_access section

#Restrict download size
reply_body_max_size 10 MB all

or

#Restrict download size
reply_body_max_size 10 MB !allowip

» Configuring Squid as Transparent Proxy :

You can configure squid as transparent proxy .

Step 1 » just find the below line

# Squid normally listens to port 3128
http_port 3128

and replace with

# Squid normally listens to port 3128
http_port 3128 intercept

Step 2 » Create a file “/root/squidfw.sh” and add the following firewall script ( modify as per your interface configuration ).

Step 3 » just run the script
[root@leela ~]# sh /root/squidfw.sh
and add the below line to “/etc/rc.local” to run the script during startup
sh /root/squidfw.sh
Step 4 (Updated) » Change default gateway ip to squid server ip on the user machines .
Now users can access Internet without setting proxy in the browser settings.

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