Squid Proxy Setup on Debian 11: Private Connections Guide
In this article
Setting up Squid on Debian 11 gives you a private proxy that routes all traffic through a single machine, shielding clients from direct exposure to the internet and allowing you to enforce access policies, log usage, and cache frequently requested content.
What You’ll Need
- Debian 11 (stable) installed on a server or VM.
- Root or sudo privileges on the machine.
- Active internet connection and a static IP or domain pointing to the server.
- Basic knowledge of the terminal and package management.
- Optional: a separate network interface or VLAN if you want to isolate the proxy network.
Step‑by‑Step
- Update the system and install Squid:
- Run
sudo apt update && sudo apt upgrade -yto bring the package lists and installed packages up to date. - Install Squid with
sudo apt install squid -y. The package pulls in all necessary dependencies.
- Run
- Verify the service status:
- Check that Squid is running:
systemctl status squid. You should see an active (running) state. - If it isn’t active, start it with
sudo systemctl start squidand enable autostart on boot usingsudo systemctl enable squid.
- Check that Squid is running:
- Backup the default configuration file:
- Execute
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.backupto preserve the original settings.
- Execute
- Configure the listening port and network access:
- Edit the config file:
sudo nano /etc/squid/squid.conf. - Locate the line that begins with
#http_port. Replace it withhttp_port 3128(or another unused port if 3128 conflicts). - Define ACLs to allow only trusted IP ranges. For example, add:
acl localnet src 192.168.1.0/24 http_access allow localnet http_access deny all
This permits devices on the 192.168.1.0/24 subnet to use the proxy while blocking all others.
- Edit the config file:
- Set up authentication (optional but recommended for private use):
- Create a password file:
sudo touch /etc/squid/passwdand set ownership:sudo chown proxy:proxy /etc/squid/passwd. - Generate a hashed password:
sudo htpasswd -c /etc/squid/passwd username. Replaceusernamewith the desired account name and follow prompts to set a password. - Add the authentication directive to the config:
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd acl authenticated proxy_auth REQUIRED http_access allow authenticated
Ensure these lines come before the finalhttp_access deny all.
- Create a password file:
- Restart Squid to apply changes:
sudo systemctl restart squid.- Confirm the new port and ACLs by running
sudo netstat -tulnp | grep 3128and reviewing thehttp_accesslog entries in/var/log/squid/access.log.
- Configure client machines to use the proxy:
- In web browsers, set the proxy host to the server’s IP and port 3128, or use the
http_proxyenvironment variable for command‑line tools:export http_proxy=http://.:3128 - If authentication is enabled, include the credentials:
http://username:password@or supply them when prompted.:3128
- In web browsers, set the proxy host to the server’s IP and port 3128, or use the
- Optional: Enable caching to reduce bandwidth usage:
- In the config file, locate
#cache_dirand uncomment or add a line such ascache_dir ufs /var/spool/squid 100 16 256, where 100 is the cache size in MB. - Restart Squid again to apply caching settings.
- In the config file, locate
- Set up firewall rules to restrict direct access to the proxy port:
- Using UFW, allow only trusted IPs:
sudo ufw allow from 192.168.1.0/24 to any port 3128. - Enable UFW with
sudo ufw enableand verify rules withsudo ufw status numbered.
- Using UFW, allow only trusted IPs:
- Monitor performance and logs:
- View real‑time traffic:
sudo tail -f /var/log/squid/access.log. - Check cache hit/miss statistics with
squidclient -h localhost:3128 mgr:infoafter installingsquidclientviasudo apt install squidclient.
- View real‑time traffic:
Common Mistakes
- Leaving the default
http_access deny allbefore custom ACLs, which blocks all traffic. - Using the same port for another service, causing Squid to fail to bind.
- Forgetting to restart Squid after editing the configuration.
- Misconfiguring authentication paths, leading to 407 errors on clients.
- Not setting proper file permissions on the password file, which can expose credentials.
Tips
- Use
squid -k parseto test configuration syntax before restarting. - Enable
visible_hostnamein the config to make logs easier to read. - For high‑traffic environments, consider moving the cache directory to a dedicated SSD.
- Regularly rotate logs with logrotate to avoid disk exhaustion.
- Use
htpasswdto add or remove users without editing the file manually.
Troubleshooting
- Squid does not start: check
/var/log/squid/cache.logfor errors and runsquid -k parseto find syntax problems. - Clients receive 403 or 407 errors: verify ACL ordering and authentication configuration.
- Proxy appears unreachable from clients: ensure the firewall allows inbound traffic on the chosen port and that the server’s IP is correct.
- Cache is not used: confirm
cache_diris set and that the cache directory has sufficient permissions and space. - Performance drops: monitor
cache.logfor cache misses and consider increasing cache size or tuningmaximum_object_size_in_memory.
Frequently Asked Questions
How do I add more users to the proxy?
Run sudo htpasswd /etc/squid/passwd newuser and enter a password when prompted. No restart is needed for the change to take effect.
Can Squid proxy HTTPS traffic?
Squid can forward HTTPS requests but does not decrypt them. For full HTTPS inspection, a separate SSL bump configuration is required, which is more complex and beyond the scope of this guide.
Is it safe to expose Squid to the public internet?
Only if you enforce strict ACLs, authentication, and firewall rules. Without these, anyone could use the proxy to anonymize traffic.
How do I change the listening port?
Edit /etc/squid/squid.conf, replace the http_port line, and restart Squid. Ensure no other service uses the new port.
What does the cache_dir setting do?
It defines where Squid stores cached objects on disk, improving bandwidth usage and load times for repeated requests.
Can I use Squid with a VPN?
Yes. Configure the VPN to route traffic to the Squid server’s IP and port, and use the same ACLs to control access.