In most cases, a company wants to efficiently maximize their bandwidth use. As you know, you can speed up your loading time when browsing by using Squid as a web cache. I’m not going to tell you how Squid works or how to install it. For more details about Squid you can refer to my old post about how to install Squid and monitor it. Now the next case is you feel your internet connection is slow, even when using Squid as a web cache.
After taking some time looking at the Squid log, you know that some of your colleagues are watching video online like YouTube, Metacafe, Google Video, Facebook, etc. and you want to finish your work at the time. This is very annoying. And also because of this the company productivity is getting lower. I’m sure you know this would be a great loss for a company.
In this article I will show you how to solve that with Squid. You can block/filter some websites or even IPs during work hours. This would increase productivity and improve bandwidth efficiency. Let’s begin.
Now I will show you step by step how to make a filter in Squid — I’m sure you are familiar with shell commands in Linux.
Please follow these steps:
1. Make a file in /etc/squid/ called denied_domains.acl with this command:
touch /etc/squid/denied_domains.acl
2. Open that denied_domains.acl with this command:
vim /etc/squid/denied_domains.acl
3. Now put every website that you want to block (one per line). Mine looks like this:
.friendster.com
.metacafe.com
.myspace.com
.videos.google.com
.youtube.com
.metacafe.com
.facebook.com
Note: you can add as many as you like, and later you can add or remove by editing this file.
4. Now save and close that file.
5. Open squid.conf, usually it will be in the /etc/squid/ folder. Or type this command:
vim /etc/squid/squid.conf
6. Add these lines in your squid.conf:
acl workinghour time MTWHFA 09:00-16.59
acl restricted-domain dstdomain "/etc/squid/denied_domains.acl"
acl blacklist_ip src 172.16.144.11-172.16.144.100/32
Explanation: The first line means you create your working-hour variable, where MTWHFA means days (M=Monday, T=Tuesday, W=Wednesday, H=Thursday, F=Friday, A=Saturday, S=Sunday) and working time with this format h1:m1-h2:m2 where h1:m1 should be lower than h2:m2. The second line creates a variable for which domains should be blocked. The third line defines which IPs should be blocked from the restricted domains.
7. Now add the filter action — put this at the rule line:
http_access deny restricted-domain workinghour blacklist_ip
8. OK, now it’s finished. Save and close squid.conf.
9. Restart your Squid with this command:
/etc/init.d/squid restart
Test it with the defined IP to the restricted domain during working hours. And you will see the page show “Access is denied”.
Easy, right? Leave any comment if you have any tips or tricks that I missed, or just say hi if you like this article. Thanks and have a nice day.
