I have the following code:
import java.net.InetAddress;
public class lookup {
public static void main(String[] args) throws Exception {
for(String host : args){
for(InetAddress addr : InetAddress.getAllByName(host)){
System.out.println(addr.getHostAddress());
}
}
}
}
We recently changed the CNAME for a host we'll call foo.example.com from pointing at bar.example.com to point at baz.example.com. If I run:
java -Djava.net.preferIPv4Stack=true lookup foo.example.com
I get baz.example.com's ip address, as expected. However if I run:
java lookup foo.example.com
I still get bar.example.com's ip address.
I've confirmed that neither bar.example.com nor baz.example.com have AAAA records. dig
and ping
both resolve baz.example.com as expected. How do I get java's ipv6 stack to properly resolve this?