java getLocalHost()UnknownHostException/etc/hosts文件与linux api不同吗? [英] java getLocalHost() UnknownHostException /etc/hosts file differs linux api?

查看:184
本文介绍了java getLocalHost()UnknownHostException/etc/hosts文件与linux api不同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两台redhat 6.3机器,两者在/etc/hosts中都没有变化(即,我还没有为它们添加IP地址).在我的机器上可以正常运行getLocalhost并返回主机名a.domain.com.另一个失败,并显示UnknownHostException.

I have two redhat 6.3 machines, BOTH have no changes in /etc/hosts (ie. I have not added an ip address to them). On of my machines can run getLocalhost fine AND return the hostname a.domain.com. The other one fails with UnknownHostException.

以前,我总是将ip添加到/etc/hosts中,但是我想知道为什么这台机器不需要它.两台机器上的/etc/nsswitch.conf都有主机:文件dns",因此两台机器上都是相同的.

Previously, I always added ip to /etc/hosts, but I am wondering why this one machine does not needs that. The /etc/nsswitch.conf on both machines has "hosts: files dns" so that is the same on both machines.

/etc/sysconfig/network-scripts/ifcfg-eth0脚本有很大的不同.出现UnknownHostException的节点是这样的

There is a big difference on the /etc/sysconfig/network-scripts/ifcfg-eth0 scripts. The node that gets UnknownHostException is something like this

DEVICE="eth0"
BOOTPROTO="static"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=10.10.1.5
PREFIX=23

工作的人是这样的...

The one that works has something like this...

DEVICE="eth0"
HWADDR="AA:AA:AA:AA:3F:A8"
NM_CONTROLLED="yes"
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
IPADDR=10.10.1.2
PREFIX=23
GATEWAY=10.10.1.1
DNS1=10.20.100.100
DNS2=10.20.100.101
DOMAIN="domain.com sub.domain.com"

这可能是原因吗?还是我可以查看哪些其他文件以查看为什么它不起作用?我认为Java正在对计算机进行一些linux getLocalHost api调用以获取主机名.

Could this somehow be the cause? or what other files can I look at to see why this is not working? I assume java is making some linux getLocalHost api call into the machine to get the hostname.

谢谢, 院长

推荐答案

嗯,我偶然发现了两者之间的区别.在我的/etc/sysconfig/network文件中,我在工作计算机上具有FQDN,但在另一台计算机上,我只有主机名"b",因此将其更改为"b.domain.com"可以解决此问题,而我没有这样做.根本不需要修改我的/etc/hosts文件!!!!

ah, I stumbled upon the difference. In my /etc/sysconfig/network file, I had the FQDN on the working machine but on the other machine, I only had the hostname "b" so changing that to "b.domain.com" fixed the issue and I don't need to modify my /etc/hosts file at all!!!!

迪恩

这篇关于java getLocalHost()UnknownHostException/etc/hosts文件与linux api不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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