Filtering Data using Squid

In this lesson, we will configure squid to filter data traveling via squid. In case will be discussed in separated steps.

1. To block access to a particular remote sites for example www.porn.com having IP address 10.2.1.9, add following tags in squid.conf:

acl blocked_sites dstdomain www.porn.com

acl blocked_ip dst 10.2.1.9

http_access deny blocked_sites

http_access deny blocked_ip

Note, we need to block both DNS name and IP address of blocked sites, otherwise users still can access the sites using their IP address. dst keyword tells the following argument will be a destination address, while dstdomain keyword tells the following arguments will be a destination domain name.

 

2. To block any mp3 download, add following configuration in squid.conf:

acl file_mp3 urlpath_regex -i \.mp3$

http_access deny file_mp3

the urlpath_regex keyword tells squid to filter the urlpath of client's requests and do filtering using regex expression that follows the keyword ( \*.mp3$)
 
3. To block more specifically any mp3 download containing word "sex" in the filename, add following configuration in squid.conf:

acl file_mp3 urlpath_regex -i sex*\.mp3$

http_access deny file_mp3

 

4. To block users from accessing internet during office hours (08.00 to 14.00) from Monday to Friday, add following configuration in squid.conf:
acl office_hours time MTWHF 8:00-14.00
http_access deny office_hours
keyword time in the first line indicate the type of acl is time restriction. The argumen followed is the weekday and hour duration. The abbreviation for week days are:
S= Sunday, M= Monday, T=Tuesday, W=Wednesday, H=Thursday, F=Friday, A= Saturday