views:

350

answers:

3

The situation goes like this, I have two network interfaces in my macbook pro. One is a statically defined Ethernet interface and the other one is a DHCP configured wireless interface.

I am trying to figure out how to configure a specific java project to use my statically wired interface only and not simply pick the first one in the list either through the JVM or through my IDEA ( IntelliJ 8 )

I have managed to achieve this via an instance of vmware where I have my virtual environment feeding off my wired interface only but this ads performance problems and just general headaches of flipping between windows / osx.

I have so far been unable to find a jvm property that let's me specify which nic gets used nor have I seen documentation for IntelliJ that defines that. If anyone has any ideas on how to solve this as painlessly as possible I would appreciate the help.

+1  A: 

The NIC used for comms is selected by the operating system depending on the best 'route' available to what ever address is being accessed. There is no way for an application that sits above the NIC drivers to select a specific NIC. You can only get close when you're listening on a port bound at a specific address, which is only applicable if you're running a server.

You could try modifying the 'metric' of the route specific to a NIC to force the OS to prefer it.

Cogsy
That is what I feared, thanks for the answer I will try o apply my duck tape vmware solution for now.I was also thinking about using an intelligent proxy that would simply move traffic between the nics depending on who was calling it.
wojtek_z
+2  A: 

java.net.Socket has a constructor which specifies which local IP address to bind to, and since each network interface gets its own IP address, you can use that.

But getting from a java.net.Socket to a higher-level protocol (e.g. HTTP) is another matter entirely, but you don't specify what that would be.

I don't know of a JVM-level way of doing this, sadly, just the above programmatic approach.

skaffman
A: 

This may be of help: Identify Network Interface Example

"[I]f you have a preference or otherwise need to specify which NIC to use, you can query the system for the appropriate interfaces and find an address on the interface you want to use."

yawmark