How to disable / block sites with Squid Proxy ACL rules on Debian GNU / Linux – Setup Transparent Proxy

Squid transparant proxy disabling blocking websites with Squid proxy

Often when configuring new Firewall router for a network its necessary to keep log on HTTP (Web) traffic passing by the router. The best way to do this in Linux is by using Proxy server. There are plenty of different Proxy (Caching) servers for GNU / Linux. However the most popular one is Squid (WWW Proxy Cache). Besides this its often a requirement in local office networks that Proxy server is transparent (invisible for users) but checking each and every request originating from the network. This scenario is so common in middle sized and small sized organizations that its a must that every Linux admin is ready to easily configure it. In most of my experience so far I used Debian Linux, so in this post I will explain how to configure Transparent Squid Proxy with configured ACL block rules for employee's time wasting services like facebook / youtube / vimeo etc.

Here is diagram I found on a showing graphically below Squid setup:

Squid as transparent proxy behind nat firewall diagram

1. Install Squid Proxy Server

Squid is available as Debian package since a long time, so on Deb Linux installing Squid is a piece of cake.

debian-server:~# apt-get install --yes squid

2. Create /var/cache/proxy directory and set proper permissions necessary for custom config

debian-server:~# mkdir /var/cache/proxy
debian-server:~# chown -R proxy:proxy /var/cache/proxy

3. Configure Squid Caching Server

By default debian package extract script does include default squid.conf which should be substituted with my custom squid.conf. A Minor user changes has to be done in config, download my squid.conf from here and overwrite default squid.conf in /etc/squid/squid.conf. Quickest way to do it is through:

debian-server:~# cd /etc/squid
debian-server:/etc/squid# mv /etc/squid/squid.conf /etc/squid/squid.conf.orig
debian-server:/etc/squid# wget -q
debian-server:/etc/squid# chown -R root:root squid.conf

Now open squid.conf and edit lines:


Change which is IP assigned to eth1 (internal NAT-ted interface) with whatever IP of local (internal network) is. Some admins prefer to use local net addressing.
Below in configuration, there are some IPs from network configured through Squid ACLs to have access to all websites on the Internet. To tune such IPs you will have to edit lines after (1395) after comment

# allow access to filtered sites to specific ips

4. Disabling sites that pass through the proxy server

Create file /etc/disabled-sites i.e.:

debian-server:~# touch /etc/disabled-sites

and place inside all siles that would like to be inaccessible for local office network either through text editor (vim / pico etc.) or by issuing:

debian-server:~# echo '' >> /etc/disabled-sites
debian-server:~# echo ''' >> /etc/disabled-sites
debian-server:~# echo '' >> /etc/disabled-sites

5. Restart Squid to load configs

debian-server:~# /etc/init.d/squid restart
[ ok ] Restarting Squid HTTP proxy: squid.

6. Making Squid Proxy to serve as Transparent proxy through iptables firewall Rules

Copy paste below shell script to lets say /etc/init.d/





# forward to squid.
$IPT -t nat -I $PRER -p tcp -s -d ! –dport www -j $RED –to 3128
$IPT -t nat -I $PRER -p tcp -s -d ! –dport 3128 -j $RED –to 3128

# Reject connections to squid from the untrusted world.
# rules for order.
$IPT -A $IN -p tcp -s -d $ALL_NWORKS –dport 65221 -j $AC

$IPT -A $IN -p tcp -s $ALL_NWORKS –dport 65221 -j $REJ
$IPT -A $IN -i $OUT_B_IFACE -p tcp -s $ALL_NWORKS –dport 3128 -j $REJ

Easiest way to set up firewall rules is with:

debian-server:~# cd /etc/init.d/
debian-server:/etc/init.d# wget -q
debian-server:/etc/init.d# chmod +x
debian-server:/etc/init.d/# bash
Then place line /etc/init.d/ into /etc/rc.local before exit 0

That's all now Squid Transparent Proxy will be up and running and the number of sites listed in disabled-sites will be filtered for Office employees returning a status of Access Denied.

Access Denied msg

Gets logged in /var/log/squid/access.log example of Denied access for Employee with IP is below: - - [16/Oct/2013:16:50:48 +0300] "GET HTTP/1.1" 403 1528 TCP_DENIED:NONE

Various other useful information on what is cached is also available via /var/log/squid/cache.log and /var/log/squid/store.log

Another useful thing of using Transparent Squid Proxy is that you can always keep track on exact websites opened by Employees in Office so you can easily catch people trying to surf p0rn websites or some obscenity.

Hope this post helps some admin out there 🙂 Enjoy

Share this on:

More helpful Articles

Download PDFDownload PDF

Tags: , , , , , , , ,

4 Responses to “How to disable / block sites with Squid Proxy ACL rules on Debian GNU / Linux – Setup Transparent Proxy”

  1. Nannie says:
    Google Chrome 27.0.1453.116 Google Chrome 27.0.1453.116 Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36

    Hey this is somewhat of off topic but I was wondering if
    blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding expertise so I wanted to get guidance from someone with experience.

    Any help would be enormously appreciated!

    View CommentView Comment
  2. Ramesh says:
    Firefox 29.0 Firefox 29.0 Windows XP Windows XP
    Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0

    Dear Sir,

    I want to make a transparent proxy in Redhat 5.3. So please help me about this topic.Because in configure Squid but users are bypass the proxy and open these website those are not allowed to open like facebook and gmail.

    Kindly help me about this topic as soon as posibel.

    Kind regards.



    View CommentView Comment
    • admin says:
      Firefox 29.0 Firefox 29.0 Windows 7 x64 Edition Windows 7 x64 Edition
      Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0

      Hello Remesh,

      Just create the /etc/disabled-sites file as empty and facebook and gmail will not be blocked. Omit

      echo '' >> /etc/disabled-sites
      echo ''' >> /etc/disabled-sites
      echo '' >> /etc/disabled-sites



      View CommentView Comment
      • Ramesh says:
        Firefox 30.0 Firefox 30.0 Windows XP Windows XP
        Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0


        Thanks for your quick response.

        Please explain it.  I can't understand the way you explain.

        If required I can send a sample of my squid file configration.


        Ramesh Mudad

        View CommentView Comment

Leave a Reply

CommentLuv badge