Restricting Access to specific web sites/keywords in squid

Squid is one of the most popular proxy server which can be employed to run on linux servers.

Let us see how to block accessing certain sites using Squid.

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

Like;

[root@server ~]# cat /etc/squid/blockedsites.squid
 #blocked sites
 www.yahoomail.com
 www.gmail.com

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

acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
# ACL blocksites
acl blocksites dstdomain “/etc/squid/blockedsites.squid”

 

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

 

# Recommended minimum Access Permission configuration:
# Only allow cachemgr access from localhost
http_access allow manager localhost
# Deny access to blocksites ACL
http_access deny blocksites

 

Step 3 » Time to restart squid service

[root@server ~]# service squid restart

 

Restricting Access to specific keywords :

Step 1 » create a file ( /etc/squid/blockkeywords.squid ) and insert the keywords one per line.

[root@server ~]# cat /etc/squid/blockkeywords.squid
#blocked keywords
sex
porn

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

# ACL blocksites

acl blocksites dstdomain “/etc/squid/blockedsites.squid”
# ACL blockkeywords
acl blockkeywords url_regex -i “/etc/squid/blockkeywords.squid”

 

Then insert the following line “http_access deny blockkeywords” to http_section to deny the access to the acl
“blockkeywords” .

 

http_access allow manager localhost
# Deny access to blocksites ACL
http_access deny blocksites
# Deny access to blockkeywords ACL
http_access deny blockkeywords

 

 

 

Revisions

There are no revisions for this post.

Tags: , ,

No comments yet.

Leave a Reply