A strange UnknownHostException

18,705

Solution 1

i have had the same exception and solved it by setting my hostname manually in /etc/hosts for the 'localhost' entry both.

127.0.0.1       localhost DL006285-linux

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback DL006285-linux

Solution 2

If it is a dual stack (ipv6 + v4) Java prefers ipv6.

You can force it to prefer ipv4, if your ipv6 is misconfigured somehow.

Set system property with: -Djava.net.preferIPv4Stack=true

soure: http://docs.oracle.com/javase/6/docs/technotes/guides/net/ipv6_guide/

Solution 3

There may be problem in giving the subnet value to the program. I gave the subnet value by trimming it before passing to the program.

subnet = subnet.trim();
int timeout = 1500;
for(int i=1;i<254;i++)
        {
        try
          {
            String host = subnet +"."+i;
            if (InetAddress.getByName(host).isReachable(timeout))
              {
                Check = Check+host+"\n";
                System.out.println(host);
              } 

           }
        catch (UnknownHostException ex) { 
            Logger.getLogger(WiFi.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(WiFi.class.getName()).log(Level.SEVERE, null, ex);
Share:
18,705
fuyou001
Author by

fuyou001

soft [email protected]

Updated on June 04, 2022

Comments

  • fuyou001
    fuyou001 almost 2 years

    In a web project .
    I see the log:

    hadoop.hbase.zookeeper.ZKConfig - java.net.UnknownHostException: example.com 
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1201)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1154)
    at java.net.InetAddress.getAllByName(InetAddress.java:1084)
    at java.net.InetAddress.getAllByName(InetAddress.java:1020)
    at java.net.InetAddress.getByName(InetAddress.java:970)
    

    but when I ping example.com, it's ok, I also telnet example.com 2181 successfully! I found the similar question so I run the DomainResolutionTest in my Server java DomainResolutionTest example.com
    but it's ok !

    env:

    java -version
    

    java version "1.6.0_25"
    Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
    Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)

    os:Red Hat Enterprise Linux Server release 5.7

    I am curious why is Inet6AddressImpl,I think it may be Inet4AddressImpl

    How to solve it?
    What's the cause ?