Website Vidya
Linux & ServersStep-by-Step Guide

How to Install and Configure Squid Proxy on Ubuntu 24.04

Learn how to install and configure squid proxy on ubuntu 24.04 with Access Control Lists (ACLs), HTTP basic authentication, and UFW firewall rules.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Install and Configure Squid Proxy on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

5 min read

Learn how to install and configure squid proxy on ubuntu 24.04 with Access Control Lists (ACLs), HTTP basic authentication, and UFW firewall rules.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Installing Squid on Ubuntu 24.04
  • Step 2: Understanding and Backing Up squid.conf
Grounded in full engineering runbookWebsiteVidya AI Engine

In corporate networks, educational institutions, and cloud infrastructures, controlling outgoing internet traffic and caching frequently requested web assets is vital for security and bandwidth efficiency.

A forward caching proxy acts as an intermediary gateway between client workstations and the public internet, inspecting web requests, filtering unauthorized destinations, and speeding up downloads.

Squid is the world's most battle-tested, feature-rich open-source caching proxy daemon, supporting HTTP, HTTPS, and FTP protocols with granular access controls.

Deploying Squid on Ubuntu 24.04 LTS provides network administrators with total control over outbound traffic patterns and client connection policies.

Advertisement

In this guide, we walk through how to install and configure squid proxy on ubuntu 24.04, define IP-based Access Control Lists (ACLs), enforce password authentication, and configure client devices.

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

Advertisement
  • A server running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • A non-root user account with sudo administrative privileges.
  • UFW firewall installed.
  • A client computer or terminal with curl to test proxy connectivity.

Step 1: Installing Squid on Ubuntu 24.04

Squid is available directly from the standard Ubuntu package repositories.

First, update your local package list, then install the squid package along with apache2-utils (which provides the htpasswd utility for user authentication):

Verify that the Squid systemd service is active and running:

# Refresh package index and install Squid:
sudo apt update
sudo apt install -y squid apache2-utils

# Check Squid service operational status:
sudo systemctl status squid
# Expected output confirms:
# Active: active (running)

# Enable Squid to start automatically on system boot:
sudo systemctl enable squid

Step 2: Understanding and Backing Up squid.conf

The main configuration file for Squid is located at /etc/squid/squid.conf.

Advertisement

This file is exceptionally large (often exceeding 8,000 lines) because it contains extensive inline documentation describing hundreds of parameters.

Create a safe backup of the original configuration file before making changes:

Identify the default listening port directive (http_port 3128):

# Create a timestamped backup of the original configuration:
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.bak

# View active uncommented configuration directives:
grep -v '^#' /etc/squid/squid.conf | grep -v '^$'
# Snippet:
# acl localnet src 0.0.0.1-0.255.255.255
# acl localnet src 10.0.0.0/8
# acl localnet src 172.16.0.0/12
# acl localnet src 192.168.0.0/16
# http_port 3128

Step 3: Configuring IP-Based Access Control Lists (ACLs)

By default, Squid denies all external traffic with the http_access deny all fallback directive.

To allow specific internal subnets or trusted public IP addresses to route through the proxy, define custom Access Control Lists (ACLs).

Open /etc/squid/squid.conf and add your client subnet rule directly above the http_access deny all statement:

Save the following configuration snippet:

# Open squid.conf in text editor:
sudo nano /etc/squid/squid.conf

# Locate the ACL section and define your allowed IP network:
# acl allowed_clients src 192.168.1.0/24 203.0.113.45

# Locate the http_access section and insert the allow rule above deny all:
# http_access allow allowed_clients
# http_access deny all

# Test configuration syntax for errors:
sudo squid -k check

# Restart Squid to reload active access rules:
sudo systemctl restart squid

Step 4: Configuring Password-Based HTTP Basic Authentication

If your proxy server is hosted in a public cloud with dynamic client IP addresses, IP-based filtering is impractical.

Instead, configure HTTP Basic Authentication using Squid's built-in basic_ncsa_auth helper program.

Create a password file named /etc/squid/passwords using htpasswd:

Add the authenticated user credentials and configure Squid to mandate login:

