Search This Blog

2015-07-07

Get IP Address from Commandline in Linux

There are multiple ways to hack together fetching an IP address for each interface.

But one of the easiest ways that I've recently learned about is using the hostname command

Using:

hostname -I

OR

hostname --all-ip-addresses


Will as the man page says

Display all network addresses of the host. This option enumerates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted. Contrary to option -i, this option does not depend on name resolution. Do not make any assumptions about the order of the output.

This will not show you which interface has which IP but it will show you which IPs are configured which is useful in some scenarios.

References:
http://stackoverflow.com/questions/13322485/how-to-i-get-the-primary-ip-address-of-the-local-machine-on-linux-and-os-x
http://linux.die.net/man/1/hostname

No comments:

Post a Comment