How to control source IP in multihome configuration

2.7k Views Asked by At

I have 14 java processes running on one blade. Each process have binding to virtual IP recognized by ProxyServer (F5), so when external client call to F5 his call redirected to one of 14 processes.

Most of all, my process (one of 14) perform call to another application running on different blade.

Here is the question: How can I control source IP in outgoing TCP packets on java process running with virtual IP on TCP client? In other words I am looking for a way to set virtual IP as the source address in outgoing TCP packets. (by default it set to physical IP of the blade).

2

There are 2 best solutions below

5
Alastair McCormack On

You can use the following Socket constructor:

Socket(String remoteHost, int remotePort, InetAddress localAddress, int localPort)

or use Socket.bind() after socket creation.

See http://docs.oracle.com/javase/6/docs/api/java/net/Socket.html

0
Brian White On

Forgetting the language/library for the moment... You define the local address and/or local port for a connecting socket the same way you do for a listening socket. You bind() the socket to whatever IP address and/or port you wish. Not binding is the same as binding to zero values.

When the value is zero, the OS will pick for you: For the address, it will bind to the address of the interface used to send to the destination. For the port, it will pick a non-privileged port (>1023) that is currently unused.