Binding JVM to An IP Other than Default

拥有回忆 提交于 2019-12-08 12:23:13

问题


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..


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/2134924/binding-jvm-to-an-ip-other-than-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!