Java cannot resolve DNS address from AIX: UnknownHostException

后端 未结 5 491
無奈伤痛
無奈伤痛 2021-01-16 04:26

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 UnkownHostE

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-16 04:42

    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.").

提交回复
热议问题