2

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?

Elitmiar
  • 775
  • 3
  • 15
  • 31
  • 1
    ifconfig 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 Answers6

8

One way would be:

ip address list
Node
  • 1,644
  • 1
  • 13
  • 15
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
1

You can use ping if you know the network interface. (eth0, eth1, wlan0, etc.)

ping -I eth0 www.google.com
ping [-I interface]

from 10.1.1.4

alt text

Jindrich
  • 4,968
  • 8
  • 30
  • 42
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