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.

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.
- Prerequisites and Supported Releases
- Step 1: Installing Squid on Ubuntu 24.04
- Step 2: Understanding and Backing Up squid.conf
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.
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.
Complete step-by-step administrator tutorial on deploying and securing a Squid caching forward proxy on Ubuntu 24.04 LTS (Noble Numbat). Explains default port 3128 configuration, creating custom Access Control Lists (ACLs) to restrict client IP ranges, configuring password-based HTTP authentication with apache2-utils, and testing proxy connections with curl.
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:
- A server running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- A non-root user account with
sudoadministrative privileges. - UFW firewall installed.
- A client computer or terminal with
curlto 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.
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.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Set Up a Firewall with UFW on Ubuntu 24.04 — Configure UFW firewall rules to secure Squid proxy port 3128.
- How to Set Up WireGuard VPN on Ubuntu 24.04 — Compare caching proxies with encrypted full-tunnel VPN architectures.
- Initial Server Setup on Ubuntu 24.04 LTS — Foundational Linux server security hardening guide.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
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.3128. You can change this to any port by modifying the http_port directive in /etc/squid/squid.conf.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
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.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!