Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get a fully qualified domain name

843790Mar 23 2010
InetAddress.getCanonicalHostName() does not return a fully qualified domain name (FQDN) but rather a short host name.
I tried this on a Sun and linux server with Java 1.5.

nsswitch.conf has following entry
hosts: files dns

nslookup for machine "abc" returns its FQDN
$>nslookup abc
Name: abc.company.com

$>cat /etc/hosts | grep abc
x.x.x.x abc abc.company.com abc1

getCanonicalHostName returns only "abc".

When I set the system property sun.net.spi.nameservice.provider.1" to "dns,sun"
getCanonicalHostName returns a FQDN (in this case "abc.company.com")

But being a library vendor, I cannot change this JVM property or configuration files.
Is there a way I can get a FQDN

Thanks you for your help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 20 2010
Added on Mar 23 2010
0 comments
1,037 views