我需要与不懂 java 的网络管理员沟通,以解决在运行 getLocalHost() 时显示的网络设置问题。该框位于两个网络上,getLocalHost() 返回错误的网络。在我们所有其他服务器上,这不会发生。我希望能够使用命令行向网络管理员显示出问题了。但是我对 linux 网络命令不够熟悉,不知道该调用什么。
最佳答案
尝试如下hostname
命令,
hostname --all-ip-address|cut -d ' ' -f1
如果上面的方法不起作用,请按如下方式尝试 ifconfig
,
ifconfig eth0| grep 'inet addr:'|awk '{print $2}'|cut -d':' -f2
这里还有一个选项,你也可以使用ip
命令,如下所示,
ip addr show eth0|grep "eth0"|awk '{print $2}'|tail -1|cut -d'/' -f1
The
eth0
here is a system specific interface name, you have to check about your own interface on your system. Unless last two commands may not be able to help you.
关于java - 什么是 java.net.InetAddress.getLocalHost(); 的 linux 命令行等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28240857/