Java 无法从 AIX 解析 DNS 地址:UnknownHostException [英] Java cannot resolve DNS address from AIX: UnknownHostException
问题描述
我遇到了这个奇怪的错误.
I'm having this strange error.
在 AIX 上,如果我可以从命令行访问我的服务器(使用 ping/telnet)
On AIX, if I can reach my server from the command line ( using ping / telnet )
但是如果我尝试使用 java,我会遇到 UnkownHostException
But If I try using java I've got UnkownHostException
这是由于 Java 无法以某种方式使用"DNS,但我不知道为什么.如果我使用 IP 地址,它就可以正常工作.
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.
这是我的测试程序.
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!");
}
}
有谁知道 AIX 下的某种配置禁止程序(如 java)访问 DNS 信息?
Is anyone aware of some kind of configuration under AIX that forbids programs ( like java ) to access DNS information?
我(以及 sysadm )已将我的地址添加到/etc/hosts 中,但它也不起作用.
I ( well the sysadm ) have added my address in /etc/hosts but it doesn't work either.
提前致谢
Java 版本:
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)
推荐答案
设置系统属性
sun.net.spi.nameservice.provider.1=dns,sun
sun.net.spi.nameservice.provider.1=dns,sun
在 Ubuntu 上为我解决了这个问题
fixed this problem for me on Ubuntu
这篇关于Java 无法从 AIX 解析 DNS 地址:UnknownHostException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!