Hello.

After installing Squid, SquidGuard might be useful, a “plugin” for Squid to control and redirect URLs processed by Squid, useful for blocking malicious and unwanted sites.

Let’s proceed with the installation

sudo apt-get install squidGuard

and of course immediately after with the configuration

sudo vi /etc/squidguard/squidGuard.conf

where you need to add/modify these lines

dbhome folders_path logdir /var/log/squid3

# DESTINATION CLASSES:

dest ads { #location of blacklists, domains, urls, expressions. domainlist folder_name/ads/domains urllist folder_name/ads/urls expressionlist folder_name/ads/expressions }

# ACL RULES:

acl { default { #allow except ‘ads’ pass !ads all #redirect to transparent gif redirect http://localhost/blank.gif

} }

“folders_path” = path where to put the folders with the files containing the list of URLs to block

“folder_name” = name of the folder where the URLs will be placed

Pay attention to where this folder is placed and to the permissions and owner (user and group) assigned; for example, I put this folder in the same folder as SquidGuard, copying it as administrator, so then I had to change user and group from root and root to my_user and my_group. Check carefully also after a service restart and/or machine reboot: new files will be created for which you’ll need to change permissions as above; to be safe, I also gave execution permissions to the user.

Let’s initialize the SquidGuard database (to be done every time you update the URL list)

sudo squidGuard -C all

and to be sure there were no errors, check the log files

sudo cat /var/log/squidguard/squidGuard.log

To get a list, or rather a blacklist of URLs, just search on Google, but I recommend URLBlacklist: by downloading the file, you’ll find many folders inside divided by categories; I copied the URLs of the categories dialers, phishing, spyware, virusinfected into the respective “domains” and “urls” files so as to have greater coverage.

Now let’s modify the Squid configuration file

sudo vi /etc/squid/squid.conf

and add under

# TAG: url_rewrite_program

this

#SquidGuard url_rewrite_program /usr/bin/squidGuard -c /etc/squidguard/squidGuard.conf url_rewrite_children 5 #threads url_rewrite_concurrency 0 #jobs per threads

finally restart Squid

service squid restart

Bye!

! :) !

Source:

http://thejimmahknows.com/network-adblocking-using-squid-squidguard-and-iptables/