How to install and configure Squid on Linux Ubuntu Server 18.04 – Do you want to build an ubuntu linux based server and want to make your internet network much faster than before? If so, then here is the right place for you because in this article I will present an article on how to install Squid on Linux ubuntu server 18.04.
By installing Squid and configuring it properly, you can speed up the internet network speed at your place or on some of your client computers. Let’s first learn about Squid and how Squid can make your internet network access faster than before and we will continue to the core discussion, namely how to install Squid and configure Squid on ubuntu.
What is Squid?
Squid is a daemon that is used as a proxy server and web cache. Squid has many types of uses, from speeding up web servers by performing repetitive query caching, DNS caching, website caching, and search caching for computers on the network for a group of computers using the same network resources, to assisting security with how to do a traffic filter. Although used mostly for the HTTP and FTP protocols, Squid also offers limited support for several other protocols including Transport Layer Security (TLS), Secure Socket Layer (SSL), Internet Gopher, and HTTPS. Version 3.1 includes support for the IPv6 protocol and the Internet Content Adaptation Protocol (ICAP).
Squid is generally designed to run on a UNIX-like operating system, although Squid can also run on the Windows operating system. Because it is released under the GNU General Public License, Squid is free software.
Caching is a way of storing requested Internet objects (such as web page data) accessible via HTTP, FTP and Gopher on a system that is closer to the site requesting it. Some web browsers can use the local Squid cache to act as an HTTP proxy server, thus reducing access time and of course bandwidth consumption. It is often useful for Internet service providers to increase speed to their subscribers, and for LANs that share Internet channels. Because it is a proxy (it acts like a client, according to client requests), the web cache can provide anonymity and security. However, web cache can also be a significant problem when looking at privacy issues, because indeed it can log a lot of data, including the URL requested by the client, when it happened, the name and version of the web browser the client is using and the operating system from, and where it came from. he accesses that site.
Furthermore, a client program (for example, a web browser) can explicitly determine which proxy server to use if it wants to use a proxy (generally for ISP customers) or it can also use a proxy without extra configuration, which is often referred to as “Transparent Caching”, where all HTTP requests to outside network will be processed by the proxy server and all responses are stored in cache. The second case generally takes place within companies and corporations (all clients are on the same LAN) and often has the privacy concerns noted above.
Squid has many features that can help make connections anonymously, such as modifying or turning off certain header fields in an HTTP request submitted by a client. When that happens, what Squid will do depends on the person handling the computer running Squid. People requesting web pages over a network that is transparently used usually do not know that all the HTTP requests they submit are logged by Squid. (Source: Indonesian Wikipedia)
In this article, I will guide you to setup and install the latest Squid proxy server on Ubuntu.
All you need to get started is:
- Ubuntu operating system
- Access to a terminal window / command line (Ctrl-Alt-T)
- Ubuntu users with root or sudo permissions (How to Create Sudo Users and Sudo Group on Ubuntu)
- The apt package installer, included by default
- Text editors, such as nano
How to Install Squid Proxy on Ubuntu
Step 1: Refresh Software Repositories
Make sure you are working with the latest software version available.
Open a terminal window, and enter the following:
sudo apt-get update
Step 2: How to Install Squid Packages on Ubuntu
To install Squid, run the command:
sudo apt-get install squid
The system should ask for confirmation – enter (Y) and let the process complete.
Configure Squid Proxy Server
The Squid configuration file is found at /etc/squid/squid.conf.
1. Open this file in your text editor with the command:
sudo nano /etc/squid/squid.conf
2. Navigate to find http_port option. Typically, it is set to listen on Port 3218. This port usually carries TCP traffic. If your system is configured for traffic on other ports, change it here.
You can also set the proxy mode to be transparent if you want to prevent Squid from changing your requests and responses.
Replace it with the following:
http_port 1234 transparent
3. Navigate to the options http_acacess deny all. Currently configured to block all HTTP traffic. This means no web traffic is allowed.
Replace it with the following:
http_access allow all
4. Navigate to the option visible_hostname. Add the name you want to this entry. This is how the server will appear to anyone trying to connect. Please save changes (Save Changes) and exit (exit).
5. Restart the Squid service by entering:
sudo systemctl restart squid
Configure the Squid Client
All of these configurations have been prepared for your Squid proxy server. Now, switch over to your client machine and open your web browser.
If you are using Firefox, you can find the proxy settings on the menu:
Menu → Options → Network Settings → Settings
Check the radio button for manual proxy configuration.
If you entered a hostname in Step 4, you should be able to enter that name as well as the port you designated. Otherwise, use the IP address for your Squid proxy hosting system.
To test it, you can visit https://whatismyipaddress.com/ip-lookup – if your proxy is working, your IP address will be displayed as the proxy server IP address.
Add Squid ACL
Note: After each time you follow this step, you must save and exit, then restart the Squid service to apply the new configuration.
Create an access control list by editing the squid.conf file again, as in Step 4.
Add a new line as follows:
acl localnet src 192.168.0.15
This will create a rule that only allows the systems at this IP address to connect. It is recommended that you comment out the lines to identify the rules:
acl localnet src 192.168.0.15 # test computer
Anything after the # sign is ignored by Squid.
You can define the IP address ranges as follows:
acl localnet src 192.168.0.15/30
To open a specific port, add the following:
acl Safe_ports port 123 # Custom port
Configure Proxy Authentication
This forces the user to authenticate to use the proxy.
Start by installing apache2-utils:
sudo apt-get install apache2-utils
Create a passwd file, and change the ownership to the Squid proxy user:
sudo touch /etc/squid/passwd
sudo chown proxy: etc/squid/passwd
Add a new user and password
1. To add a new user to Squid, use the command:
sudo htpasswd /etc/squid/passwd newuser
The system will ask you to enter and confirm a password for the new user.
2. Edit the file /etc/squid/squid.conf, and add the following command line:
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid Basic Authentication
auth_param basic credentialsttl 2 hours
acl auth_users proxy_auth REQUIRED
http_access allow auth_users
Block Websites on Squid Proxy
1. Create and edit a new text file /etc/squid/blocked.acl by entering:
sudo nano /etc/squid/blocked.acl
2. In this file, add the website that you want to block, starting with a period, for example:
Note: The point determines to block all subsites of the main site.
3. Open the file again /etc/squid/squid.conf:
sudo nano /etc/squid/squid.conf
4. Add the following line just above your ACL list:
acl blocked_websites dstdomain “/etc/squid/blocked.acl”
http_access deny blocked_websites
Commands that are frequently used when working with the Squid Service
To check the status of your Squid software, enter:
sudo systemctl status squid
See if the service is running or not.
To start the service, enter:
sudo systemctl start squid
Then set the Squid service to launch when the system starts by entering:
sudo systemctl enable squid
You can rerun the current status command to verify the service is running and to stop the service, use the command:
sudo systemctl stop squid
To prevent Squid from launching at startup, enter:
sudo systemctl disable squid
And that’s a brief guide on how to install Squid on linux ubuntu server 18.04 and a good and correct guide to configuring Squid. Make sure you use this Squid service on your server to get a secure and fast network. Hopefully this article was useful for you and good luck. 🙂