117

I need to find the Raspberry PI IP address on local network without connect the Raspberry to a monitor. How do I do it on Linux or Mac OS systems?

2

19 Answers 19

126

All raspberry devices MAC addresses started with B8:27:EB (for RPi4 B they start with dc:a6:32, replace where appropriate).

So, on *nix systems, this can be accomplished by executing the following command:

nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'

where 192.168.1.* will be your local network mask. You will get an answer like:

Nmap scan report for raspberrypi.localnetwork.lan (192.168.1.179)

The 192.168.1.179 is the Raspberry Pi IP address on you network.

If you are on a Mac system you can use Homebrew to install nmap:

brew install nmap

On Windows, you might use Wireshark and use the following display filter:

eth.addr[0:3] == B8:27:EB
13
  • 2
    Or with less pipes: nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
    – ripat
    Commented Feb 26, 2014 at 12:08
  • 2
    Thanks @ripat, that is a lot more concise - updated! One little detail, you need to run as administrator or the nmap will not display the MAC address.
    – J. Costa
    Commented Feb 26, 2014 at 15:13
  • 4
    You would not appreciate the importance of this answer until you have tried to headlessly locate your raspberrypi in an office setting where IP's are dished out using DHCP. Cheers for this @ripat
    – Ransom
    Commented Apr 17, 2014 at 11:53
  • 3
    This answer didn't work for me since nmap wasn't spitting out the hostnames for me. However, it did inspire me to search for open ssh ports with nmap and that did enable me to find the pi: sudo nmap -p 22 --open -sV 192.168.0.0/24 per this guy's post. Commented Jul 8, 2015 at 17:06
  • 1
    An improvement to automatically grab default IP and subnet mask, and also display hostname and MAC in addition to IP: sudo nmap -sP `ip -o -f inet addr show | grep \`ip route get 1 | awk '{print $NF;exit}'\` | awk '{print $4}'` | awk '/^Nmap/{ip=gensub(/[^0-9\.]/,"","g", $NF);host=$(NF-1)}/B8:27:EB/{printf "%s\t%s\t%s\n", ip, $3, host}'
    – gregmac
    Commented Aug 10, 2017 at 17:00
87

If you're running MacOS or Linux, try this one:

$ arp -na | grep -i b8:27:eb

On windows, you can use:

arp -a | findstr b8-27-eb

On RPi 4B, you need to use different string for comparision (dc:a6:32:be:95). You can check it on your RPi by

ip -br link

There will be entries for each network card. eth0 is cable internet, wlan0 is the WiFi.

6
  • 7
    This solution is much faster than an nmap solution!
    – ryanm
    Commented Dec 29, 2015 at 3:49
  • This solution worked for me, unlike the nmap solution which gave only part of the list.
    – Wilbert
    Commented Feb 15, 2016 at 7:42
  • 11
    This will only show hosts which have made it into your arp tables, so sometimes misses the quiet ones. It might help to do an nmap scan once first. Commented Mar 10, 2016 at 0:36
  • 1
    It might, but for me this never failed. Plus it's an easy first try.
    – amenthes
    Commented Feb 9, 2018 at 10:44
  • Thanks for this. I modified it slightly and use arp -n | awk '/b8:27:eb/ {print $1}' now.
    – 0x01
    Commented Apr 6, 2018 at 12:02
15

I use mDNS/Bonjour to give my Pi a local name like pi.local. I dont need to know it's IP address and this works for shortcuts and when you need to embed a link...

How and Why to assign a local name to your Pi

1
  • Awesome! I used to fiddle around with /etc/hosts locally to get this functionality on my desktop, this is a MUCH better solution! Thanks so much for the pointer!
    – 0x01
    Commented Apr 6, 2018 at 12:10
12

By default the raspberry's name is raspberrypi. You can just 'ping raspberrypi' and the ICMP echo reply gives you the IP address. It worked for me. Make sure though the DHCP server is reachable as the raspberry's NIC is by default in DHCP client mode. Otherwise the raspberry gets an APIPA address.

2
  • trying to figure out how and by what service "raspberrypi" is resolved to an IP? As it is not in my host file, nor my dns?... Commented Jan 9, 2022 at 21:18
  • 1
    I guess this only works if you already have a shell on the Raspberry Pi, which is not what was asked.
    – ayke
    Commented Jan 2, 2023 at 21:54
