Configure Kafka to expose JMX only on 127.0.0.1

I just managed to make Kafka only listen to the defined broker port, and disabling JMX altogether:

export KAFKA_JMX_OPTS="-Djava.rmi.server.hostname=localhost -Djava.net.preferIPv4Stack=true"

When starting a fresh Kafka 1.1.0 broker on Ubuntu, I initially saw two open ports:

$ netstat -tulpn | grep 19894
tcp6       0      0 :::40487                :::*                    LISTEN      19894/java
tcp6       0      0 127.0.0.1:9092          :::*                    LISTEN      19894/java

After setting the above environment variable in the kafka-server-start.sh file, the second port is no longer opened:

$ netstat -tulpn | grep :9092
tcp        0      0 127.0.0.1:9092          0.0.0.0:*               LISTEN      20345/java
$ netstat -tulpn | grep 20345
tcp        0      0 127.0.0.1:9092          0.0.0.0:*               LISTEN      20345/java