• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to block with keywords and extensions in SQUID - Part 2

{{postValue.id}}

To add acl rule by keywords and extensions in SQUID

In this article we going to see about configuring acl rule by keywords and extensions.

To install and configure the squid visit the following link,

https://www.linuxhelp.com/how-to-install-and-configure-squid-part-1/

To Configure by keywords

Create a keyword_block.txt file with a list of keywords to block (or) allow in /etc/squid/

[root@linuxhelp user1]# vim /etc/squid/keyword_block.txt

list of keywords

Open the squid configuration file.

[root@linuxhelp user1]# vim /etc/squid/squid.conf

Enter the acl rule to block by keywords as shown below,

acl test src 192.168.5.219 192.168.5.63    
acl keyword_block  url_regex  " /etc/squid/keyword_block.txt" 
http_access deny test keyword_block
http_access  allow test

Explanations

1st line - Enter the source acl name as “ test” and entered the IP addresses/network address .
2nd line - Enter the acl name as “ keyword_block” and the path of the keyword list file.
3rd line - Enter the “ deny” option along with acl name test and keyword_block, so that any link which carries the keywords mentioned in the file will be denied for the IP’ s which comes under the acl name “ test” .
4th line - Enter “ allow test “ so that all other domains except the keywords in the file can be accessed.
list

Save the configuration file after entering the rule and reload the squid service

[root@linuxhelp user1]# service squid reload

Try to access the domain with the given keywords in the file, the following error appears.
proxy server error
Any link containing the keyword ‘ tube’ will be denied by the squid proxy server as we have mentioned it in the rule.
squid proxy server

Now, the acl rule for keyword block is successfully executed.

acl rule

To Configure by extension

Create a block list in ext_block.txt" file. Here we are adding the extensions mp3, mp4 and zip.

[root@linuxhelp user1]# vim /etc/squid/ext_block.txt

block list

Open the squid configuration file.

[root@linuxhelp user1]# vim /etc/squid/squid.conf

Enter the acl rule to block by extension

acl test src 192.168.5.219 192.168.5.63    
acl ext_block  url_regex  " /etc/squid/ext_block .txt" 
http_access deny test ext_block
http_access  allow test

Explaination

1st line - Enter the source acl name as “ test” and IP addresses.
2nd line - Enter the acl name as “ ext_block” and path of the extension list file.
3rd line - Enter the “ deny” option along with acl name test and ext_block so that in any webpages downloading the extensions like .mp3,.mp4,.zip will be denied for the IP’ s which comes under the acl name “ test” .
4th line - Enter “ allow test“ so that all other domains except the list in the file can be accessed and downloaded.

acl list

Save the file after entering the rule and reload the squid service.

[root@linuxhelp user1]# service squid reload

In the below example, you can see the squid proxy is refusing the connection of .mp3 file.
downloading error
The webpage is refused because it is a download link of .zip file.
refused webpage

To configure the Squid visit,
https://www.linuxhelp.com/how-to-configure-acl-rule-by-timing-and-browser-in-squid/

To limit bandwidth in Squid visit,
https://www.linuxhelp.com/how-to-limit-bandwidth-squid/

Tags:
benjamin
Author: 

Comments ( 2 )

parthiban
This is the local IP addresses used for testing Environment, instead of this IP's you can use your IP address
vam
192.168.5.219 192.168.5.63 what is this ip address
Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

Do I have to install squid on every desktop?

A

No you can maintain a separate server and just add a proxy to its client.

Q

whats difference between domain block and keyword block?

A

The domain block blocks the particular domain URL the keyword block filters the word from the URL in case if you doesn't know the complete URL

Q

Is it possible to add and maintain squid server via Gitlab

A

Yes. This is very efficeint method if you make changes from multile admins

Q

How to reload the Squid service ?

A

To reload the Squid service use the following command.

systemctl reload squid.service

Q

What's the legal status of Squid?

A

Squid is copyrighted by The Squid Software Foundation and contributors.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Isaiah ?
What is the use of SUID & SGID commands

How to set the special permissions to the files and folders using SUID and SGID commands...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.