Squid proxy and cache server guide

Last time at work our system administrator had an issue with Squid multiple IPs configuration. The IP binding wasn’t working properly for him. Clients could connect to multiple IPs of the Squid server, but still all outgoing connections were made from the main IP of the server. The intention was to make Squid multiple IPs configuration that sets the IP for outgoing connections the same as the IP used to connect with the Squid server.

I have investigated the issue and, thankfully, the solution for this Squid multiple IPs setup is quick and easy. It can be simply configured by creating an ACL matching the IP used to connect with the Squid proxy, and then by using this ACL together with tcp_outgoing_address setting.

Further in the article you will find an example and working code that solves Squid multiple IPs problem.

Squid multiple IPs solution

Open up your Squid configuration file. In Linux-based operating systems like Ubuntu or CentOS the configuration file lies in /etc/squid/squid.conf directory.

In the configuration file you need to add the code above. You have to replace IP and ACL_NAME, of course.

acl ACL_NAME myip IP
tcp_outgoing_address IP ACL_NAME

ACL_NAME is a name of your ACL. You can pickup any name you want, keeping in mind that you cannot use spaces and special characters.
IP is the IP you want to bind in your Squid multiple IPs configuration.

Example code can look as following:

acl myip_173_194_112_40 myip 173.194.112.40
tcp_outgoing_address 173.194.112.40 myip_173_194_112_40

You can notice how I named my ACL. I use this format as it’s clear what it is, I am recommending to the same if you don’t have other ideas for naming your ACLs.

To add more IPs to your Squid proxy, simply repeat the code above with more IPs. Example:

acl myip_173_194_112_40 myip 173.194.112.40
tcp_outgoing_address 173.194.112.40 myip_173_194_112_40

acl myip_173_194_112_32 myip 173.194.112.32
tcp_outgoing_address 173.194.112.32 myip_173_194_112_32

acl myip_173_194_112_14 myip 173.194.112.14
tcp_outgoing_address 173.194.112.14 myip_173_194_112_14

That’s all. Those two lines are enough to properly bind IPs in your Squid multiple IPs configuration.

Learn more about Squid