I have a very specific use-case at work where I have several external IP addresses (a full class C), and I need to select the outbound IP address I'm using. The requests are http, and the application server is a different machine on the internal network. For simplicity, I'd like to keep this as an http proxy so I don't have to change my application code.


  • Proxy looks for a header like "External-Ip: x.y.z.a" and sends traffic through the interface with that external IP address. I am able to easily modify the header so if I need to send the interface name that's fine.
  • If the header doesn't exist the proxy will pick a random one, and then return which interface it used as an http header.

What's the easiest way to accomplish this?

  • I don't understand the situation yet. Sometimes the questioners are so nice to illustrate the network with some ASCII art... Your gateway has to decide which external IP it shall use. The proxy does not run on the gateway so how should it make such a decision? Do you have several (virtual) gateways? How shall the gateway read HTTP headers? May 17, 2013 at 22:26
  • @HaukeLaging: I don't know. I have requirements (application specify the public IP) and something needs to make that happen. Right now the gateway and the proxy are the same machine and that routing is done with a very hacky C program that requires daily reboots. I know this, or similar, problems have been solved "correctly" before and I'm trying to figure out how. May 17, 2013 at 22:30
  • Was a language problem; I had misunderstood "For simplicity, I'd like to keep this as an http proxy". May 17, 2013 at 22:44
  • You can use Safesquid proxy, this feature is available in that.. just search on google May 18, 2013 at 2:29

1 Answer 1


For what it's worth, Squid has this built in natively.

I used 'acl outbound0 req_header .2$' to set an ACL named 'outbound0' to the .2 external IP. I generated the remaining ACLs with a script and just hardcoded them in the config file.

Then, I combined it with tcp_outgoing_address, which chooses an external IP based on ACLs. The result looks like:

acl outbound0 req_header TS-Outbound-IP \.20$
acl outbound1 req_header TS-Outbound-IP \.21$
acl outbound2 req_header TS-Outbound-IP \.22$
acl outbound3 req_header TS-Outbound-IP \.23$
acl outbound4 req_header TS-Outbound-IP \.24$
acl outbound5 req_header TS-Outbound-IP \.25$

tcp_outgoing_address outbound0
tcp_outgoing_address outbound1
tcp_outgoing_address outbound2
tcp_outgoing_address outbound3
tcp_outgoing_address outbound4
tcp_outgoing_address outbound5

For now, this works perfectly for what we need. I'll keep the question open because this method seems kludgy, and I"m interested in alternatives.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .