IP addresses form the basis of communication between computers or computer networks via the Internet or in a local network. The IP address (Internet Protocol Address ) is a numeric label associated with each computer. IP addresses can be either IPv4 which are 32 bit or the newer 128-bit IPv6 addresses.
When you connect your Raspberry Pi to the Internet or on the local network, it will be assigned an IP address.
An IP address in a Raspberry Pi is important for remote access, connection via SSH, or to view web pages. A dynamic IP address is always assigned to your Raspberry Pi by your router when you access the Internet. You can assign a static IP address that will not change every time you reconnect to the Internet.
In this article, we will highlight several ways of finding out the IP address of your Raspberry Pi.
Prerequisite
- A Raspberry PI 3, 4 single-board computer.
- Network connectivity.
- MicroSD card, preferably with 32 GB capacity.
- A power supply adapter.
- A computer for remote access.
Method 1: Get IP address from Raspberry PI OS
You can use several terminal commands from your Raspberry PI OS to get its IP address. You can launch the terminal application from your desktop installation of a Raspberry PI or access it after login from a headless installation.
The “ifconfig” command in Linux distributions will give you detailed information on the network configuration.
Using the “ifconfig” terminal command.
pi@raspberrypi:~ $ ifconfig
The command above will give detailed information of the “lo” interface identity loopback interface and either the wlan0 network details for a Wi-Fi connection or eth0 for a wired connection or both wlan0 and eth0.
You can simplify the details of the output from the “ifconfig” command for either the eth0 or wlan0 network connections.
You can use the following terminal command to simplify “ifconfig” output on a (wlan0) Wi-Fi connection.
Example output on wlan0
pi@raspberrypi: ~ $ ifconfig wlan0 | grep ‘inet’ inet 192.168.0.200 netmask 255.255.255.0 broadcast 192.168.0.255
You can use the following terminal command to simplify the “ifconfig” output on an (eth0) wired connection.
Example output on eth0 pi@raspberrypi: ~ $ ifconfig eth0 | grep ‘inet’ inet 192.168.0.7 netmask 255.255.255.0 broadcast 192.168.0.255
Using the “hostname” terminal command
The “hostname -I” terminal command in Linux distributions will return the IP addresses for all hostnames.
pi@raspberry: ~ $ hostname -I
Example output using hostname -I command
pi@raspberrypi: ~ $ hostname -I 192.168.0.200
Note: You ought to make sure the I in the hostname -I command is capitalized for the command to return the IP addresses for all hostnames. A lowercase I in the “hostname -i” command will return the hostname instead of the hostname’s IP address.
Method 2: Get IP address from remote devices
Using the “ping” command to find the IP address of your Raspberry PI
You can run the ping command within the shell, terminal, or command prompt in almost every operating system
You need to open the terminal application on Linux distributions or the Command Prompt on a Windows operating system and run the “ping” command.
ping raspi
The command will ping your Raspberry Pi, and if successful, it will retrieve its IP address. However, sometimes an error might occur, and you get the following message: cannot resolve raspi: Unknown host.
When you get an error message, try the following options with the “ping” command.
ping raspberrypi OR ping raspberrypi.local
If you run RetroPie, use the following command.
ping retropie
Example output of the “ ping raspberrypi.local command.
When the command runs successfully, it will return the IP address and the following message.
ping raspberrypi.local (192.168.0.200): 56 data bytes 64 bytes from 192.168.0.200: icmp_seq=0 ttl=255 time=2.618 ms
Example error message for unsuccessful “ping raspberrypi.local” command.
You will get such an error if you have multiple Raspberry PI devices on the same network.
ping: unknown host raspberrypi.local OR ping: the request could not find host raspberrypi.local. Please check the name and try again.
If you get such an error message, you need to explore other methods to find the IP address of your Raspberry Pi.
Using Nmap network mapper to find the IP address of your Raspberry PI
A network mapper can scan your local networks to find all the connected devices within a specific subnet.
The map tool is a versatile networking tool available for installation on Windows, macOS, and Linux operating systems.
If you do not have Nmap installed in your system, then your first step is to install Nmap on your device.
Installation of Nmap
Linux
You can install Nmap in most Linux distributions such as Fedora, Raspian, or Ubuntu using their default package manager on the terminal.
sudo dnf install nmap OR sudo apt install nmap
macOS & Windows
You can install Nmap in both Windows and macOS by obtaining its installation from the Nmap download page.
The next step is to find the subnet in your local using your current local computer’s IP address. Most networks have a subnet range from 192.168.0.0 to 192.168.0.255
Retrieve local IP addresses of your current local computer
macOS
On your Mac device, go to System Preferences > Network
Then select “active network connection” and open “View status of this connection.”
Windows
On a Windows device, go to: Windows Settings > Network & Internet > Change connection properties > Properties > IPv4 address:
Linux
You can retrieve your IP address using the “hostname -I” or “ifconfig” command.
hostname -I
The next step is to determine the subnet of your local network.
You can describe the range of addresses in your subnet by replacing the last number of your IP address with 0/24.
Example
If your IP address is 192.168.0.44, the subnet range is 192.168.0.0/24.
The Nmap command
nmap -sn 192.168.0.0/24
Using Nmap command on a Unix system
sudo nmap -sn 192.168.0.0/24
The –sn flag tells the Nmap tool to ping every address on the subnet, but it will not scan open ports in the subnet.
Example output
The command will return a list of devices connected to the network.
:~$ sudo nmap -sn 192.168.0.0/24 Starting Nmap 7.01 ( https://nmap.org ) at 2021-03-22 15:39 EAT Nmap scan report for 192.168.0.1 Host is up (0.0055s latency). MAC Address: 50:0F:F5:3E:22:50 (Unknown) Nmap scan report for 192.168.0.106 Host is up (0.010s latency). MAC Address: C4:D9:87:BA:88:17 (Intel Corporate) Nmap scan report for 192.168.0.105 Host is up. MAC Address: B8:37:EB:EA: E0:D5 (Raspberry Pi Foundation) Nmap scan report for 192.168.0.200 Host is up (0.0049s latency). Nmap done: 256 IP addresses (4 hosts up) scanned in 205.26 seconds.
From our example above, the Nmap command found a Raspberry Pi device
MAC Address: B8:37:EB:EA: E0:D5 (Raspberry Pi Foundation) Nmap scan report for 192.168.0.200
The IP address for our Raspberry Pi is 192.168.0.200.
Using Arp cache to find the IP address of your Raspberry PI
You can also find the IP address of your Raspberry Pi by displaying the arp cache of your local computer.
The arp cache is a list of associated IP and mac addresses in your local network.
The “arp” terminal command on Linux or Mac
$ arp -a | grep raspberry raspberrypi.home (192.168.0.200) at b8:37:eb:ea:eo:d5
Alternative methods to find the IP address of your Raspberry PI
I recommend using network tools like Angry IP scanner, Advanced IP Scanner, or your router.
Advanced IP Scanner
Advanced IP Scanner is a tool available for Windows, and it can scan your entire network. The tool is a very intuitive networking tool and is available for download.
Angry IP Scanner
Angry IP scanner is a free networking tool available for Linux, macOS, and Windows operating systems.
Router
You can use your router to find the IP address of a Raspberry Pi on an isolated network. Most routers display all the machines connected to the network, their IP addresses, and mac addresses. This method is helpful if you have access to your router’s interface.
Recap
Through the article, we have highlighted different ways to find the IP address of your Raspberry Pi. You should note that your Raspberry Pi may have a different IP address depending on your network connection. A Raspberry Pi device may have a different IP address from a Wi-Fi or Ethernet connection. By now, you can confidently find the IP address of your Raspberry Pi.