SQUID Proxy Server
A proxy server is a device that usually sits between a client and the destination the user is trying to reach. It can provide security, anonymity, and even protection for the client behind the proxy. To help in this process is Squid, which is a web proxy server for Red Hat. It sits between the client and web server that the user is trying to connect to. Many times these devices are used when you want to control access to the Internet (think web filtering). As a web proxy, it can also cache data that users request from the Web and make it locally available, reducing the load on your external devices such as gateways and firewalls.
A Squid proxy server is generally installed on a separate server than the Web server with the original files. Squid works by tracking object use over the network. Squid will initially act as an intermediary, simply passing the client’s request on to the server and saving a copy of the requested object. If the same client or multiple clients request the same object before it expires from Squid’s cache, Squid can then immediately serve it, accelerating the download and saving bandwidth.
Installing the squid package:
By default the squid package is not installed, check whether the package is installed or not by using the following command.
[root@centos Desktop]# rpm -qa|grep squid squid-3.3.8-26.el7.x86_64
If the package is not installed install it by using yum install command
[root@centos Desktop]# yum install squid Loaded plugins: fastestmirror, langpacks Resolving Dependencies --> Running transaction check ---> Package squid.x86_64 7:3.3.8-26.el7 will be installed --> Processing Dependency: libecap.so.2()(64bit) for package: 7:squid-3.3.8-26.el7.x86_64 --> Running transaction check ---> Package libecap.x86_64 0:0.2.0-9.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================== Package Arch Version Repository Size ====================================================================== Installing: squid x86_64 7:3.3.8-26.el7 base 2.6 M Installing for dependencies: libecap x86_64 0.2.0-9.el7 base 20 k Transaction Summary =========================================================================== Install 1 Package (+1 Dependent package) Total download size: 2.6 M Installed size: 8.6 M Is this ok [y/d/N]: y Downloading packages: (1/2): libecap-0.2.0-9.el7.x86_64.rpm | 20 kB 00:17 (2/2): squid-3.3.8-26.el7.x86_64.rpm | 2.6 MB 00:25 ---------------------------------------------------------------------------- Total 103 kB/s | 2.6 MB 00:25 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libecap-0.2.0-9.el7.x86_64 1/2 Installing : 7:squid-3.3.8-26.el7.x86_64 2/2 Verifying : 7:squid-3.3.8-26.el7.x86_64 1/2 Verifying : libecap-0.2.0-9.el7.x86_64 2/2 Installed: squid.x86_64 7:3.3.8-26.el7 Dependency Installed: libecap.x86_64 0:0.2.0-9.el7 Complete!
Start the service and set it to be start at Boot time.
[root@centos Desktop]# systemctl enable squid Created symlink from /etc/systemd/system/multi-user.target.wants /squid.service to /usr/lib/systemd/system/squid.service.
[root@centos Desktop]# systemctl start squid [root@centos Desktop]# systemctl status squid ● squid.service - Squid caching proxy Loaded: loaded (/usr/lib/systemd/system/squid.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2016-03-21 13:00:11 IST; 7s ago Process: 16554 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (code=exited, status=0/SUCCESS) Process: 16542 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS) Main PID: 16601 (squid) CGroup: /system.slice/squid.service ├─16601 /usr/sbin/squid -f /etc/squid/squid.conf ├─16603 (squid-1) -f /etc/squid/squid.conf └─16657 (logfile-daemon) /var/log/squid/access.log Mar 21 13:00:10 centos systemd: Starting Squid caching proxy... Mar 21 13:00:11 centos squid: Squid Parent: will start 1 kids Mar 21 13:00:11 centos squid: Squid Parent:squid-1 process16603 ...ed Mar 21 13:00:11 centos systemd: Started Squid caching proxy. Hint: Some lines were ellipsized, use -l to show in full. [root@centos Desktop]#
The Main Configuration file for Squid can be located at /etc/squid/squid.conf
The sample code of squid.conf file is as follows
# # 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) machines acl 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 # # Add any of your own refresh_pattern entries above these. # refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern . 0 20% 4320
Un-comment and adjust the following to add cache directory.
Restart the squid service and Add firewall rule to allow squid 3128 port.
[root@centos Desktop]# systemctl restart squid
firewall-cmd –zone=public –add-port=3128/tcp –permanent
Save rules and restart service.
Done configuration part now time to test browsing pointing squid ip and default port in client browser.
Open up firefox browser and go to Tools > Options > Advance tab > Network > Settings > select manual proxy settings radio button and provide squid server IP 10.0.0.1(here i used server ip address is 10.0.0.1) and port 3128 and check use this use this proxy server for all protocols and then click oK.
see squid access.log file by using following command.
tail -f /var/log/squid/access.log
Now enjoy the internet and also save your bandwidth by using the cache server.
originally sourced: https://www.unixmen.com/install-configure-squid-proxy-server-rhelcentos/