Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
857 views
in Technique[技术] by (71.8m points)

java getLocalHost() UnknownHostException /etc/hosts file differs linux api?

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.

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.

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"

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.

thanks, Dean

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!!!!

Dean


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...