How to set up a Linux Squid Proxy Server with multiple IPs
The Linux Squid Proxy software used to be extremely popular when the internet wasn’t using HTTPS and SSL certificates. Now people prefer to use a SOCKS proxy server because they offer more configuration options and are generally seen as more secure with SSL encryption. Here we are going to set up a Squid Proxy Server and configure it for use with multiple IPs. The commands in this article will work on all RHEL-based servers like CentOS, RockyLinux and Almaliux.
Required Hardware
To set up your Squid proxy on Linux you will need at minimum one of our NVMe VPS with 5GB of space, 1GB RAM and some swap. You should have unlimited bandwidth and a subnet of IPs.
Update & Install/Set up Squid Proxy Server
Squid Proxy Server is contained in the epel repository so when you issue the command below. This will ;
- 1. Update your server
- 2. Install the epel repository
- 3. Install Nano
- 4. Install Squid Proxy server
- 5. Stop & Disable FirewallD
- Provide the status of Squid
yum update -y && yum install epel-release nano -y && yum update -y && yum install squid -y && systemctl start squid && systemctl enable squid && systemctl stop firewalld && systemctl disable firewalld && systemctl status squid
Configure Squid Proxy Server
Squid mostly comes ready to use but you’re going to want to ensure only users you want to connect to the proxy can connect. In this guide, we are going to secure Squid by only allowing access from certain IPs.
/etc/squid/squid.conf
First, more the original squid.conf file out of the way.
mv /etc/squid/squid.conf /etc/squid/old-squid.conf
Now create a new squid.conf and paste the below code to the file. We have added notations to the file for the sections you need to change.
nano /ect/squid/squid.conf
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src ALLOW-CONEECTIONS-FROM/32 # IP in /32 format
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
acl myip_51_xxx_xx_15 myip 51.xx.xx.15
tcp_outgoing_address 51.xx.xx.15 myip_51_xx_xx_15
#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports
# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost
# And finally deny all other access to this proxy
http_access deny all
# Squid normally listens to port 3128
http_port 3128
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid
#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
Restrict Access
acl localnet src ALLOW-CONNECTIONS-FROM/32 # IP in /32 format
Replace this section with the IP you want to allow to connect to your proxy. To allow more IPs just copy the section. It will look like this once edited.
acl localnet src 192.168.0.1/32 # Notation
Configure Additional IPs in Squid Proxy
To configure any additional IPs you have to add a section for each IP. In the squid.conf file you will see the following section;
acl myip_51_xxx_xx_15 myip 51.xx.xx.15
tcp_outgoing_address 51.xx.xx.15 myip_51_xx_xx_15
Edit this section and fill out your IP address. The section will look like this once complete;
acl myip_51_199_10_15 myip 51.199.10.15
tcp_outgoing_address 51.199.10.15 myip_51_199_10_15
To add more IPs just copy the section and edit it with your other IP details. Here I added two more IPs to the squid.conf file.
acl myip_51_199_10_15 myip 51.199.10.15
tcp_outgoing_address 51.199.10.15 myip_51_199_10_15
acl myip_51_199_10_16 myip 51.199.10.16
tcp_outgoing_address 51.199.10.16 myip_51_199_10_16
acl myip_51_199_10_17 myip 51.199.10.17
tcp_outgoing_address 51.199.10.17 myip_51_199_10_17
Save & Restart Squid
That’s the configuration of Squid Server complete. Save the squid.conf file and restart squid. You can then start using your new proxy with additional IPs.
systemctl restart squid
We have a range of IPs located in different countries around the world. These are ideal for Squid. You can order additional IPs from your client area (Services > View Addons)