gpt4 book ai didi

linux - 域名解析在 Ubuntu64 9.04 机器上的 Java 应用程序中不起作用。所有其他软件都能正确解析 DNS

转载 作者:IT王子 更新时间:2023-10-29 00:22:43 31 4
gpt4 key购买 nike

我在 Ubuntu64 9.04 PC 上安装了许多 Java 应用程序,但它们都不能解析域名(也有多个 JRE - 其中一些是 IBM 产品)。如果我将域名及其关联的 IP 地址放在主机文件中,则 Java 应用程序仅适用于这些域。所有其他非 Java 程序(如 ping、firefox 等)都可以很好地处理域解析。我已经尝试在 java.security 文件中禁用 DNS 缓存 - 对于我的所有 JRE - 但那也不起作用。我会很感激一些帮助来解决这个问题。谢谢!


更新:我确定我家里或办公室里没有代理服务器。 - 感谢你们在这里帮助我。既然我又在进行 Java 开发,我真的很想使用 Linux 而不是 Windows。

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:~$

最佳答案

再次感谢这里的人的指导,我找到了答案。当我执行以下操作时,上面的 Java 程序可以工作:

java -Djava.net.preferIPv4Stack=true DomainResolutionTest

详细信息:

jgreenwood@jeg-ubuntu64:~$ java -Djava.net.preferIPv4Stack=true DomainResolutionTest 
www.google.com/209.85.225.106
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)

事实证明,IPv6 堆栈中存在错误。有几篇文章使我得出了这个结论:

http://uclue.com/?xq=2127

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477211

https://answers.launchpad.net/ubuntu/+question/23024

我当然希望我不必在每次运行 Java 应用程序时都添加 IPv4 废话。最终的解决方案可能在第二个链接中——一个丢失的包。我们拭目以待。

Debian Bug report logs - #477211 ia32-sun-java6-bin: Needs to depend on lib32nss-mdns ... Cannot resolve domain names. Resolve fine on the rest of the system, have not tested with other JDK's. Installed from package and set with update-java-alternatives.

DNS works for everything else on my system. Running on Debian 2.6.23-AMD64. Have tried both Lenny packages and Sid packages. Works as expected with sun-java6-bin, fails with ia32-sun-java6-bin. Arg. ... If you hit java with strace you'll see that it is trying to use libnss_mdns4_minimal.so.2, which is available in the package lib32nss-mdns. You should add a dependency on that to fix the bug.

Same thing happens for sun-java6-bin - libnss-mdns is used here.

我的机器上确实缺少这个包:

jgreenwood@jeg-ubuntu64:~$ dpkg -L lib32nss-mdns
Package `lib32nss-mdns' is not installed.
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

无论如何,我希望这篇文章对其他人有所帮助,因为这是一个需要解决的主要 PITA。

关于linux - 域名解析在 Ubuntu64 9.04 机器上的 Java 应用程序中不起作用。所有其他软件都能正确解析 DNS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1608503/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com