How to Set Up & Install Squid Proxy Server on Ubuntu 18.04

Introduction

Squid is a popular open source web proxy server that can be used to efficiently cache and proxy web content. It is a great tool for improving web performance and security. In this tutorial, we will show you how to set up and install Squid Proxy Server on Ubuntu 18.04. We will cover the installation of Squid from the official Ubuntu repositories, as well as from the Squid official website. We will also show you how to configure Squid to allow access from specific IP addresses and how to set up basic authentication. Finally, we will provide some useful tips that you can use to further harden your Squid proxy server.

How to Set Up & Install Squid Proxy Server on Ubuntu 18.04

1. Update the system

Before you start, make sure your system is up to date. You can do this by running the following command:

sudo apt update && sudo apt upgrade -y

2. Install Squid

Once your system is up to date, you can install Squid by running the following command:

sudo apt install squid -y

3. Configure Squid

Once Squid is installed, you need to configure it. To do this, open the Squid configuration file in a text editor:

sudo nano /etc/squid/squid.conf

4. Allow Access to Squid

By default, Squid will only allow access from the localhost. To allow access from other computers, you need to add the following line to the configuration file:

http_access allow all

5. Restart Squid

Once you have made the necessary changes to the configuration file, you need to restart Squid for the changes to take effect. You can do this by running the following command:

sudo systemctl restart squid

6. Test Squid

Once Squid is up and running, you can test it by running the following command:

curl -x http://localhost:3128 http://example.com

If everything is working correctly, you should see the HTML source code of the example.com website.
[ad_1]

Introduction

Squid is a Linux-based proxy application. The Squid proxy server is used for filtering traffic, security, and DNS lookups.

Also, Squid can speed up a web server by caching resources. The Squid Proxy allows a server to cache frequently visited web pages. When the user requests a web page or file, the request goes directly to the proxy server — an intermediary device between the user’s device and the internet. The proxy server pulls up the resources and relays them to the user.

This guide will walk you through how to set up and install Squid Proxy server on Ubuntu.

set up and install squid proxy on ubuntu

Prerequisites

Installing Squid Proxy on Ubuntu

Step 1: Refresh the Software Repositories

Ensure you’re working with the latest software version available.

Launch a terminal window, and enter the following:

sudo apt-get update

Step 2: Install Squid Package on Ubuntu

To install Squid, run the command:

sudo apt-get install squid

The system should prompt for confirmation – enter Y and allow the process to complete itself.

Configuring 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 the http_port option. Typically, this is set to listen on Port 3218. This port usually carries TCP traffic. If your system is configured for traffic on another port, change it here.

You may also set the proxy mode to transparent if you’d like to prevent Squid from modifying your requests and responses.

Change it as follows:

http_port 1234 transparent

3. Navigate to the http_access deny all option. This is currently configured to block all HTTP traffic. This means no web traffic is allowed.

Change this to the following:

http_access allow all

4. Navigate to the visible_hostname option. Add any name you’d like to this entry. This is how the server will appear to anyone trying to connect. Save the changes and exit.

5. Restart the Squid service by entering:

sudo systemctl restart squid

Configure Squid Client

All this configuration has been done to set up your Squid proxy server. Now, switch to your client machine and open your web browser.

If you’re using Firefox, you can find the proxy settings under:

Menu > Options > Network Settings > Settings

Tick the radio button for Manual proxy configuration.

If you’ve entered a hostname in Step 4, you should be able to enter that name plus the port you have designated. Otherwise, use the IP address for the system hosting your Squid proxy.

To test it, you can visit https://whatismyipaddress.com/ip-lookup – if your proxy is working, your IP address should display as the proxy server’s IP address.

Add Squid ACL

Note: After each of these steps, you should 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 system at this IP address to connect. It is recommended that you comment the line to identify the rule:

acl localnet src 192.168.0.15 # test computer

Anything after the # sign is ignored by Squid.

You can specify a range of IP addresses as follows:

acl localnet src 192.168.0.15/30

Open Ports

To open a specific port, add the following:

acl Safe_ports port 123 # Custom port

Configure Proxy Authentication

This forces users 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 user proxy:

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 prompt you to enter and confirm a password for newuser.

2. Edit the /etc/squid/squid.conf file, and add the following command lines:

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 websites to be blocked, starting with a dot:

.facebook.com

.twitter.com

Note: The dot specifies to block all subsites of the main site.

3. Open the /etc/squid/squid.conf file again:

sudo nano /etc/squid/squid.conf

4. Add the following lines just above your ACL list:

acl blocked_websites dstdomain “/etc/squid/blocked.acl”
http_access deny blocked_websites

Commands When Working with the Squid Service

To check the status of your Squid software, enter:

sudo systemctl status squid

This will tell you whether 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 re-run the status command now to verify the service is up and running.

To stop the service, use the command:

sudo systemctl stop squid

To prevent Squid from launching at startup, enter:

sudo systemctl disable squid

Conclusion

If you’ve followed along closely, you should now have a basic understanding of how Squid works, and how to install and configure Squid Proxy on Ubuntu.

Proxy servers are a valuable tool for securing network traffic, preventing attacks and restricting access.

Check out our article on how to set up your Ubuntu system to work with a proxy server to configure your Ubuntu machine to use a proxy.

Interested in setting up this application on a different OS? You may want to check out how to install Squid on CentOS 7.



[ad_2]

How to Set Up & Install Squid Proxy Server on Ubuntu 18.04

Squid is a popular open source web proxy server that can be used to cache web content and reduce the load on your web server. It is a widely used proxy server that supports HTTP, HTTPS, and FTP protocols. In this tutorial, we will show you how to set up and install Squid proxy server on Ubuntu 18.04.

Prerequisites

  • A server running Ubuntu 18.04.
  • A root user access or normal user with sudo privileges.

Step 1 – Install Squid

First, you will need to install Squid on your server. You can do this by running the following command:

sudo apt-get update
sudo apt-get install squid

Once the installation is complete, you can start the Squid service by running the following command:

sudo systemctl start squid

You can also enable the Squid service to start automatically on boot by running the following command:

sudo systemctl enable squid

Step 2 – Configure Squid

Once the Squid service is running, you can configure it by editing the Squid configuration file. The configuration file is located at /etc/squid/squid.conf.

You can edit the configuration file using your favorite text editor. For example, you can use nano:

sudo nano /etc/squid/squid.conf

Once you have opened the configuration file, you can add the following lines to the end of the file:

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

http_access allow localnet
http_access allow localhost
http_access deny all

Save and close the file, then restart the Squid service for the changes to take effect:

sudo systemctl restart squid

Step 3 – Test Squid

At this point, Squid should be up and running. You can test it by running the following command:

curl -x http://localhost:3128 http://example.com

If everything is working correctly, you should see the HTML source code of the example.com website.

Conclusion

In this tutorial, we have shown you how to set up and install Squid proxy server on Ubuntu 18.04. You should now have a basic understanding of how to configure and use Squid proxy server.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00