Reputation: 833
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?
Upvotes: 1
Views: 1690
Reputation: 356
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().
Upvotes: 3