0

Why JMX listening on 0.0.0.0? It is possible to change this listening to 127.0.0.1 only?

I searched JMX documentation for any information about listening on 0.0.0.0 and found nothing.

When I run my app and check in cmd netstat it prints TCP 0.0.0.0:1099 0.0.0.0:0 LISTENING [java.exe]

I register beans like:

    @Bean
    public ConnectorServerFactoryBean serverConnector() throws MalformedObjectNameException {
        ConnectorServerFactoryBean factoryBean=new ConnectorServerFactoryBean();
        factoryBean.setServiceUrl("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/appname");
        factoryBean.setThreaded(true);
        return factoryBean;
    }

    @Bean
    public RmiRegistryFactoryBean registry() {
        RmiRegistryFactoryBean factoryBean=new RmiRegistryFactoryBean();
        factoryBean.setPort(1099);
        factoryBean.setAlwaysCreate(true);
        return factoryBean;
    }

and

    @Bean
    public MBeanServerConnection clientConnection() throws IOException {
        MBeanServerConnectionFactoryBean factoryBean = new MBeanServerConnectionFactoryBean();
        factoryBean.setServiceUrl("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/appname");
        factoryBean.afterPropertiesSet();
        return factoryBean.getObject();
    }

Any ideas how can I change this listening to 127.0.0.1 only? I use Spring Boot 1.4.1.RELEASE

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Morvid
  • 1
  • 5
  • check entries around etc/hosts file – NPE Apr 02 '19 at 09:29
  • @NPE Check them why? Check them for what? What do explicitly written IP addresses have to do with the `/etc/hosts` file? – user207421 Apr 02 '19 at 09:45
  • `0.0.0.0` means all available ip addresses. Hence it already is listening on `127.0.0.1` and as well the external available ip address. – M. Deinum Apr 02 '19 at 09:46
  • @M.Deinum Indeed, but that doesn't mean there aren't good reasons for wanting to listen on 127.0.0.1 only. – user207421 Apr 02 '19 at 09:51
  • @M.Deinum yes, I know that this is a wildcard, but I want JMX to listening on `127.0.0.1` only. – Morvid Apr 02 '19 at 10:04
  • I never said that there aren't good reasons, but the why isn't clear. Maybe stuff isn't working and the OP things that is because things are listening on everything. – M. Deinum Apr 02 '19 at 10:04
  • Then please add that to your question. Also are you using regular Spring which you deploy to Tomcat or are you using Spring Boot? What to do is different on the way you use JMX. – M. Deinum Apr 02 '19 at 10:05
  • @M.Deinum already edited. I use Spring Boot 1.4.1.RELEASE. – Morvid Apr 02 '19 at 10:15
  • See https://stackoverflow.com/questions/35367232/how-to-configure-jmx-to-bind-to-localhost-only (which is more or less a duplicate of this). – M. Deinum Apr 02 '19 at 10:33

1 Answers1

0

You can use the Java Option -Djava.rmi.server.hostname=127.0.0.1 to listen only on 127.0.0.1

Ramesh Subramanian
  • 944
  • 1
  • 12
  • 28