Wednesday, July 22, 2009

Specify Outgoing IPs Using Squid

A while back, I asked some of my fellow gurus if I could use Squid to specify an outgoing IP based on what port a connection is made and no knew. Turns out you can.

Linux Version: Ubuntu 8.04
Squid Version: Squid Cache: Version 3.0.STABLE1

Say I have several IPs on a server such as 192.168.42.3, 192.168.42.4, and 192.168.42.5. I want Squid to listen on three different ports, and depending on what port a client connects to, use a different outgoing IP address. Here is what needs to go into the squid configuration file (/etc/squid3/squid.conf):

acl port1 myport 3128
tcp_outgoing_address 192.168.42.3 port1

acl port2 myport 3129
tcp_outgoing_address 192.168.42.4 port2

acl port3 myport 3130
tcp_outgoing_address 192.168.42.5 port3

http_port 3128
http_port 3129
http_port 3130