1

I've been having an issue with DNS lookup for IPv6 addresses that I can't seem to find good information about.

I'm trying to lookup an IPv6 address using InetAddress.getByName("ipv6.local.com"). It throws an UnknownHostException error.

The weird part is I know the DNS server can be contacted because this works:

InetAddress.getByName("ipv4.local.com")

I also know the IPv6 record is working because I can run:

nslookup ipv6.local.com

and it properly returns 3ffe:b00:0:1:4678:3eff:fe36:16e8.

Likewise, if I run the following in C++, I get a result with the above address as well:

int errorCode = getaddrinfo("ipv6.local.com", "4242", &hints, &res);

I have also tried Inet6Address.getByName(), but this also throws UnknownHostException. So why do getaddrinfo() and nslookup work and not InetAddress.getByName()?

I am attempting the DNS lookup from an Android device (Galaxy Tab S2 8") running Android 6.0.1 on the same network as the DNS server. The DNS server has a record "ipv4.local.com" pointing to 192.168.0.190, and a record "ipv6.local.com" pointing to 3ffe:b00:0:1:4678:3eff:fe36:16e8.

The DNS server is explicitly set in Wi-Fi settings on the Android device, and is running on 192.168.0.182.

Any ideas?

Ron Maupin
  • 6,180
  • 4
  • 29
  • 36
Jim
  • 833
  • 6
  • 13
  • http://stackoverflow.com/questions/41560351/android-getting-ipv6-address-from-hostname – Malt May 11 '17 at 21:29
  • Does `InetAddress.getAllByName()` return any IPv6 addresses for you? – Remy Lebeau May 11 '17 at 21:51
  • Thanks Remy. Unfortunately getAllByName throws the same UnknownHostException for ipv6.local.com and works for ipv4.local.com. – Jim May 16 '17 at 18:47
  • Where did you get the `3ffe:b00:0:1:4678:3eff:fe36:16e8` address? That is a global address, and you should not use a global address unless it was assigned to you by your ISP or RIR. I'm not suggesting that is your problem here, but it could cause you problems in the future if it wasn't properly assigned to you. – Ron Maupin Jul 22 '18 at 18:31

1 Answers1

3

I am not sure why IPv6 resolution is not working for you. Here is the example of Java code(java version "1.8.0_171") I tested:

package com.myjava.ip;


import java.net.InetAddress;
import java.net.UnknownHostException;

class MyIpByHost {

    public static void main(String a[]){

        try {
            InetAddress host = InetAddress.getByName("ipv6.google.com");
            System.out.println(host.getHostAddress());
        } catch (UnknownHostException ex) {
            ex.printStackTrace();
        }
    }
}

Output: java com/myjava/ip/MyIpByHost => 2404:6800:4003:c02:0:0:0:8a

This code returns IPv6 for endpoint "ipv6.google.com".

Java run C functions in it's backend to get work done. As you already know getaddrinfo() function of C supports IPv6, but gethostbyname() does not. You may be running outdated version of java with underlying C function gethostbyname() which does not support IPv6. I would suggest you to upgrade Java which will use getaddrinfo().

Nijil
  • 356
  • 3
  • 9