# Create password file and add user 'proxyuser':
sudo htpasswd -c /etc/squid/passwords proxyuser
# Prompt: New password: [Enter password]

# Ensure Squid can read the password file:
sudo chown proxy:proxy /etc/squid/passwords
sudo chmod 640 /etc/squid/passwords

# Add authentication directives to /etc/squid/squid.conf:
# auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
# auth_param basic realm Squid Proxy Server
# acl authenticated_users proxy_auth REQUIRED
# http_access allow authenticated_users
# http_access deny all

# Reload Squid configuration:
sudo systemctl restart squid

Step 5: Opening Squid Port in UFW Firewall

Squid listens on TCP port 3128 by default.

If your proxy uses IP authentication, open port 3128 strictly to your authorized subnet:

If using password authentication, open port 3128 in UFW:

# If restricting to a specific client IP:
sudo ufw allow from 203.0.113.45 to any port 3128 proto tcp comment 'Squid Proxy Client'

# Or open port 3128 generally (when protected by password auth):
sudo ufw allow 3128/tcp comment 'Squid Proxy Service'

# Verify active UFW rules:
sudo ufw status

Step 6: Testing Proxy Connections from Client Devices

Verify that client web requests successfully route through Squid by executing a test query using curl from a remote client computer:

Run the curl command with the -x (proxy) flag:

Verify the request in Squid's real-time access log on the server:

# On CLIENT machine (testing without auth):
curl -x http://YOUR_PROXY_IP:3128 -I https://ubuntu.com

# On CLIENT machine (testing with password auth):
curl -x http://proxyuser:PASSWORD@YOUR_PROXY_IP:3128 -I https://ubuntu.com
# Expected HTTP response:
# HTTP/1.1 200 Connection established

# On SQUID SERVER (monitor live traffic logs):
sudo tail -f /var/log/squid/access.log
# Log output confirms:
# 1718000000.123  150 203.0.113.45 TCP_TUNNEL/200 5234 CONNECT ubuntu.com:443 proxyuser HIER_DIRECT/185.125.190.29 -

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

HTTP 403 Forbidden: Access Denied

Cause: The client's IP is not defined in the allowed ACL, or the rule is placed after http_access deny all.

Resolution: Ensure your http_access allow rule appears before any deny statements in /etc/squid/squid.conf.

sudo squid -k check && sudo tail -n 50 /var/log/squid/cache.log

HTTP 407 Proxy Authentication Required

Cause: Client did not provide proxy credentials, or credentials in /etc/squid/passwords do not match.

Resolution: Provide credentials via curl -x http://user:pass@proxy-ip:3128 or verify permissions on /etc/squid/passwords.

sudo ls -la /etc/squid/passwords

Squid fails to start after configuration modifications

Cause: Syntax error in /etc/squid/squid.conf.

Resolution: Run sudo squid -k parse to locate the exact line number containing the syntax violation.

sudo squid -k parse

Security Best Practices and Hardening

Never leave Squid running as an open proxy accessible to the entire internet without IP restrictions or authentication; open proxies are rapidly hijacked for botnets and abuse.

Consider changing the default listening port from 3128 to an unassigned high port to reduce automated script scans.

Monitor cache and access logs regularly in /var/log/squid/access.log to detect unauthorized traffic spikes.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
A forward proxy (like Squid) sits in front of client devices to control outbound internet access, filter URLs, and cache external content. A reverse proxy (like Nginx or Caddy) sits in front of backend web servers to route incoming client traffic, terminate SSL, and load-balance requests.
By default, Squid acts as a blind TCP tunnel (using the HTTP CONNECT method) for HTTPS traffic without decrypting contents. To inspect or filter HTTPS URLs, administrators enable SSL Bumping (SslBump), which requires generating and distributing a custom root Certificate Authority (CA) to client browsers.
Stop the Squid daemon with sudo systemctl stop squid, delete the cache directory contents with sudo rm -rf /var/spool/squid/*, rebuild the swap directories with sudo squid -z, and restart the service with sudo systemctl start squid.
Squid's default TCP listening port is 3128. You can change this to any port by modifying the http_port directive in /etc/squid/squid.conf.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout