Java的。 InetAddress.getLocalHost返回奇怪的IP [英] Java. InetAddress.getLocalHost returns strange IP
本文介绍了Java的。 InetAddress.getLocalHost返回奇怪的IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白,为什么下面的代码打印0.0.9.229而不是127.0.0.1。任何人都可以告诉我,热门解决这个问题吗?
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:
在Ubuntu上运行的代码
UPD: Code running on Ubuntu
/ etc / hosts
/etc/hosts
127.0.0.1 localhost
127.0.1.1 2533
推荐答案
问题是我的主机名只包含数字而无法解析。
我在第一个位置用字符更改我的/ etc / hostname并且问题已经解决。
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.
这篇关于Java的。 InetAddress.getLocalHost返回奇怪的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文