How to Install and configure Squid proxy server on CentOS 8.1

How to Install and configure Squid proxy server on CentOS 8.1

Introduction:

Squid is a caching and forwarding HTTP web proxy. It is used for speeding up a web server by caching repeated requests, caching web, DNS and other computer network lookups. This is made for a shared network resources and filtering traffic. This tutorial covers the installation process of squid proxy on CentOS 8.1

Installation process:

To Install proxy server, use below command

[root@linuxhelp ~]# yum install squid
Last metadata expiration check: 2:19:14 ago on Friday 23 October 2020 12:53:06 PM IST.
Dependencies resolved.
Installing:
 squid                 x86_64       7:4.4-8.module_el8.2.0+319+d18e041f.1       AppStream       3.5 M
Installing dependencies:
 libecap               x86_64       1.0.1-2.module_el8.2.0+319+d18e041f         AppStream        29 k
 perl-Digest-SHA       x86_64       1:6.02-1.el8                                AppStream        66 k
Is this ok [y/N]: y
Downloading Packages:
(1/3): libecap-1.0.1-2.module_el8.2.0+319+d18e041f.x86_64.rpm         120 kB/s |  29 kB     00:00    
 (3/3): squid-4.4-8.module_el8.2.0+319+d18e041f.1.x86_64.rpm           779 kB/s | 3.5 MB     00:04    
------------------------------------------------------------------------------------------------------
Total                                                                 731 kB/s | 3.6 MB     00:05     
:                                                                              1/1
  Installing       : perl-Digest-SHA-1:6.02-1.el8.x86_64   
   ……
   …….
   ……..                                       
  libecap-1.0.1-2.module_el8.2.0+319+d18e041f.x86_64                                                  
  perl-Digest-SHA-1:6.02-1.el8.x86_64                                                                 
Complete!

To start squid proxy service type

[root@linuxhelp ~]# systemctl start squid

Now enable the squid service

[root@linuxhelp ~]# systemctl enable squid
Created symlink /etc/systemd/system/multi-user.target.wants/squid.service → /usr/lib/systemd/system/squid.service.

Check status for squid proxy server using below command

[root@linuxhelp ~]# systemctl status squid
● squid.service - Squid caching proxy
   Loaded: loaded (/usr/lib/systemd/system/squid.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-10-23 15:14:26 IST; 21s ago
 

Now open squid configuration file.

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

Now in squid.conf file create an “acl”

acl localnet src 192.168.7.0/24
http_access allow localnet

Now to put some rules create an acl

acl badsites url_regex “/etc/squid/badsites”
http_access deny badsites

to create “badsite” file to put some links which to be block

[root@linuxhelp ~]# vim /etc/squid/badsites

Give the links which needs to be blocked in file.

.facebook.com
.flipkart.com
.amazon.in

To add squid port number in firewall to allow it pass through it

[root@linuxhelp ~]# firewall-cmd --permanent --add-port=3128/tcp
Warning: ALREADY_ENABLED: 3128:tcp
success

Reload the firewall

[root@linuxhelp ~]# firewall-cmd --reload
success

restart squid to reflect changes what have been made

[root@linuxhelp ~]# systemctl restart squid

move to client pc to configure squid proxy server Ip address This is “access-denied “page badsites file blocked by squid proxy server. Google is allowed hence this page is loading

With this, the method of installation squid proxy server on CentOS8.1 comes to an end.

Tag : Squid CentOS
Comment
abhishekkumar
Sep 12 2022
I follow your tutorial, all commands go to successful But my internet is not working why
Add a comment
FAQ
Q
What this command "squid -z" will do ?
A
this command will create cache directories.
Q
What is the location of cache storage in the Squid?
A
The squid stores cache in /var/spool/squid.
Q
Squid stores data in which file format?
A
Squid stores data in ufs (Unix File System) format also called the Berkeley Fast File System.
Q
From where squid configuration file can be accessed?
A
We can access it by Vim using vim /etc/squid/squid.conf.
Q
What is the default port of the squid ?
A
The default port on which squid runs is 3128.