Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is linux command line equivalent of java.net.InetAddress.getLocalHost();

I need to communicate with Network Admin, who doesn't know java, to fix a network setup issue that is revealed when getLocalHost() runs. The box is on two networks and getLocalHost() returns the wrong one. On all of our other servers, this does not happen. I want to be able to show the Network Admin using the command line, that something is wrong. But I'm not familiar enough with the linux network commands to know what to call.

like image 781
Steve Cohen Avatar asked Oct 19 '22 18:10

Steve Cohen


1 Answers

Try hostname command as follows,

hostname --all-ip-address|cut -d ' ' -f1

If above one not working try ifconfig as follows,

ifconfig eth0| grep 'inet addr:'|awk '{print $2}'|cut -d':' -f2

Here is also an other option, you can use ip command as follows also,

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.

like image 52
Skynet Avatar answered Oct 29 '22 16:10

Skynet