title: Fully qualified machine name Java with /etc/hosts
body: <p>I am trying get the fully qualified name of my machine (Windows 7 x64) in Java. On my machine, I've updated the c:\Windows\system32\drivers\etc\hosts file such that it has an entry like this:</p>
  
  <pre><code>10.44.2.167 myserver myserver.domain.com
  </code></pre>
  
  <p>All our systems have an entry in the \etc\hosts file (in the above format) which I cannot change.</p>
  
  <p>The following code always returns "myserver" and I am never able to get the fully qualified name.</p>
  
  <pre><code>InetAddress addr = InetAddress.getLocalHost();
  String fqName = addr.getCanonicalHostName();
  </code></pre>
  
  <p>How do I achieve this in Java?</p>
  
  <p>Thanks,</p>
  
  <p>Shreyas</p>