Squid Server Configuration On CentOS7
Squid Server Configuration On CentOS7
Installing Squid
Before installing any packages, it is recommended to update the
system and packages using the following command.
yum -y update
Now you can install Squid Proxy using the following command.
Once you install Squid, you can start the program immediately
using the following command.
squid -h
squid -v
You can check the error logs of Squid using the following
command.
tail -f /var/log/squid/access.log
Configuring Squid
Squid can be easily configured by editing the global
configuration file /etc/squid/squid.conf. To edit the configuration
file run the following command.
nano /etc/squid/squid.conf
You can use any editor of your choice, in this tutorial we will
be using nano editor. If you don't have nano editor installed,
you can run yum -y install nano command to install nano editor.
#
# Recommended minimum configuration:
## Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where
browsing
# should be allowed
acl localnet src 10.0.0.0/8 # RFC1918 possible internal
network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal
network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal
network
acl localnet src fc00::/7 # RFC 4193 local private
network range
acl localnet src fe80::/10 # RFC 4291 link-local
(directly plugged) machinesacl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports# Deny CONNECT to other than
secure SSL ports
http_access deny CONNECT !SSL_ports# Only allow cachemgr
access from localhost
http_access allow localhost manager
http_access deny manager# We strongly recommend the
following be uncommented to protect innocent
# web applications running on the proxy server who think the
only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR
CLIENTS
## Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal)
IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost# And finally deny all other
access to this proxy
http_access deny all# Squid normally listens to port 3128
http_port 3128# Uncomment and adjust the following to add a
disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256# Leave coredumps
in the first cache dir
coredump_dir /var/spool/squid
For changes to take effect you will need to restart your Squid
server, use the following command for same.
systemctl restart squid
The ports which are not listed above will not be accessed
through the proxy. You can add a Port into the list
of Safe_ports by modifying the list of ACLs for ports. For example
it you want to allow port 168 to be accessed through the proxy
server you can add the following ACL entry for this.
For changes to take effect you will need to restart your Squid
server, use the following command for same.
Now create a new file and provide the ownership to squid daemon
so that it can access it. Run the following command for same.
Now you can add a new user to the password file using
the htpasswd tool. In this tutorial we will be creating an example
user pxuser. You can replace pxuser with anything you like. Run
the following command to create a new user using htpasswd tool.
It will ask for the new password twice, provide the password and
you will see following output.
As we have our password file ready, you can now edit the squid
configuration file using the following command.
nano /etc/squid/squid.conf
Add the following lines into the configuration file under the
access control lists of ports.
Write the changes to the file and exit from editor. Reload the
Squid daemon using the following command.
Now if you will try to use the proxy server, it will ask you for
authentication. Provide your username and password and you will
be able to use the proxy server. Unauthenticated user will be
shown an error page.
Blocking Websites
You can easily block a single or a list of websites from the
users. Using a separate file for the list of websites to be
blocked is a good way to manage the blocked websites. Create a
new file to store the list of websites to be blocked using your
favorite editor.
nano /etc/squid/blocked_sites
Now enter the list of sites you want to block. One website per
line.
liptanbiswas.com
liptan.com
Save the file and exit the editor. In this example we used some
example websites, you can put a list of actual websites you wish
to block. Now open the Squid configuration file again using the
following command.
nano /etc/squid/squid.conf
Enter the following lines under acl list and http_access list.
Write the changes to the file and exit from editor. Reload the
Squid daemon using the following command.
Now if you will try to access the blocked sites, you will get
an access denied message from Squid.
nano /etc/squid/squid.conf
Scroll down to find the following lines into the file.
Now change the http_port from 3128 to any port you want. Make sure
that no other service is using the port which you will use for
Squid. Now restart the Squid daemon and you will see that the
changes are in effect.
Conclusion
In this detailed tutorial we learned how to install Squid proxy
server on CentOS 7 systems. You can now easily setup a basic
installation of Squid. You also learnt about some basic
configuration of Squid proxy server including enabling basic
authentication.