Ubuntu64 9.04机器上的Java应用程序中的域名解析不起作用。所有其他软件都能正确解析DNS [英] Domain name resolution not working in Java Applications on Ubuntu64 9.04 machine. All other software resolves DNS correctly

查看:188
本文介绍了Ubuntu64 9.04机器上的Java应用程序中的域名解析不起作用。所有其他软件都能正确解析DNS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Java应用程序安装在Ubuntu64 9.04 PC上,并没有一个可以解析域名(有多个JRE也是一些IBM产品)。如果我将域名与其相关联的IP地址放在hosts文件中,则Java应用程序仅适用于这些域。每个其他非Java程序 - 如ping,firefox等 - 在域解析方面工作正常。我已经尝试在java.security文件中禁用DNS缓存(对于我的所有JRE),但是也没有。我会感谢一些帮助,弄清楚这一个。谢谢!






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

  jgreenwood @ jeg-ubuntu64:〜 $ cat /etc/resolv.conf 
#由NetworkManager生成
domain hsd1.in.comcast.net。
搜索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
;;全局选项:printcmd
;;得到答案:
;; - >> HEADER< - opcode:QUERY,status:NOERROR,id:56845
;;国旗:qr rd ra; QUERY:1,ANSWER:3,AUTHORITY:0,ADDITIONAL:0

;;问题部分:
; google.com。 IN A

;;答案部分:
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

;;查询时间:35毫秒
;;服务器: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()+\\\
+ 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();
}

}

输出是:

 错误:www.google.com 
java.net.UnknownHostException:www.google.com
在java。 net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
在java.net.InetAddress $ 1.lookupAllHostAddr(InetAddress.java:862)
在java.net.InetAddress.getAddressFromNameService(InetAddress.java:1213)
在java.net.InetAddress.getAllByName0(InetAddress.java:1166)
在java.net.InetAddress.getAllByName(InetAddress.java:1096)
在java.net.InetAddress.getAllByName(InetAddress .java:1032)
在java.net.InetAddress.getByName(InetAddress.java:982)
在DomainResolutionTest.main(DomainResolutionTest.java:12)






从命令行:(相同结果)

  jgreenwood @ jeg-ubuntu64:〜$ javac DomainResolutionTest.java 
jgreenwood @ jeg-ubuntu64:〜$ java DomainResolutionTest
错误:www.google.com
java.net.UnknownHostException:www.google.com
在java.net.Inet6AddressImpl.lookupAllHostAddr(本机方法)
在java.net.InetAddress $ 1.lookupAllHostAddr(InetAddress.java:849 )
在java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
在java.net.InetAddress.getAllByName0(InetAddress.java:1153)
在java.net.InetAddress。 getAllByName(InetAddress.java:1083)
在java.net.InetAddress.getAllByName(InetAddress.java:1019)
在java.net.InetAddress.getByName(InetAddress.java:969)
在DomainResolutionTest.main(DomainResolutionTest.java:12)
jgreenwood @ jeg-ubuntu64:〜$ java -version
java版本1.6.0_16
Java(TM)SE运行时环境1.6.0_16-b01)
Java HotSpot(TM)服务器虚拟机(build 14.2-b01,混合模式)
jgreenwood @ jeg-ubuntu64:〜$
/ pre>

解决方案

再次,由于这里的人的指导,我找到了一个答案。以下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错误:www.google.com
java.net.UnknownHostException:www.google.com
在java.net.Inet6AddressImpl.lookupAllHostAddr(本地方法)
在java .net.InetAddress $ 1.lookupAllHostAddr(InetAddress.java:849)
在java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
在java.net.InetAddress.getAllByName0(InetAddress.java: 1153)
在java.net.InetAddress.getAllByName(InetAddress.java:1083)
在java.net.InetAddress.getAllByName(InetAddress.java:1019)
在java.net.InetAddress .getByName(InetAddress.java:969)
在DomainReso lutionTest.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/+问题/ 23024



我确实希望在每次运行Java应用程序时都不必添加IPv4垃圾邮件。最终的解决方案可能在第二个链接 - 一个丢失的包。我们将看到。


Debian错误报告日志 - #477211
ia32-sun-java6-bin:需要依赖于
lib32nss-mdns
...
无法解析域名。在系统的其余部分解决
罚款,
未与其他JDK进行测试。
从包装中安装并设置
update-java-alternatives。



DNS适用于我的
系统上的其他一切。在Debian上运行
2.6.23-AMD64。尝试过Lenny包和Sid包。作为
与sun-java6-bin的预期,$ ia32-sun-java6-bin
失败。精氨酸。 ...如果
你用strace打java,你会看到
它试图使用
libnss_mdns4_minimal.so.2,这是
可用的包
lib32nss-mdns。你应该添加一个
依赖来修复错误。



同样的事情发生在sun-java6-bin -
libnss-mdns被使用


我的机器上确实没有包裹:

  jgreenwood @ jeg-ubuntu64:〜$ dpkg -L lib32nss-mdns 
未安装lib32nss-mdns包。
使用dpkg --info(= dpkg-deb --info)来检查存档文件
和dpkg --contents(= dpkg-deb --contents)来列出其内容。

无论哪种方式,我希望这篇文章能帮助别人,因为这是一个主要的PITA。


I have an number of Java applications installed on an Ubuntu64 9.04 PC, 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 it's associated IP address, then the Java apps work for those domains only. Every other non Java program - like ping, firefox, etc - work just fine with domain resolution. I've tried to disable DNS caching in the java.security file - for all of my JREs - but that didn't work either. I would appreciate some help in figuring this one out. Thanks!


UPDATE: I am sure there isn't a proxy server in my home or office. - I appreciate you guys helping me here. I REALLY want to use Linux instead of windows now that I'm doing Java development again.

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


UPDATE: I wrote this java program in RAD:

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();
    }

}

The output is:

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)


From the command line: (same result)

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

解决方案

Once again, thanks to the guidance of the people here, I've found an answer. The Java program above works when I do the following:

java -Djava.net.preferIPv4Stack=true DomainResolutionTest


Details:

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)

It turns out that there is a bug in the IPv6 stack. There are a couple of posts that led me to this conclusion:

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

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

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

I sure hope I don't have to add the IPv4 crap in every time I run a Java app. The final solution may be in the second link - a missing package. We shall see.

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.

The package is indeed missing on my machine:

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.

Either way, I hope this post helps someone else, because this was a major PITA to figure out.

这篇关于Ubuntu64 9.04机器上的Java应用程序中的域名解析不起作用。所有其他软件都能正确解析DNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