I’ve got a few host that return an unqualified name for InetAddress.getLocalHost().getCanonicalHostName()
(Documented here)
e.g. “foo” instead of “foo.example.com”.
What could cause this and how could I fix it?
Running “hostname -f
” on the command line returns the FQDN
and nslookup
on the short name also returns the FQDN.
CentOS 7.7.1908
JRE 1.8.0_231-b11
2
Answers
Can you paste contents of /etc/hosts file?
or the output of cat /etc/hosts | grep localhost
The issue is most likely there, as it does not have a FQDN defined for 127.0.0.1
It’s likely your machine’s configuration. Check that DNS for the domain resolves properly and that there is a domain set.
Java will either lookup in
/etc/hosts
or use you OS facilities to do the name address to name resolution.Since you’re looking for localhost, you may need a host specific mechanism to resolve it.
Also your machine likely has many interfaces, and not all of them may resolve to the same FQDN.
It may help to enumerate all network interfaces to see what’s wrong: