views:

89

answers:

3

I have a multihomed system with multiple NICs and IPs.

I am not %100 sure how my Sun JVM chooses the IP representing 'this' system (that's the "source IP" when connecting to another system using Socket or URLConnection). Does it pick the system default NIC, or perhaps it does a reverse lookup on the system's name? etc.

In any case, is there a way to explicitly bind the JVM to a specific IP?

Alternatively, if anyone knows how to do that from Axis Webservices framework, that would be immensely helpful.

Much appreciated..

+3  A: 

It's done by the Operating System, not by JVM. It uses the routing table to determine which interface can route to the destination that you are trying to reach, and use it.

If you have multiple interfaces that can route to the given destination, in theory you should be able to choose which source address you'd use, but I don't know if you actually can --- perhaps bind before connect would do? But then, since you won't have access to the routing table, how do you decide what interfaces can reach to the destination?

Kohsuke Kawaguchi
+2  A: 

I'm not sure how to control it when using a URL, but when creating a Socket, you can use the constructor that takes a local address argument.

erickson
A: 

Thanks Erickson and Kohsuke for the responses.

Unfortunately, I'm looking for something that can be done through a JVM level configuration change, rather than at the code level; Because I'm implementing web services, and the boilerplate socket creation code is embedded deep within the Axis framework implementation or its automatically generated classes, and I'd like to avoid fiddling with either if at all possible.

dukeofspook
As Kohsuke pointed out, the default local address is a function of the OS. Although you've encountered this as a programmer, you might actually have better luck with your question at serverfault.com.
erickson