Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

After I've booted up, what's the easiest way to obtain and display the IP address that the device is currently using?
I'm using Raspbian, and ifconfig doesn't appear to be installed.

Are there any widgets that display this information in LXDE?

share|improve this question
2  
It probably is installed; you have to sudo ifconfig on Debian. –  Alex Chamberlain Aug 2 '12 at 16:49
    
I'm realizing that now. I think I got spoiled by Ubuntu's command line hints. I'll check it out when I power it back up. –  Zoot Aug 2 '12 at 18:02
    
That's a bash thing, rather than a Ubuntu thing. I think ifconfig is just installed with different permissions. –  Alex Chamberlain Aug 2 '12 at 18:04
    
Yep, I forgot to sudo. ifconfig is installed by default, but it comes up with a command not found error if you don't sudo it. Thanks! –  Zoot Aug 3 '12 at 3:22
    
My Raspbian shows the IP-address just before the login prompt. –  Thorbjørn Ravn Andersen Aug 3 '12 at 21:49

12 Answers 12

up vote 35 down vote accepted

The if family of tools including ifconfig are being deprecated and replaced by the newer ip commands so you can use any one of the following from the command line to determine your IP address:

sudo ip addr show

or

sudo hostname --ip-address

or if you still want to use ifconfig, and it is not already installed

sudo apt-get install wireless-tools
sudo ifconfig -a
share|improve this answer
7  
+1 for the ip addr show, didn't know you could do that! –  jackweirdy Aug 2 '12 at 16:15
1  
@jackweirdy that is the newer tools that are replacing the old if tools. Try man ip for some additional details. –  Steve Robillard Aug 2 '12 at 16:17
    
cheers for that, learnt something new today :) –  jackweirdy Aug 2 '12 at 16:29
    
is ther an "arp" command that will show you something in line of IP address? –  ppumkin Aug 2 '12 at 16:31
2  
ip a is sufficient if you want to get the IP address :) –  Oliver Salzburg Aug 3 '12 at 15:58

You can use this little python script as well.

import socket

def get_local_ip_address(target):
  ipaddr = ''
  try:
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect((target, 8000))
    ipaddr = s.getsockname()[0]
    s.close()
  except:
    pass

  return ipaddr
print "Raspberry Pi - Local IP Address"
print(get_local_ip_address('10.0.1.1'))
print(get_local_ip_address('google.com'))
share|improve this answer
5  
A bit overkill don't you think? Not much point replacing the existing Linux commands that achieve the same. –  Jivings Aug 3 '12 at 7:07
    
@Jivings Bit harsh - it's an answer, that works! (I say without testing...) It could be the basis of a widget on a desktop for instance. –  Alex Chamberlain Aug 3 '12 at 7:23
    
@Bryan Welcome to Stack Exchange and Raspberry Pi! –  Alex Chamberlain Aug 3 '12 at 7:24
    
@AlexChamberlain Sorry Bryan. Hadn't had my coffee yet this morning :) –  Jivings Aug 3 '12 at 7:41
1  
This could even be added to the messages service that runs after login to automatically display the IP address along side the startx message. Then it would be automatic no typing required. –  Steve Robillard Aug 3 '12 at 11:01

You may be able to check the DHCP status/logs on your DHCP server. Especially if it's on your home network. On all the routers I have owned this has been fairly easy to find.

This is helpful if you are running headless and just want to know the address to ssh to.

share|improve this answer
    
@gnibbler +1 for addressing the issue for those running headless. One think to note, identifying which device is the Pi can be tricky since it does not always identify itself over the network, and so, may show up without a name in the attached devices list. This thread raspberrypi.org/phpBB3/viewtopic.php?f=36&t=6998 has more on the problem and solution –  Steve Robillard Aug 3 '12 at 11:07
    
@SteveRobillard, mine does identify itself, but it also may help someone if they see a MAC address starting like b8:27:eb:xx:xx:xx, it's probably a RPi :) –  John La Rooy Aug 3 '12 at 11:14

