Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

Requirements:

  • 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?

share|improve this question
    
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? –  Hauke Laging May 17 '13 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. –  insta May 17 '13 at 22:30
    
Was a language problem; I had misunderstood "For simplicity, I'd like to keep this as an http proxy". –  Hauke Laging May 17 '13 at 22:44
    
You can use Safesquid proxy, this feature is available in that.. just search on google –  Rahul Patil May 18 '13 at 2:29
add comment

1 Answer

up vote 0 down vote accepted

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 192.168.1.20 outbound0
tcp_outgoing_address 192.168.1.21 outbound1
tcp_outgoing_address 192.168.1.22 outbound2
tcp_outgoing_address 192.168.1.23 outbound3
tcp_outgoing_address 192.168.1.24 outbound4
tcp_outgoing_address 192.168.1.25 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.