title: Why is Java getting the cached version of the host name?
body: <p>Please refer to this question:</p>
  
  <p><a href="https://askubuntu.com/questions/758432/is-there-another-place-to-host-machine-name?noredirect=1#comment1132454_758432">https://askubuntu.com/questions/758432/is-there-another-place-to-host-machine-name?noredirect=1#comment1132454_758432</a></p>
  
  <p>As you can see, I'm using this method to get the machine name:</p>
  
  <pre><code>private InetAddress getFirstNonLoopbackAddress(boolean preferIpv4, boolean preferIPv6) throws SocketException {
      Enumeration&lt;NetworkInterface&gt; en = NetworkInterface.getNetworkInterfaces();
      while (en.hasMoreElements()) {
          NetworkInterface i = en.nextElement();
          for (Enumeration&lt;InetAddress&gt; en2 = i.getInetAddresses(); en2.hasMoreElements();) {
              InetAddress addr = en2.nextElement();
              if (!addr.isLoopbackAddress()) {
                  if (addr instanceof Inet4Address) {
                      if (preferIPv6) {
                          continue;
                      }
                      return addr;
                  }
                  if (addr instanceof Inet6Address) {
                      if (preferIpv4) {
                          continue;
                      }
                      return addr;
                  }
              }
          }
      }
      return null;
  } 
  </code></pre>
  
  <p>The caller:</p>
  
  <pre><code>InetAddress ip = getFirstNonLoopbackAddress(true, false);
  this.machineName = ip.getCanonicalHostName();
  </code></pre>
  
  <p>But the result is I'm getting the old machine name, before I change it in Ubuntu.</p>
  
  <p>How can I get the real machine/host name as in /etc/hostname file?</p>