DevOps Tools

Guide to Setting Up and Configuring Squid Proxy Server

In this guide, we’ll walk through the process of setting up and configuring a Squid proxy server on an Ubuntu machine. This involves installing necessary packages, configuring the Squid service, and verifying its operation. We’ll also explain each command used throughout the setup.

Step 1: Update and Upgrade the System

Before installing new software, it’s good practice to update the package list and upgrade the existing packages to ensure we have the latest versions and security patches.

sudo apt-get update
sudo apt-get upgrade
  • sudo apt-get update: This command fetches the latest package lists from the repositories, ensuring you get the latest versions of packages and dependencies.
  • sudo apt-get upgrade: This command upgrades all the installed packages to their latest versions based on the updated package lists.

Step 2: Install Squid and Network Tools

Next, we’ll install Squid, a popular caching and forwarding HTTP proxy. Additionally, we’ll install net-tools for network troubleshooting.

sudo apt-get install squid3
sudo apt-get install net-tools
  • sudo apt-get install squid3: This installs Squid version 3 on your system.
  • sudo apt-get install net-tools: This installs a collection of programs that form the base set of the NET-3 networking distribution for Linux. This includes tools like ifconfig and netstat.

Step 3: Manage the Squid Service

After installation, we need to start, enable, and check the status of the Squid service to ensure it runs properly.

sudo systemctl start squid
sudo systemctl status squid
sudo systemctl enable squid
sudo systemctl restart squid
  • sudo systemctl start squid: This starts the Squid service.
  • sudo systemctl status squid: This checks the status of the Squid service, showing whether it’s active and running.
  • sudo systemctl enable squid: This enables Squid to start automatically at boot.
  • sudo systemctl restart squid: This restarts the Squid service to apply any configuration changes.

Step 4: Verify Squid’s Network Listening

To ensure Squid is listening on the correct port, we can use netstat and ps.

sudo netstat -tulnp | grep 3128
ps -ef | grep squid
  • sudo netstat -tulnp | grep 3128: This checks if Squid is listening on port 3128, displaying the process details.
  • ps -ef | grep squid: This shows all processes related to Squid, ensuring it is running correctly.

Step 5: Backup and Modify Squid Configuration

Before making changes, we back up the original configuration file. Then, we edit the configuration to set the desired proxy settings.

sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
sudo vim /etc/squid/squid.conf
  • sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.bak: This creates a backup of the original Squid configuration file.
  • sudo vim /etc/squid/squid.conf: This opens the Squid configuration file in the vim text editor for editing.

Inside the configuration file, make the following changes:

#http_port 3128
#http_access allow localhost manager
http_access allow all
#http_access deny manager
acl localnet src
  • http_port This changes the proxy to listen on the specified IP address and port.
  • http_access allow all: This allows all connections to use the proxy. (Note: This setting is for demonstration purposes and might not be suitable for all environments due to security concerns).
  • acl localnet src This defines an access control list (ACL) named localnet that matches traffic from the specified IP range.

Step 6: Restart and Check Squid Service

After modifying the configuration, restart the Squid service and check its status.

sudo systemctl restart squid
sudo systemctl status squid
  • sudo systemctl restart squid: This restarts Squid to apply the new configuration.
  • sudo systemctl status squid: This verifies that Squid is running correctly with the new settings.

Step 7: Verify Squid’s Network Listening Again

Finally, we recheck if Squid is listening on the correct port and IP.

sudo netstat -tulnp | grep squid
  • sudo netstat -tulnp | grep squid: This confirms that Squid is listening on the specified IP address and port.

Additional Step: Setting Up a VirtualBox VM

To test the proxy configuration, you can set up a VirtualBox VM with Ubuntu and manually configure the proxy settings to use

Ali Imran
Over the past 20+ years, I have been working as a software engineer, architect, and programmer, creating, designing, and programming various applications. My main focus has always been to achieve business goals and transform business ideas into digital reality. I have successfully solved numerous business problems and increased productivity for small businesses as well as enterprise corporations through the solutions that I created. My strong technical background and ability to work effectively in team environments make me a valuable asset to any organization.

Leave a Reply