Java cannot resolve DNS address from AIX: UnknownHostException

I got this strange error.

On AIX, if I can get to my server from the command line (using ping / telnet)

But if I try to use java, I have a UnkownHostException

This is because Java cannot somehow "use" DNS, but I don’t know why. If I use an IP address, it works fine.

This is my test program.

import java.net.*; public class Test { public static void main( String [] args ) throws Exception { String host = args[0]; int port = Integer.parseInt( args[1] ); System.out.println("Connecting to: " + host + " at port: " + port ); Socket socket = new Socket( host, port ); System.out.println("Connected!"); socket.close(); System.out.println("Closed!"); } } 

Does anyone know of some configuration on AIX that prevents programs (like java) from accessing DNS information?

I (well, sysadm) added my address to / etc / hosts, but it doesn't work either.

Thanks in advance

Java version:

 Java(TM) 2 Runtime Environment, Standard Edition (build pap32dev-20080315 (SR7)) IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 AIX ppc-32 j9vmap3223-20080315 (JIT enabled) 
+1
source share
5 answers

I have this problem too. I have several java programs installed on Ubuntu64, and none of them can resolve domain names (there are also several JREs - some of them are IBM products). If I put the domain name in the hosts file with an IP address, then it works only for these domains. Any other program other than Java works fine with domain resolution. WEIRD! If I find an answer, I will post it here. If you have an answer, please help us!

+1
source

Java does not seem to respect the DNS lookup order specified on the system. For example, on my Solaris system in /etc/nsswitch.conf I defined:

hosts: nis dns files

Java first wants to switch to dns , which I don’t understand. It seems that you can reorder by setting the sun.net.spi.nameservice.provider.n properties.

One workaround I found is to add '.' at the end of the hostname. For example, if in / etc / hosts I have

 192.168.1.1 mailhost 

In my java application, I would specify InetAddress.getAllByName("mailhost.") .

+1
source

Setting the System property

sun.net.spi.nameservice.provider.1 = DNS, Sun

fixed this problem for me on Ubuntu

+1
source

Check if you need to use a proxy server, and if so, specify its data on the command line

http://helpdesk.objects.com.au/java/how-to-tell-a-java-application-to-use-a-proxy-server

0
source

You should check the / etc / services files.

I had the same error, and this is because the service:

 domain .......... 

commented out.

0
source

All Articles