Java cannot resolve DNS address from AIX: UnknownHostException

元气小坏坏 提交于 2019-12-01 12:58:12

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!

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

Setting the System property

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

fixed this problem for me on Ubuntu

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

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

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

domain .......... 

was commented.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!