Squid proxy How to filter or block a particular port

last updated in Categories , , , , , , , ,

Q. I am using Debian stable Linux version and squid proxy server for our small software company. I need to block a port number 1234. How to filter a particular port?

A. You can easily filter any port with squid ACL (Access Control List).

ACL is used for defining an access List. When using “file” the file should contain one item per line By default, regular expressions are CASE-SENSITIVE. To make them case-insensitive, use the -i option.

Procedure to block a port

First open /etc/squid/squid.conf file
# vi /etc/squid/squid.conf
Locate your ACL section and add configuration directive as follows:
acl block_port port 1234
http_access deny block_port
http_access allow all

If you just want to skip a particular IP (192.168.1.5) try as follows:
acl block_port port 1234
acl no_block_port_ip src 192.168.1.5
http_access deny block_port !no_block_port_ip
http_access allow all

Close and save the file.

Restart squid proxy server:
# /etc/init.d/squid restart

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 15 comments/add one below):

15 comment

  1. Opened ACL.But could not understand where to write the configuration changes as u have stated.Plz help its urgent.

  2. Hi,

    I tried your given the instruction port blocking for yahoo messanger, gtalk but its not working that rule..

    acl porttest port 5050 5222 5223
    acl block_port port 5050 5222 5223
    acl test src 172.27.162.43
    http_access deny block_port test
    http_access allow all

    Please help me how to port level blocking partiucalar src ip’s

    Its possible to deny particular port ??

    Thanks
    Yagnes
    s.yagnes@gmail.com

  3. Hi,

    I tried your given the instruction port blocking for yahoo messanger, gtalk but its not working that rule..

    acl block_port port 5050 5222 5223
    acl test src 172.27.162.43
    http_access deny block_port test
    http_access allow all

    Please help me how to port level blocking partiucalar src ip’s

    Its possible to deny particular port ??

    Thanks
    Yagnes
    s.yagnes@gmail.com

  4. sir,
    i’m using redhad 5 server edition. i config squid.config for particular websites can’t access. but now i want to particular my netwok ip’s only allowed particular website only other website totaly blocked. how do done this?..
    example
    my n/w is 191.168.0.0/255.255.0.0
    but 191.168.3.6 ip user only access gmail.com other website totally block how to done this?
    note: particular websites only i want to allow other website i want to deny how?
    how to done this plz help[replay] me….

  5. Hello,

    Can we try multiple ip’s should be exempted in blocked search, like, –

    acl no_block_port_ip src 192.168.1.5, 192.168.1.6, 192.168.1.4
    http_access deny block_port !no_block_port_ip

    Please guide me.

  6. Hello,

    I have a RHEL 5 Proxy server. my client on Window XP or Window Vista.
    How can I block any user MAC Address to access Internet

    Please guide me.

  7. i want allow and block website by physical address in squid.
    how can i do ?
    but with ip4 i already done.

    Have a question? Post it on our forum!