What is Squid?
Squid is a highly acclaimed, open-source caching proxy for the web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching frequently requested web pages on the local server. Furthermore, it is heavily used by network administrators as a forwarding proxy to filter traffic, block malicious websites, and control employee internet access.
Step 1: Install the Squid Package
Squid is extremely stable and available directly from the standard Ubuntu package repositories. Open your terminal and update your package lists, then install Squid:
sudo apt update
sudo apt install squid -y
Once installed, the Squid service will automatically start and configure itself to listen on the default port, 3128.
Step 2: Understand the Configuration File
The behavior of the proxy server is controlled by a single configuration file located at /etc/squid/squid.conf. Because this file contains thousands of lines of documentation, it’s highly recommended to back it up before making edits:
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.backup
Open the file in a text editor to begin configuring your Access Control Lists (ACLs):
sudo nano /etc/squid/squid.conf
Step 3: Create an Access Control List (ACL)
By default, Squid denies all incoming requests from IP addresses outside of localhost to prevent the server from becoming an open proxy abused by attackers. To allow computers on your local network to use the proxy, you must define an ACL.
Scroll down to the section defining ACLs (search for acl localnet). Add a rule defining your internal subnet. For example, if your office network is 192.168.1.0/24, add:
acl office_network src 192.168.1.0/24
Step 4: Grant Access to the ACL
Defining the ACL simply creates a variable; you must now explicitly allow that variable to access the proxy. Scroll down to the http_access section of the file.
Add the following line above the http_access deny all line (order is extremely important; rules are read top-to-bottom):
http_access allow office_network
Step 5: Restart the Service and Test
Save and close the squid.conf file. To apply the new rules, you must restart the Squid service:
sudo systemctl restart squid
To verify that the proxy is working, go to a client computer on the 192.168.1.0/24 network, open its web browser settings, and configure it to use a manual proxy. Enter the IP address of your Ubuntu server and port 3128. If configured correctly, the browser will successfully load websites, and the traffic will be logged in the Squid access log located at /var/log/squid/access.log.