As an alternative to finding the DHCP assigned IP address, I've added a reserved IP address in my router/DHCP server. It matches the MAC address of the Raspi and always assigns the same IP address - even after a fresh install of the OS.

With Wheezy now having SSH enabled by default, it means I can login to a freshly installed Raspberry Pi without ever needing to connect a keyboard or monitor.

Apologies for not answering the question directly, but it seemed closely related enough to suggest.

share|improve this answer
    
If it helps people find easy ways to determine the IP, I'm all for it. –  Zoot Aug 7 '12 at 16:52

$ host raspberrypi –> raspberrypi has address 192.168.1.20

$ host raspberrypi | grep ‘address’ | cut -d’ ‘ -f4 –> 192.168.1.20

$ nslookup 192.168.1.20 –> Server: 192.168.1.1 –> Address: 192.168.1.1#53 –> 20.1.168.192.in-addr.arpa name = raspberrypi.

$ nslookup 192.168.1.20 | grep ‘=’ | cut -d’ ‘ -f3 –> raspberrypi.

share|improve this answer

What worked for me :

sudo ifconfig

since ifconfig was at sbin/ifconfig

share|improve this answer
    
While I appreciate your response, Alex Chamberlain's comment and Steve Robillard's response already contain this information. –  Zoot Jul 9 '13 at 12:54

If you want to see your external ip address use this on your command line

curl http://ipecho.net/plain; echo;

You could create a function to make it easier.

Edit your .bashrc and add the following function at the end of the file.

Function to display the external ip address

Function to display the external ip address

Calling your function from cli

enter image description here

You may find more interesting ways to obtain your ip address in this link

http://www.if-not-true-then-false.com/2010/linux-get-ip-address/

share|improve this answer
    
Thanks for this answer! –  dmeehan Aug 29 at 13:23

Shea Silverman and Jacob Bates have recently created a tool called PIP that allows you to obtain the IP of your raspberry pi without even attaching it to a screen, as it installs a script that send your IP address to a server that you can visit with your main PC. It may not be the best option in every situation, but it is a very clever hack.

share|improve this answer

Just to add some supplement here, the reason you might not have ifconfig is because your system is probably using the iproute2 suite instead. iproute2 includes updated equivalents of the old ifconfig and route suites.

I'm bringing this up because if you start to try commands you're used to with ifconfig or route, your first instinct might be to install those old packages instead of just using the newer equivalent. For instance, if you need to use netstat and realize it's missing, just do a search for "iproute2 netstat equivalent" and you should find the "ss" command. For further reading and documentation, refer to the Linux Foundation's article on it: http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2

share|improve this answer
1  
I appreciate your answer, but I did have ifconfig installed. I just forgot to sudo before the command. Check out the comments below the answer. –  Zoot Apr 16 '13 at 18:20
1  
Doh! I only use Arch and it hasn't used ifconfig for awhile. –  codey Apr 18 '13 at 3:02
    
No problem. It threw me for a loop, too. –  Zoot Apr 19 '13 at 20:00

I suggest that you use Bonjour instead of having to find the IP address. Let it be assigned via DHCP and as long as your PC is on the same network you can access it by name.

For example.. raspberrypi.local

Once this is setup you can run completely headless, connect to the Pi with SSH, or VNC etc..

Here is an article explaining how to setup for Bonjour. http://www.raspberrypi.org/forums/viewtopic.php?f=66&t=18207

Note that for a windows machine you will need to install Apply Bonjour printer services driver, a tiny thing...

For Mac and Ubuntu, Bonjour is already there.

share|improve this answer

Baby script to return the ip address, works from a prompt:

ip address list | grep inet | grep -v 127.0.0 | cut -d " " -f 6 | cut -d "/" -f 1

share|improve this answer

I don't know about LXDE. To know your IP address of your device visit the site Ip-Details.com . Here they will also provide IP location, ISP address, country etc...

share|improve this answer
3  
This will only provide an external IP, not your internal IP. –  Zoot Jul 9 '13 at 12:54

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.