I have a java server. I want to be able to connect to it with a JMX client. I do this:
JMXServiceURL jmxUrl = new JMXServiceURL(null,null,JMX_PORT);
JMXConnectorServer jmxRemoteServer;
jmxRemoteServer=JMXConnectorServerFactory.newJMXConnectorServer(jmxUrl, jmxEnvironment, server);
jmxRemoteServer.start();
This works. I can fire up JConsole and connect to JMX_PORT on my machine and pretty graphs show up.
There is a problem. This causes the JMX server to bind to JMX_PORT on all interfaces. I want to have it bind to 127.0.0.1 only. Otherwise, it is a security concern for me.
According to the documentation, JMXServiceURL jmxUrl = new JMXServiceURL(null,null,config.getJmxRemotePort());
should create a JMXServiceURL with the default protocol (jmxmp) and localhost. I have tried giving it "127.0.0.1" explicitely as an address to bind to, and it did not work either.
Java's JMX server binds to all IP addresses, and refuses to bind to 127.0.0.1 only.