Binding JVM to An IP Other than Default
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 u开发者_运维知识库sing 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..
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?
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.
精彩评论