getLocalHost()

T

Thomas Richter

Hi folks,

consider a Linux machine with a temporary internet connection that is
shut down/reconnected occasionally and that receives its hostname
(when applicable) via DHCP. If I'm shutting the running network
connection down with "ifdown eth0", then

java.net.InetAddress.getLocalHost()

fails with an "UnknownHostException".

What's that supposed to say? There *is* always a local host,
and its name is "localhost", so why does it fail? And if
so, how could it fail?

Aparently, the sytem host name (returned by gethostname(2)) is
still that one assigned by the DHCP server, which is now invalid,
by why is *that* address of any interest since "localhost" would
always be apropriate?


Greetings,
Thomas
 
G

Gordon Beaton

If I'm shutting the running network connection down with "ifdown
eth0", then

java.net.InetAddress.getLocalHost()

fails with an "UnknownHostException".

What's that supposed to say? There *is* always a local host, and its
name is "localhost", so why does it fail? And if so, how could it
fail?

What does the "hosts" entry in /etc/nsswitch say? Does it list "files"
before "dns"?

What does /etc/hosts contain? Does it (incorrectly) map "localhost" to
an IP address other than 127.0.0.1?

/gordon
 
T

Thomas Richter

Hi Gordon,
What does the "hosts" entry in /etc/nsswitch say? Does it list "files"
before "dns"?

No, it lists first "dns", then "files". (Yes, I fixed that...)
What does /etc/hosts contain? Does it (incorrectly) map "localhost" to
an IP address other than 127.0.0.1?

No. If I set the hostname manually to "localhost" by calling sethostname(2),
everything's back fine; the problem seems to be that the system still
believes it has the hostname assigned by the DHCP server.

So long,
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top