Java cannot resolve DNS address from AIX: UnknownH

2019-02-20 02:46发布

I'm having this strange error.

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

But If I try using java I've got UnkownHostException

This is due to Java cannot somehow "use" the DNS but I don't know why. If I use the 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!");

            }
     }

Is anyone aware of some kind of configuration under AIX that forbids programs ( like java ) to access DNS information?

I ( well the sysadm ) have added my address in /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)

标签: java dns aix
5条回答
放我归山
2楼-- · 2019-02-20 03:02

Setting the System property

sun.net.spi.nameservice.provider.1=dns,sun

fixed this problem for me on Ubuntu

查看更多
smile是对你的礼貌
3楼-- · 2019-02-20 03:03

I am having this problem as well. I have an number of java programs installed on Ubuntu64, and none of them can resolve domain names (there are multiple JRE's too - some of them are IBM products). If I put the domain name in the hosts file with the IP address, then it works for those domains only. Every other non java program works just fine with domain resolution. WEIRD! If I find the answer, I will post it here. If you have the answer, help us please!

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-02-20 03:12

You have to check in the /etc/services files.

I had the same error and it was because the service:

domain .......... 

was commented.

查看更多
爷的心禁止访问
5楼-- · 2019-02-20 03:15

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

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

查看更多
戒情不戒烟
6楼-- · 2019-02-20 03:18

Java doesn't seem to respect the ordering of DNS lookups specified on the system. For example, on my Solaris system in /etc/nsswitch.conf I have defined:

hosts: files nis dns

Java want to go to dns first, which I don't understand. It seems like it's possible to change the ordering, by setting sun.net.spi.nameservice.provider.n properties.

One workaround I've found is to append a '.' at the end of a host name. For example, if in /etc/hosts, I have

192.168.1.1 mailhost

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

查看更多
登录 后发表回答