Java 无法从 AIX 解析 DNS 地址:UnknownHostException

发布于 2024-07-23 20:58:30 字数 1103 浏览 2 评论 0原文

我遇到了这个奇怪的错误。

在 AIX 上,如果我可以从命令行访问我的服务器(使用 ping / telnet ),

但是如果我尝试使用 java,则会出现 UnkownHostException

这是由于 Java 无法以某种方式“使用”DNS,但我不知道为什么。 如果我使用 IP 地址,它工作正常。

这是我的测试程序。

    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 信息?

我(以及 sysadm )已在 /etc/hosts 中添加了我的地址,但它也不起作用。

预先感谢

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)

I'm having this strange error.

On AIX, if I can reach my server from the command line ( using ping / telnet )

But If I try using java I've got UnkownHostException

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.

This is my test program.

    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!");

            }
     }

Is anyone aware of some kind of configuration under AIX that forbids programs ( like java ) to access DNS information?

I ( well the sysadm ) have added my address in /etc/hosts but it doesn't work either.

Thanks in advance

Java version:

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦里人 2024-07-30 20:58:31

设置系统属性

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

在 Ubuntu 上为我解决了这个问题

Setting the System property

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

fixed this problem for me on Ubuntu

哑剧 2024-07-30 20:58:31

检查您是否需要使用代理,如果需要,请在命令行上指定其详细信息

http://helpdesk.objects.com.au/java/how-to-tell-a-java-application-to-use-a-proxy-服务器

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

忆伤 2024-07-30 20:58:31

您必须签入 /etc/services 文件。

我遇到了同样的错误,这是因为 service:

domain .......... 

被评论了。

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

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

domain .......... 

was commented.

路还长,别太狂 2024-07-30 20:58:30

我也有这个问题。 我在Ubuntu64上安装了许多java程序,但它们都不能解析域名(还有多个JRE - 其中一些是IBM产品)。 如果我将域名与 IP 地址一起放入主机文件中,则它仅适用于这些域。 所有其他非 java 程序都可以很好地处理域解析。 诡异的!
如果我找到答案,我会将其发布在这里。 如果您有答案,请帮助我们!

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!

亽野灬性zι浪 2024-07-30 20:58:30

Java 似乎不尊重系统上指定的 DNS 查找顺序。 例如,在我的 Solaris 系统上,我在 /etc/nsswitch.conf 中定义了:

hosts: files nis dns

Java 希望首先转到 dns,但我不这样做理解。 似乎可以通过设置 来更改顺序sun.net.spi.nameservice.provider.n 属性。

我发现的一种解决方法是附加一个“.” 在主机名的末尾。 例如,如果在 /etc/hosts 中,我

192.168.1.1 mailhost

在我的 java 应用程序中,我将指定 InetAddress.getAllByName("mailhost.")

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文