UnknownHostException when enabling JMX in Java 8

6,428

After debugging class java.net.InetAddress, method getLocalHost, I've seen it calls Inet4AddressImpl.getLocalHostName, which returns "185-69-214-74.ded.intelignet.com.br" when I use '-Djava.net.preferIPv4Stack=true'. If I omit 'java.net.preferIPv4Stack', then InetAddress.getLocalHost calls Inet6AddressImpl.getLocalHostName, which returns "mybox" and the problem goes away.

In other words, 'UnknownHostException' only happens if these conditions are both true:

  • -Djava.net.preferIPv4Stack=true
  • Java version = 8

So I'll just omit -Djava.net.preferIPv4Stack=true, since I haven't figured out another way of fixing this.

Share:
6,428

Related videos on Youtube

Elifarley
Author by

Elifarley

Updated on September 18, 2022

Comments

  • Elifarley
    Elifarley over 1 year

    Using Java 7, I can launch a JVM with JMX enabled without any problems using these properties:

    -Dcom.sun.management.jmxremote
    -Dcom.sun.management.jmxremote.ssl=false
    -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote.port=8787
    

    If I use Java 8 (Java build 1.8.0_45-b14; Java HotSpot(TM) 64-Bit Server VM build 25.45-b02, mixed mode), I always get an error like this:

    java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: 185-69-214-74.ded.intelignet.com.br: 185-69-214-74.ded.intelignet.com.br: unknown error

    The error also happens if I add this system property:

    -Djava.rmi.server.hostname=185.69.214.74

    However, I can successfully launch Java 8 if I don't enable JMX.

    Why don't I see the same problem under Java 7? What is causing this and what should I do to avoid this error even with JMX enabled?

    More details:

    $ hostname
    
    mybox
    
    $ hostname -i
    
    185.69.214.74
    
    $ host $(hostname -i)
    
    74.214.69.185.in-addr.arpa domain name pointer 185-69-214-74.ded.intelignet.com.br.
    

    A possible work-around is to edit /etc/hosts to add this line:

    185.69.214.74   185-69-214-74.ded.intelignet.com.br
    

    However, I'm not allowed to do this, so I must find another way to solve this problem.

  • ᴠɪɴᴄᴇɴᴛ
    ᴠɪɴᴄᴇɴᴛ about 5 years
    Not using -Djava.net.preferIPv4Stack=true (nor using false for the value or even using java.net.preferIPv6Addresses=true) doesn’t resolve the problem with current versions of Java 8 (build 102+).