I'm curious and I want to know all different methods for getting the IP address from a Linux box, I know ifconfig
works well, but wondering if there are any other methods to use to obtain the ip address?
Asked
Active
Viewed 420 times
2

Elitmiar
- 775
- 3
- 15
- 31
-
1ifconfig is actually deprecated, and is replaced with the "ip" command. However many people (myself included) haven't quite got to grips with "ip" yet! – Coops Sep 30 '09 at 12:49
6 Answers
4
To find the external IP of a box (behind a NAT firewall for instance) try this one-liner:
curl icanhazip.com
So useful and so quick!

Coops
- 6,055
- 1
- 34
- 54
3
The ip tool is quite handy and can give you a bunch of methods for IP address determination and much more.
Quick exmaples:
ip addr show dev wlan0
ip route list | grep -w src | awk '{print "device:",$3, "address:",$9}'

PrecariousJimi
- 1,552
- 9
- 16
2
I've used
hostname -i
But honestly I shouldn't because this relies on the /etc/hosts file of the machine and not the actual IP address.

Dennis Williamson
- 62,149
- 16
- 116
- 151

Dave Drager
- 8,375
- 29
- 45
0
The following command will list all IP addresses
ip addr show
The output from ifconfig does not always show secondary addresses on interfaces which do not have a named alias, such as those added by "ip addr add"

MarkR
- 2,928
- 17
- 13