title: JMX server and JConsole cannot connect
body: <p>I have a JMX enabled application which creates RMI Registry by doing:</p>
  
  <pre><code>rmiRegistry = LocateRegistry.createRegistry(registryPort);
  </code></pre>
  
  <p>and then later on it creates <a href="http://docs.oracle.com/javase/7/docs/api/javax/management/remote/JMXConnectorServer.html" rel="nofollow">JMXConnectorServer</a> by doing:</p>
  
  <pre><code>JMXServiceURL url = new JMXServiceURL(
        "service:jmx:rmi://localhost:" + serverPort 
        + "/jndi/rmi://:" + registryPort + "/jmxrmi");
  
  connector = JMXConnectorServerFactory.newJMXConnectorServer(
                      url, 
                      null,
                      ManagementFactory.getPlatformMBeanServer());
  connector.start();
  </code></pre>
  
  <p>My problem is that I cannot connect to this JMX Server from a remote host using JConsole. I've followed the instructions for debugging/tracing JConsole and I can see that the problem is that JConsole tries to connect to a bogus IP address that it must have gotten from the Registry. Ok, it isn't exactly bogus because it happens to correspond to a virtual network interface I have on the JMX Server host machine. How on earth does JMX pick that up?</p>
  
  <p>A <code>netstat</code> on my application reveals that both the <code>serverPort</code> and the <code>registryPort</code> are bound on the wildcard interface (on both IP4 and IP6) which is as expected since I haven't supplied socket factories. Basic connectivity works from the remote host, i.e. I can get the <em>telnet test</em> to pass on both ports.</p>
  
  <p>I would have assumed that I would have to change 'localhost' in the <code>JMXServiceURL</code> to the name of my host (as other hosts sees it, not how it sees itself) but that doesn't help.</p>
  
  <p>What do do ?</p>
  
  <h3>UPDATE1</h3>
  
  <p>After some more investigation I'm pretty sure this 'bogus IP address' comes because RMI just picks the first IP it finds on its own host and then uses that as its 'call-me-back' address. It then happens to find that virtual NIC that exists on this host. That's really not want I want. I want to be able to control explicitly the RMI 'call-me-back' address.</p>