The Wild

Squid Proxy Setup on Debian 11: Private Connections Guide

· 4 min read · Ocean Life

In this article
  1. What You’ll Need
  2. Step‑by‑Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Update the system and install Squid:
    • Run sudo apt update && sudo apt upgrade -y to 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.
  2. 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 squid and enable autostart on boot using sudo systemctl enable squid.
  3. Backup the default configuration file:
    • Execute sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.backup to preserve the original settings.
  4. 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 with http_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.
  5. Set up authentication (optional but recommended for private use):
    • Create a password file: sudo touch /etc/squid/passwd and set ownership: sudo chown proxy:proxy /etc/squid/passwd.
    • Generate a hashed password: sudo htpasswd -c /etc/squid/passwd username. Replace username with 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 final http_access deny all.
  6. Restart Squid to apply changes:
    • sudo systemctl restart squid.
    • Confirm the new port and ACLs by running sudo netstat -tulnp | grep 3128 and reviewing the http_access log entries in /var/log/squid/access.log.
  7. 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_proxy environment variable for command‑line tools: export http_proxy=http://:3128.
    • If authentication is enabled, include the credentials: http://username:password@:3128 or supply them when prompted.
  8. Optional: Enable caching to reduce bandwidth usage:
    • In the config file, locate #cache_dir and uncomment or add a line such as cache_dir ufs /var/spool/squid 100 16 256, where 100 is the cache size in MB.
    • Restart Squid again to apply caching settings.
  9. 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 enable and verify rules with sudo ufw status numbered.
  10. 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:info after installing squidclient via sudo apt install squidclient.

Common Mistakes

  • Leaving the default http_access deny all before 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 parse to test configuration syntax before restarting.
  • Enable visible_hostname in 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 htpasswd to add or remove users without editing the file manually.

Troubleshooting

  • Squid does not start: check /var/log/squid/cache.log for errors and run squid -k parse to 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_dir is set and that the cache directory has sufficient permissions and space.
  • Performance drops: monitor cache.log for cache misses and consider increasing cache size or tuning maximum_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.