一个奇怪的UnknownHostException

一个奇怪的UnknownHostException

本文介绍了一个奇怪的UnknownHostException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网络项目中.
我看到了日志:

In a web project .
I see the log:

hadoop.hbase.zookeeper.ZKConfig - java.net.UnknownHostException: example.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1201)
at java.net.InetAddress.getAllByName0(InetAddress.java:1154)
at java.net.InetAddress.getAllByName(InetAddress.java:1084)
at java.net.InetAddress.getAllByName(InetAddress.java:1020)
at java.net.InetAddress.getByName(InetAddress.java:970)

但是当我 ping example.com 没关系时,我也成功 telnet example.com 2181 !我发现了类似的问题因此我在服务器 java DomainResolutionTest example.com 中运行DomainResolutionTest
没关系!

but when I ping example.com, it's ok, I also telnet example.com 2181 successfully!I found the similar questionso I run the DomainResolutionTest in my Server java DomainResolutionTest example.com
but it's ok !

env:

java -version

java版本"1.6.0_25"
Java(TM)SE运行时环境(内部版本1.6.0_25-b06)
Java HotSpot(TM)64位服务器VM(内部版本20.0-b11,混合模式)

java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)

os:Red Hat Enterprise Linux Server release 5.7

我很好奇为什么是Inet6AddressImpl,我想可能是Inet4AddressImpl

如何解决?
是什么原因?

How to solve it?
What's the cause ?

推荐答案

我遇到了相同的异常,并通过在/etc/hosts中手动为"localhost"条目设置了我的主机名来解决了这个问题.

i have had the same exception and solved it by setting my hostname manually in /etc/hosts for the 'localhost' entry both.

127.0.0.1       localhost DL006285-linux

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback DL006285-linux

这篇关于一个奇怪的UnknownHostException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:56