10

If you want to use a GUI application for it, you can use Yakala tool (https://github.com/mozcelikors/yakala) for Debian/Ubuntu. This tool helps you not only search for available Type B and Type C networks, but also helps you to directly SSH into the network:

sudo add-apt-repository ppa:mozcelikors/yakala
sudo apt-get update
sudo apt-get install yakala

or

git clone https://github.com/mozcelikors/yakala
cd yakala && sudo ./install.sh

https://raw.githubusercontent.com/mozcelikors/yakala/master/docs/img/peekx2.gif

Disclaimer: I am the creator of Yakala. Any suggestions/bugs are taken very seriously.

2
  • 1
    Classful networking was abandoned in 1993, which is a very long time ago. Commented Mar 26, 2018 at 17:28
  • What is classfull networking?
    – Denis
    Commented Jun 22, 2019 at 10:23
10

I use the free Fing app in my android smartphone. It scans the network and shows the connected devices by type, including Raspberry Pi, as well as scanning available ports. Handy to see if SSH, web or VNC are enabled and running.

9

In 2020, the accepted answer does not work anymore because the Raspberry Pi ships with a different range of MAC addresses. I could just add the "new" MAC as a comment, but the string could change again and again each model. Here is something that's more future-proof.

$ sudo nmap -sP 192.168.150.0/24 |grep 'Raspberry Pi Trading' -B2
Nmap scan report for pi4-01.lan (192.168.150.186)
Host is up (0.037s latency).
MAC Address: DC:A6:32:1B:35:6A (Raspberry Pi Trading)

The main difference above: we don't assume a MAC pattern, we just grep for the (summary), as this label is provided by nmap itself. Because nmap is continually updated, it contains internal tables of Raspberry Pi MAC addresses (or uses other criteria to detect) and we can assume that will continue working.

CAVEAT: If your scan does not identify all Pis you know are on the network, then repeat the scan -- up to 10 times. A Pi which has networking Power Management:on might not always respond to a scan.

Power Management may be a problem for you if you are scanning for multiple Pis on a LAN, as repeat scans might detect one Pi but not another. In that case, repeat the scans look for differences. (To confirm if a Pi has Power Management enabled, ssh to the Pi and run: /sbin/iwconfig wlan0|grep Management)

7

In linux and MAC, you can also type in "arp - a" in the terminal and you can get a list of connected devices, look for the one with B8 in it, example: 192.168.4.5 @ B8... will be the raspberry pi IP.

6

Or you could access to your Router via browser and find your android device -almost every router GUI has a service where you can check all devices that are currently connected to your network.

5

Copy the following into your Terminal/Console/Shell:

for i in $(jot - 1 254); do ping -t 1 192.168.1.$i && arp -a | cut -f 2,4 -d " " | tr [:lower:] [:upper:] | grep B8:27:EB; done

Please adapt 192.168.1. to your individual network.

The output will look something like this:

(192.168.1.109) B8:27:EE:DD:CC:A

192.168.1.109 would be your Raspberry Pi's IP… :)

5

Put this in pi.php on your web server:

<?php
$fp = fopen('pi', 'w');
fwrite($fp, $_REQUEST['ip'],1000);
fclose($fp);
?>

You may have to create the file pi on your web server with write permissions for your web server.

Put

curl http://yourwebserver/pi.php -d ip=`hostname -I`

in /etc/rc.local on your pi.

Get the IP of your pi by browsing http://yourwebserver/pi

5

When using a fresh install of NOOBS or Raspbian, the default hostname is "raspberrypi" and in some network configurations (i.e. if mDNS is in use and configured) you could use "raspberrypi.local". Another option is to run arp -a and look for raspberrypi

NOTE: This won't work for every instance.

1
  • That answer seems to mix up several things: different IP versions, DNS, and maybe mDNS. Whether .local can be used usually doesn't depend on IPv6, and also not on having a router present. When mDNS support is available then pi-name.local resolves, IPv6 or not. Some home routers also use .local as their local DNS domain, again this is independent of IPv6 and depends on the router model. Some home routers use different domains, such as pi-name.fritz.box.
    – TheDiveO
    Commented Feb 18, 2018 at 23:35
5

My router assigns newly discovered systems an ip-address starting at 192.168.1.2, sequentially. I went through every system in my home one day and reserved addresses for them.

That way when I create a new system, chances are that its ip-address will be 192.169.1.18.

Another way to use the serial console. You can use a serial terminal program in order to log into your raspberry pi. I would suggest using the 8N1 (8-bits, no parity bit, 1 stop bit) setting with a speed (baud rate) of 115,200. You'll need a USB to serial (3V3) connector.

4

'Fing' or 'Net Analyzer' on Android. Shows your whole network.

4

Raspbian is using a thing called mDNS, which allows you to access your raspberry pi by a hostname raspberrypi.local.

So, you don't need to search for an IP address anymore, just connect like so:

ssh [email protected]
4

If you are on Windows I suggest you to try out this script. It is mostly based on the "arp -a" command, but it saves you some extra digging and helps you when your Raspberry Pi is not already in the Arp table.

Create a text file with the following content and rename it as find_raspberry_pi.bat

@echo off
:: This script, run from a Windows (10) machine, finds a Raspberry Pi on local network

:: You can manually set subnet if needed
:: E.g.
::SET subnet=192.168.56
SET subnet=

:: --- No need to edit below this line ---

SET raspIp=
SET myip=

:: Get IP for local PC
FOR /f "tokens=1-2 delims=:" %%a IN ('ipconfig^|find "IPv4"') DO SET myip=%%b
SET myip=%myip:~1%
echo IP for local PC: %myip%

:: Retrieve subnet if not manually set
IF "%subnet%" == "" (
    SETLOCAL EnableDelayedExpansion
    SET subnet=%myip%
    FOR /l %%a IN (1,1,31) DO IF NOT "!subnet:~-1!"=="." SET subnet=!subnet:~0,-1!
    SET subnet=!subnet:~0,-1!
    SETLOCAL DisableDelayedExpansion
)

:: Show subnet
echo Subnet: %subnet%
echo.

:: Loop through arp table entries and look for Raspberry Pis MAC addresses
echo Discovering network...
:: Ping all IPs in subnet from 1 to 254
FOR /L %%N IN (1,1,254) DO start /b ping -n 1 -w 200 %subnet%.%%N >nul
timeout 1 >nul
FOR /f "tokens=1" %%f  IN ('arp -a ^| findstr "28-cd-c1 b8-27-eb e4-5f-01 dc-26-32"') DO (
    IF NOT "%%f"=="" echo Found Raspberry Pi having IP %%f
)
echo.
pause

Disclaimers:

  1. I am not the author of the original script, I just adapted it a little bit to work with a Raspberry Pi. Sadly, I cannot find the original contributor.
  2. It's not bullet-proof, it will not work if the subnet it starts scanning is not the correct one if you want to scan a different subnet you need to manually edit the appropriate line at the beginning of the script.

Still, I used it many times and it's a simple solution.

UPDATE 2022:

I updated this script. Now:

  • it can find multiple Raspberry Pis at once
  • it can find allegedly all types of Raspberry Pis (3, 4, etc.)
  • you can manually force a specific subnet if the autorecognize feature finds the wrong one

find all pis

3

Try this first:

arp -a | grep -E --ignore-case 'b8:27:eb|dc:a6:32'

The two hex strings (b8:27:eb|dc:a6:32) in this command reflect the two OUI values used by "The Foundation" for production of all RPi devices - through RPi ver 4B as of this writing. If your RPi isn't in your arp cache this command won't yield anything useful. If that's the case, then create the following file in your favorite editor, and save/write it as pingpong.sh:

#!/bin/sh

: ${1?"Usage: $0 ip subnet to scan. eg '192.168.1.'"}

subnet=$1
for addr in `seq 0 1 255 `; do
( ping -c 3 -t 5 $subnet$addr > /dev/null ) &
done
arp -a | grep -E --ignore-case 'b8:27:eb|dc:a6:32'

make it executable, and run it (use your network address here, not necessarily 192.168.1.):

$ chmod 755 pingpong.sh
$ ./pingpong.sh 192.168.1. 

Your results may appear as follows:

raspberrypi3b.local (192.168.1.131) at b8:27:eb:1:2:3 on en0 ifscope [ethernet]
raspberrypi4b.local (192.168.1.184) at dc:a6:32:2:3:4 on en0 ifscope [ethernet]

In this case, the hostname appears courtesy of mDNS. If you don't have/don't use mDNS/avahi/etc the hostname will be replaced by the character: ?.

1
  • This works great, thank you for sharing, For me, however, on an M1, arp is not able to obtain any of the hostnames, I think it could be because /etc/resolv.conf is not used in my system ( not sure if that's just M1s or all MACs )
    – mim
    Commented Dec 27, 2021 at 18:59
2

I assume you cannot connect to you PI, otherwise you'd know its IP.

If you go to your router page (usually something like 192.168.1.1 in your browser) there you should have a section with the already connected devices. You can try to plug and unplug the PI (and one device should appear / dissapear from the list)

2

I wrote myself a bash script to find my OctoPi a while ago. You can change the systype="Raspberry Pi" to whatever type of device you are looking for. It finds the subnet itself so you need not guess 192.168.1.0 or whatever. There are now 3 different OUI ranges for the Pi Foundation: https://udger.com/resources/mac-address-vendor-detail?name=raspberry_pi_foundation

B8:27:EB:xx:xx:xx   B8-27-EB-xx-xx-xx   B827.EBxx.xxxx
DC:A6:32:xx:xx:xx   DC-A6-32-xx-xx-xx   DCA6.32xx.xxxx 
E4:5F:01:xx:xx:xx   E4-5F-01-xx-xx-xx   E45F.01xx.xxxx 

So the ping grep answers need to add those

[andy@localhost ~]$ sudo ./findpi.sh

Searching 192.168.68.0/24 for Raspberry Pi systems
My address is wlp0s20f3:192.168.68.128

Found 1 Raspberry Pi system 
    Raspberry Pi system found at 192.168.68.124

I fixed it up a little and here it is:

#!/bin/bash
#-----------------------------------------------------------------#
#  Find PI bash script 
#   Andy Richter  
#   05/19/2021  I really wrote it in 2019 when I got my printer
#  This script will search the local subnet for Raspberry Pi systems  
#  The script requires root access for nmap
#
#   There are no parms we find things for ourselves
#------------------------------------------------------------------#
systype="Raspberry Pi"
#systype=Unknown
me=$(readlink --canonicalize --no-newline $0)
if [ "$EUID" -ne 0 ]
  then echo >&2 "Please run as root or use sudo $me"
  exit
else 
  if ! command -v nmap &> /dev/null
    then
       echo "nmap not found on this system. Please install. exiting"
       exit
  fi
fi
# awk doesn't like variables between /.../ 
awkstr="/^Nmap/{ipaddress=\$NF}/$systype/{print ipaddress}"
 
# Use ip route to get the active rout to the internet, IP address and interface 
#  Then use that interface to find the subnet 
myrout=`ip route get 8.8.8.8`
myaddr=`echo $myrout | grep src| sed 's/.*src \(.* \)/\1/g'|cut -f1 -d ' '`
mydev=`echo $myrout | grep dev| sed 's/.*dev \(.* \)/\1/g'|cut -f1 -d ' '`
# now get our subnet
mynet=`ip -o -f inet addr show $mydev | awk '/scope global/{sub(/[^.]+\//,"0/",$4);print $4}'`

printf "\nSearching $mynet for $systype systems\nMy address is $mydev:$myaddr\n"

# Use nmap to find PI systems. 'Raspberry Pi' is found in NMAP for PI systems
foundSys=`sudo nmap -sP $mynet | awk "$awkstr"`
foundPI=`echo $foundSys`
numpi=`echo "$foundPI" | awk '{print NF}'`
s=$([[ ($numpi == 1) ]] && echo " " || echo "s")
# Now we know, print the list if any

printf "\nFound $numpi $systype system$s\n"
for ipaddr in $foundPI
   do
     printf "\t$systype system found at $ipaddr\n"
   done

exit 0

Nmap output looks like:

Starting Nmap 7.70 ( https://nmap.org ) at 2021-05-01 15:57 EDT
Nmap scan report for 192.168.68.124
Host is up (0.021s latency).
MAC Address: B8:27:EB:58:CA:8F (Raspberry Pi Foundation)

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