Domain name resolution not working in Java Applications on Ubuntu64 9.04 machine. All other software resolves DNS correctly Domain name resolution not working in Java Applications on Ubuntu64 9.04 machine. All other software resolves DNS correctly linux linux

Domain name resolution not working in Java Applications on Ubuntu64 9.04 machine. All other software resolves DNS correctly


Once again, thanks to the guidance of the people here, I've found an answer. The Java program above works when I do the following:

java -Djava.net.preferIPv4Stack=true DomainResolutionTest

Details:

jgreenwood@jeg-ubuntu64:~$ java -Djava.net.preferIPv4Stack=true DomainResolutionTest www.google.com/209.85.225.106jgreenwood@jeg-ubuntu64:~$ java DomainResolutionTest ERROR: www.google.comjava.net.UnknownHostException: www.google.com    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)    at java.net.InetAddress.getAllByName0(InetAddress.java:1153)    at java.net.InetAddress.getAllByName(InetAddress.java:1083)    at java.net.InetAddress.getAllByName(InetAddress.java:1019)    at java.net.InetAddress.getByName(InetAddress.java:969)    at DomainResolutionTest.main(DomainResolutionTest.java:12)

It turns out that there is a bug in the IPv6 stack. There are a couple of posts that led me to this conclusion:

http://uclue.com/?xq=2127

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477211

https://answers.launchpad.net/ubuntu/+question/23024

I sure hope I don't have to add the IPv4 crap in every time I run a Java app. The final solution may be in the second link - a missing package. We shall see.

Debian Bug report logs - #477211 ia32-sun-java6-bin: Needs to depend on lib32nss-mdns ... Cannot resolve domain names. Resolve fine on the rest of the system, have not tested with other JDK's. Installed from package and set with update-java-alternatives.

DNS works for everything else on my system. Running on Debian 2.6.23-AMD64. Have tried both Lenny packages and Sid packages. Works as expected with sun-java6-bin, fails with ia32-sun-java6-bin. Arg. ... If you hit java with strace you'll see that it is trying to use libnss_mdns4_minimal.so.2, which is available in the package lib32nss-mdns. You should add a dependency on that to fix the bug.

Same thing happens for sun-java6-bin - libnss-mdns is used here.

The package is indeed missing on my machine:

jgreenwood@jeg-ubuntu64:~$ dpkg -L lib32nss-mdnsPackage `lib32nss-mdns' is not installed.Use dpkg --info (= dpkg-deb --info) to examine archive files,and dpkg --contents (= dpkg-deb --contents) to list their contents.

Either way, I hope this post helps someone else, because this was a major PITA to figure out.


This solution (-Djava.net.preferIPv4Stack=true) also works when there is long runing lookupAllHostAddr.