Squid proxy server to block websites listed in file

In this tutorial we will use Squid proxy server to block websites listed in file. Here,we will list the website in a file called “restricted-sites.squid”.
In our last post we have already setup the squid transparent proxy. The How to guide will help to install and configure the latest Squid Server.

Advantage of using file listed with restricted websites

(1) We can easily manage and search the website in a file
(2) We can write many website name in the file.Because of this,our squid configuration file looks clean and easy to understand
(As a System Administrator,always try to keep Server configuration file clean and understandable)

Precautions while configuring the Squid server

(1) Always write configuration to its related section. For eg. If you are writing acl ,it should not be written in other section.
(2) The configuration parameters are case sensitive

Squid Proxy Server configuration to block websites listed in a file

Follow the given below steps in Squid Server to block websites which are listed in file.

Step 1: Create a file /etc/squid/restricted-sites.squid. And write website name in the file which you want to block.
For example,I have given website name sharad.me . Like wise you can write as many different website name you want to restrict.

vi /etc/squid/restricted-sites.squid

sharad.me
www.sharad.me
http://sharad.me

Step 2: Be careful while writing this configuration. Write the configuration which is specific to particular section.

Edit /etc/squid/squid.conf file and write two configuration settings.

In acl section , write a new line

acl blocksites dstdomain "/etc/squid/restricted-sites.squid"

In http_access deny section,write new line

http_access deny blocksites

If you are doing this first time, the below screenshot is recommended for you.
Closely see,how the acl section and https_access section has the above given configuration written.

Squid restricted sites

Step 3: Now restart the squid service

/etc/init.d/squid restart

13 thoughts on “Squid proxy server to block websites listed in file”

  1. hi i have problem i’m using proxy for block facebook and some site but the users used hola vpn for unblock my proxy can u gave the solution pls

    Reply
  2. I have reverse problems …

    1. clients cannot reach the proxy server. i have specified the correct ip address and correct port (3128 default).

    2. clients cannot access any website, even though i have allowed that specific client IP address via

    acl allowed src 192.168.0.18/32
    http_access allow allowed

    Reply
  3. Hi Sharad,

    Your blog is very use full, I like your blog
    I have one requirement in my environment
    Setup for “squid proxy” with TLS,Please share me if you have any documentation

    Reply
  4. Thanks for this. Worked well.

    Need a help with extension to this. After blocking sites as mentioned, how can I allow certain IP’s to access the restricted sites?

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.