Search code examples
javaiplocalhosthostinetaddress

Java. InetAddress.getLocalHost returns strange IP


I'm don't understand, why code below prints 0.0.9.229 instead 127.0.0.1. Can anybody tell me, hot to fix that?

String ha = InetAddress.getLocalHost().getHostAddress();
System.out.println(ha);

UPD: Code running on Ubuntu

/etc/hosts

127.0.0.1       localhost
127.0.1.1       2533

Solution

  • The problem is that my hostname will consists only of numbers and could not be resolved. I change my /etc/hostname with characters at first position and problem has solved.