Proxies with Squid


How to install Squid Proxy on Ubuntu?

The squid package is included in the default Ubuntu 20.04 LTS repository. To install it, run the following commands as a sudo user:

sudo apt update
sudo apt install squid

After squid has been installed you can run the following to see if it's running or not:

sudo systemctl status squid

The output should look like this:

● squid.service - Squid Web Proxy Server
     Loaded: loaded (/lib/systemd/system/squid.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-08-06 14:02:43 UTC; 34s ago

(If it doesn't it could mean you are running something already on the default squid config port 3128)

Configuring Squid Proxy

Squid Proxy's configuration can be found in the following location:

cd /etc/squid/squid.conf

To edit the configuration of Squid Proxy, you can use nano:

sudo nano /etc/squid/squid.conf

If you want to change the default squid proxy port change the following line:

http_port PORT

If you want to allow any IP to the Squid Proxy then you do the following in the config file:

http_access allow all

If you want to log who is accessing your Squid Proxy then you need the following in the config file:

logformat squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt
access_log /var/log/squid/access.log squid

After making changes to the squid config, you would want those changes to be loaded by Squid so you have to reload or restart the service. Reloading is much faster than restarting especially when you have long config files

sudo systemctl restart squid
sudo systemctl reload squid

Proxy Config Examples:

Forward Proxy with Squid
forwarded_for delete
via off
no_cache deny all
cache deny all

request_header_access Cache-Control deny all
request_header_access Via deny all
request_header_access X-Forwarded-For deny all

client_persistent_connections on
server_persistent_connections on

http_access allow all
http_port 2222

cache_peer proxy1.packetsent.dev parent 1111 0 no-query default login=PASSTHRU name=proxy1

never_direct allow all
Rotating Forward Proxy with Squid
forwarded_for delete
via off
no_cache deny all
cache deny all

request_header_access Cache-Control deny all
request_header_access Via deny all
request_header_access X-Forwarded-For deny all

client_persistent_connections off
server_persistent_connections off

http_access allow all
http_port 2222

cache_peer proxy1.packetsent.dev parent 1111 0 round-robin no-query default login=PASSTHRU name=proxy1
cache_peer proxy2.packetsent.dev parent 1111 0 round-robin no-query default login=PASSTHRU name=proxy2
cache_peer proxy3.packetsent.dev parent 1111 0 round-robin no-query default login=PASSTHRU name=proxy3

never_direct allow all
Multiple Static Proxies with Squid
forwarded_for delete
via off
no_cache deny all
cache deny all

request_header_access Cache-Control deny all
request_header_access Via deny all
request_header_access X-Forwarded-For deny all

client_persistent_connections off
server_persistent_connections off

http_access allow all

http_port 1000 name=1000
acl proxy1000 myportname 1000 src 0.0.0.0/0
http_access allow proxy1000
tcp_outgoing_address OUTGOING_IP proxy1000

http_port 1001 name=1001
acl proxy1001 myportname 1001 src 0.0.0.0/0
http_access allow proxy1001
tcp_outgoing_address OUTGOING_IP1 proxy1001

http_port 1002 name=1002
acl proxy1002 myportname 1002 src 0.0.0.0/0
http_access allow proxy1002
tcp_outgoing_address OUTGOING_IP2 proxy1002

never_direct allow all

Last updated: February 14, 2022