Why Java failing to resolve FQDN address mapped to IPv6 address?

286 Views Asked by At

I am trying a simple program that will take FQDN/hostname as input and return the IPv6 addresss mapped to that FQDN configured at the DNS server

       try {
            InetAddress add= InetAddress.getByName("SCP1.xyz.com");
                System.out.println(add);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

FQDN is configured in DNS and I can see response from DNS in tcpdump including IPv6 mapping. And dig also return the response with right IPv6 mapping:

;; ANSWER SECTION:
SCP1.xyz.com.         86400   IN      AAAA    2a00:8a00:4000:65ef:ffff:ffff:ffff:b58c

But Java failed to return IPv6 address and throws java.net.UnknownHostException:

java.net.UnknownHostException: No such host is known (SCP1.xyz.com)
    at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
    at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1515)
    at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
    at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505)
    at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364)
    at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298)
    at java.base/java.net.InetAddress.getByName(InetAddress.java:1248)
    at mypack.ResolutionTest.main(ResolutionTest.java:26)

The same code works fine when FQDN is mapped to IPv4. I tried setting -Dsun.net.spi.nameservice.provider.1=dns,sun but nothing improved.

NOTE: behaviour is same in both LINUX and Windows

I am new to this stuff so would appreciate any assistance. Thanks.

0

There are 0 best solutions below