Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
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
add comment

6 Answers

up vote 8 down vote accepted

One way would be:

ip address list
share|improve this answer
    
or just 'ip addr' –  l0c0b0x Sep 30 '09 at 21:08
add comment

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"

share|improve this answer
add comment

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.

share|improve this answer
add comment

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!

share|improve this answer
    
good to know, thanks! –  l0c0b0x Sep 30 '09 at 21:08
add comment

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

share|improve this answer
add comment

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}'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.