views:

39

answers:

3

Server has couple of ip addresses (let say 1 and 2)

iface eth0 inet static
  address         1.1.1.1
  netmask         255.255.255.0
  addresses-test      1.1.1.2/32

Address 1 is default and all applications use it. How can I change connection address for my applicaton? For example, app1 connects to serverX and serverX see client address 1, app2 connects to serverX and see client address 2.

Is it possible at least theoretically? I trying to find java API, but any other working way would be ok.

A: 

Apache rewrite rules are made for this, if I understand your question.

Tony Ennis
I'm not asking about *server*, I'm asking about *client* (program that connects to other servers)
valodzka
I realize. However are you sure you're solving the right problem with the right tool? Is this a web app?
Tony Ennis
It's crawler that collects data from other sites
valodzka
A: 

You can bind the socket to a specific local address before connecting, see http://download.oracle.com/javase/6/docs/api/java/net/Socket.html#bind(java.net.SocketAddress).

cmeerw
A: 

Thanks everybody, I've found solution here http://serverfault.com/questions/66571/using-ip-alias-and-route-to-visit-a-site-through-assigned-ip-address

valodzka
Ok, but that will change the source address for all applications on that machine. Your original question seemed to imply that you were looking for a way to control the source IP address for each application separately.
cmeerw