Squid Proxy – Random Outgoing IP Address on Each Request

PROXYsquid

I have a server with 10 IPv4 addresses and I want Squid to randomly pick one of those IPv4 addresses for each request.

My current configuration for this is like:

acl random1 random 1/10
acl random2 random 1/10
acl random3 random 1/10
acl random4 random 1/10
acl random5 random 1/10
acl random6 random 1/10
acl random7 random 1/10
acl random8 random 1/10
acl random9 random 1/10
acl random10 random 1/10

tcp_outgoing_address 10.0.0.2 random1
tcp_outgoing_address 10.0.0.3 random2
tcp_outgoing_address 10.0.0.4 random3
tcp_outgoing_address 10.0.0.5 random4
tcp_outgoing_address 10.0.0.6 random5
tcp_outgoing_address 10.0.0.7 random6
tcp_outgoing_address 10.0.0.8 random7
tcp_outgoing_address 10.0.0.9 random8
tcp_outgoing_address 10.0.0.10 random9
tcp_outgoing_address 10.0.0.11 random10

But this keeps repeating the main IPv4 address of the server like 96% of the requests.

Is there's anyway to avoid this?

Best Answer

The way you chose the random values, the probability to select each IP address follows a geometric distribution. If you want to choose them uniformly, the probability of selecting an IP address (knowing the previous ones were discarded) must be 1/9 for the second, 1/8 for the third and so on:

acl random1 random 1/10
acl random2 random 1/9
acl random3 random 1/8
acl random4 random 1/7
acl random5 random 1/6
acl random6 random 1/5
acl random7 random 1/4
acl random8 random 1/3
acl random9 random 1/2

tcp_outgoing_address 10.0.0.2 random1
tcp_outgoing_address 10.0.0.3 random2
tcp_outgoing_address 10.0.0.4 random3
tcp_outgoing_address 10.0.0.5 random4
tcp_outgoing_address 10.0.0.6 random5
tcp_outgoing_address 10.0.0.7 random6
tcp_outgoing_address 10.0.0.8 random7
tcp_outgoing_address 10.0.0.9 random8
tcp_outgoing_address 10.0.0.10 random9
tcp_outgoing_address 10.0.0.11
Related Topic