98

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

20 Answers 20

113

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
9
  • 2
    Or with less pipes: nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
    – ripat
    Feb 26 '14 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
    Feb 26 '14 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
    Apr 17 '14 at 11:53
  • 1
    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. Jul 8 '15 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
    Aug 10 '17 at 17:00
68

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
  • 6
    This solution is much faster than an nmap solution!
    – ryanm
    Dec 29 '15 at 3:49
  • This solution worked for me, unlike the nmap solution which gave only part of the list.
    – Wilbert
    Feb 15 '16 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. Mar 10 '16 at 0:36
  • 1
    It might, but for me this never failed. Plus it's an easy first try.
    – amenthes
    Feb 9 '18 at 10:44
  • Thanks for this. I modified it slightly and use arp -n | awk '/b8:27:eb/ {print $1}' now.
    – 0x01
    Apr 6 '18 at 12:02
12

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
    Apr 6 '18 at 12:10
8

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. Mar 26 '18 at 17:28
  • What is classfull networking?
    – Denis
    Jun 22 '19 at 10:23
7

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.

5

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.

5

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.

4

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.

4

If you run MacOS, use PiFinder, it is an application that will tell you the IP of a Raspberry Pi on your network.

3

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… :)

3

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

3

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
    Feb 18 '18 at 23:35
3

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.

3

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)

2

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

2

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 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

set raspIp=
set myip=
set subnet=

:: 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%

:: Get subnet
set subnet=%myip%
setlocal enabledelayedexpansion
for /l %%a in (1,1,31) do if NOT "!subnet:~-1!"=="." set subnet=!subnet:~0,-1!
set subnet=%subnet:~0,-1%
setlocal disabledelayedexpansion  
echo Subnet: %subnet%
echo.

:top
:: Loop through arp table entries and look for Raspberry Pi's MAC address
for /f "tokens=1" %%f  in ('arp -a ^| findstr b8-27-eb') do (set raspIp=%%f)

if "%raspIp%"=="" (
    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
    goto :top
) else (
    echo Found Raspberry PI with IP: %raspIp%
)
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.

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

2

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 pi@raspberrypi.local
1

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)

1

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: ?.

0

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.

[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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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