我安装了一个Ubuntu64 9.04 PC上的Java应用程序的数量,并没有一个可以解析域名(有多个JRE的太多 - 其中一些是IBM的产品)。 如果我把该域名的hosts文件与它相关的IP地址,那么Java应用程序仅用于这些领域的工作。 所有其他非Java程序 - 如ping,火狐等 - 的工作只是域名解析的罚款。 我试着在java.security文件中禁用DNS缓存 - 我所有的JRE的 - 但也不能工作。 我希望在搞清楚了这一个了一些帮助。 谢谢!
更新:我肯定没有在我的家中或办公室中的代理服务器。 - 我感谢你们帮助我这里。 我真的想现在我又做Java开发,而不是使用Windows的Linux操作系统。
jgreenwood@jeg-ubuntu64:~$ cat /etc/resolv.conf
# Generated by NetworkManager
domain hsd1.in.comcast.net.
search hsd1.in.comcast.net.
nameserver 192.168.0.1
jgreenwood@jeg-ubuntu64:~$ env | grep -i proxy
jgreenwood@jeg-ubuntu64:~$ dig google.com
; <<>> DiG 9.5.1-P2 <<>> google.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56845
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 58 IN A 74.125.53.100
google.com. 58 IN A 74.125.45.100
google.com. 58 IN A 74.125.67.100
;; Query time: 35 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Thu Oct 22 13:37:26 2009
;; MSG SIZE rcvd: 76
更新:我在RAD写了这个java程序:
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.io.PrintWriter;
import java.io.StringWriter;
public class DomainResolutionTest {
public static void main(String[] args) {
if (args.length == 0) args = new String[] { "www.google.com" };
try {
InetAddress ip = InetAddress.getByName(args[0]);
System.out.println(ip.toString());
}catch (UnknownHostException uhx) {
System.out.println("ERROR: " + uhx.getMessage() + "\n" + getStackTrace(uhx));
Throwable cause = uhx.getCause();
if (cause != null) System.out.println("CAUSE: " + cause.getMessage());
}
}
public static String getStackTrace(Throwable t)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
t.printStackTrace(pw);
pw.flush();
sw.flush();
return sw.toString();
}
}
输出是:
ERROR: www.google.com
java.net.UnknownHostException: www.google.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:862)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1213)
at java.net.InetAddress.getAllByName0(InetAddress.java:1166)
at java.net.InetAddress.getAllByName(InetAddress.java:1096)
at java.net.InetAddress.getAllByName(InetAddress.java:1032)
at java.net.InetAddress.getByName(InetAddress.java:982)
at DomainResolutionTest.main(DomainResolutionTest.java:12)
在命令行:(相同的结果)
jgreenwood@jeg-ubuntu64:~$ javac DomainResolutionTest.java
jgreenwood@jeg-ubuntu64:~$ java DomainResolutionTest
ERROR: www.google.com
java.net.UnknownHostException: www.google.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)
at java.net.InetAddress.getByName(InetAddress.java:969)
at DomainResolutionTest.main(DomainResolutionTest.java:12)
jgreenwood@jeg-ubuntu64:~$ java -version
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)
jgreenwood@jeg-ubuntu64:~$