0

when I write following code in cmd:

ping localhost

I see following result:

Pinging hostname.A.B.com [::1] with 32 bytes of data:
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms

When I write

InetAddress.getLocalHost().getCanonicalHostName();

it returns only hostname

How can I achieve to return hostname.A.B.com from java code ?

P.S.

It is not duplicate. I use code from top answer but I don't achieve desired result.

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

0

In your case, you grab the localhost address InetAddress.getLocalHost() so if you haven't put your fully qualified name for your host, you only get the hostname. In linux (and probably OS X and other UNIX system), you need to add your qualified hostname to /etc/hosts to your localhost entry for this to work.

Andy
  • 2,469
  • 1
  • 25
  • 25