Ubuntu – How to tell squid use Source IP address for sending requests

ipPROXYsquidUbuntu

I have two interfaces in my ifconfig, eth0 and eth1. Squid is set to accept connections from both of them on port 3000.

However, eth0's ip address is always used to send proxy requests, even if client has connected using eth1 address.

How do i force squid to always use just the source IP as tcp_outgoing_address (without writing this IP in config file)?

What i've tried additionally:

acl from_eth0 src A.B.C.D/1
acl from_eth1 src E.F.G.H/1

tcp_outgoing_address A.B.C.D from_eth0
tcp_outgoing_address E.F.G.H from_eth1

If i need to use iptables, how exactly rules will look for me?

Best Answer

There are many types of acl. src means the client IP and not the interface IP (local address).

I use localip acl type for that purpose:

acl from_eth0 localip A.B.C.D
acl from_eth1 localip E.F.G.H

tcp_outgoing_address A.B.C.D from_eth0
tcp_outgoing_address E.F.G.H from_eth1
tcp_outgoing_address 1.2.3.4 # default

ACL types are described in doc page.

However, it's painful to write each address by hand. I don't think it's a final solution because of that.