The fastest way to get the IP address of a Raspberry Pi connected to your network is to run hostname -I in the terminal, or ping raspberrypi.local from another machine using mDNS. If you are completely headless and locked out, scan your subnet with nmap or check your router's DHCP lease table. Below, we break down every method from quick CLI checks to automated Python scripts, specifically updated for the NetworkManager architecture in Raspberry Pi OS Bookworm.

Quick-Reference: 5 Ways to Find Your Raspberry Pi's IP Address

Depending on whether you have a monitor attached, SSH access, or are entirely locked out, choose the method that matches your current access level. This table covers the primary techniques used on the bench.

Method Command / Action Prerequisite Best For
Local CLI hostname -I or ip -4 addr show Direct terminal or active SSH session Quick checks when already logged in
mDNS Ping ping raspberrypi.local Avahi daemon running on Pi; mDNS support on host OS Headless setups on the same local subnet
Network Scan nmap -sn 192.168.1.0/24 Nmap installed on host machine; Pi powered on Finding a Pi with an unknown or changed hostname
Router Admin Check DHCP Client List / ARP Table Admin access to your router's web UI When CLI tools fail or Pi is on a different VLAN
Python Auto-Report Custom socket script via MQTT/Email Python script running on boot (systemd) Remote IoT deployments where IP changes frequently

Hardware & Software Bill of Materials

The code and commands in this guide target the Raspberry Pi 5 (8GB) and Raspberry Pi Zero 2 W running Raspberry Pi OS Bookworm. Bookworm introduces a major shift: it replaces dhcpcd with NetworkManager, meaning older tutorials telling you to edit /etc/dhcpcd.conf will fail. We also use the RP1-compatible gpiozero library instead of the deprecated RPi.GPIO.

Core Components:

  • Raspberry Pi 5 (8GB) or Pi Zero 2 W
  • 64GB MicroSD Card (A2 rating for fast OS boot)
  • Official 27W USB-C PD Power Supply (Pi 5) or 5V/2.5A (Zero 2 W)
  • 5mm Green LED and 330Ω through-hole resistor (for network status indication)

Status LED Pin Mapping

To visually confirm your Pi has grabbed an IP address without needing a monitor, wire a status LED to GPIO 17. The Python script below will pulse this LED when an IP is successfully acquired.

Pi Pin (Physical) GPIO (BCM) Component Wiring Note
Pin 11 GPIO 17 330Ω Resistor Connect to LED Anode (long leg)
Pin 9 GND LED Cathode Connect to LED Cathode (short leg)

The Headless CLI Methods (Local & Remote)

If you have SSH access, finding your IP is trivial. Run hostname -I (capital 'i'). This returns all assigned IPv4 addresses separated by spaces. If you are using Ethernet and WiFi simultaneously, you'll see two IPs. To isolate a specific interface, use the iproute2 suite:

# Get IP for Ethernet only
ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

# Get IP for WiFi only
ip -4 addr show wlan0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

Remote Host Scanning: If you don't know the IP and mDNS (.local) is failing on your Windows host, use Nmap to scan your subnet. Assuming your host machine is on 192.168.1.15, scan the /24 range:

nmap -sn 192.168.1.0/24

Look for the MAC address vendor label "Raspberry Pi Foundation" in the output to identify the correct device.

Network Debugging: When the Pi Won't Connect

When you cannot reach the Pi, don't just reboot it blindly. Here are the first three things to check when a headless Pi drops off the network:

  1. Physical Link & Power: Check the Ethernet port LEDs or verify your power supply. A voltage drop below 4.8V under load causes the Pi 5's RP1 chip to brownout the WiFi/Ethernet MAC layers, dropping the connection while keeping the CPU alive.
  2. NetworkManager Profile State: In Bookworm, WiFi profiles are managed by NetworkManager. If a profile is set to autoconnect no, it won't connect on reboot. Verify via UART console with nmcli connection show.
  3. DHCP Server Availability: If your router's DHCP pool is exhausted, the Pi will self-assign an APIPA address (169.254.x.x), making it unreachable from standard subnets.

Common Error Strings and Fixes

If you are plugged into a serial console or monitor and see these errors, here is the ranked resolution path:

Error: Network is unreachable
Cause: The interface is administratively down, or no default gateway is assigned.
Fix: Bring the interface up manually: sudo ip link set wlan0 up, then request a lease: sudo dhclient wlan0.
Error: Temporary failure in name resolution
Cause: You have an IP address, but DNS is broken. You are pinging a domain (like google.com) instead of an IP.
Fix: Check /etc/resolv.conf. If it's empty, force a DNS server via NetworkManager: sudo nmcli con mod "MyWiFi" ipv4.dns "8.8.8.8" and restart the connection.

Automated IP Reporting via Python

For remote IoT deployments (like a Pi Zero 2 W monitoring a greenhouse on a cellular hotspot), the IP address changes every time the modem reconnects. Instead of relying on port forwarding or dynamic DNS, we can write a Python script that fetches the local IP and blinks our GPIO status LED to confirm network readiness.

Note: This code targets Raspberry Pi OS Bookworm and uses gpiozero, which is pre-installed and fully compatible with the Pi 5's RP1 I/O controller.

import socket
import time
import logging
from gpiozero import LED
from signal import pause

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

# Pin Definitions (BCM numbering)
STATUS_LED_PIN = 17
status_led = LED(STATUS_LED_PIN)

def get_local_ip():
    """
    Fetches the primary local IP address by opening a dummy UDP socket.
    This avoids binding to 127.0.0.1 and gets the actual routed interface IP.
    """
    try:
        # Connect to a public DNS (doesn't actually send data)
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.settimeout(2)
        s.connect(("8.8.8.8", 80))
        ip_address = s.getsockname()[0]
        s.close()
        return ip_address
    except socket.error as e:
        logging.error(f"Socket error while fetching IP: {e}")
        return None
    except Exception as e:
        logging.error(f"Unexpected error: {e}")
        return None

def indicate_network_status(is_connected):
    """Blinks LED rapidly if connected, holds solid if disconnected."""
    if is_connected:
        status_led.blink(on_time=0.2, off_time=0.2, background=True)
        logging.info("Network UP: LED pulsing.")
    else:
        status_led.on()
        logging.warning("Network DOWN: LED solid.")

if __name__ == "__main__":
    logging.info(f"Starting IP Monitor on GPIO {STATUS_LED_PIN}...")
    
    while True:
        try:
            current_ip = get_local_ip()
            if current_ip and not current_ip.startswith("127."):
                logging.info(f"Current IP Address: {current_ip}")
                indicate_network_status(True)
                # Here you could add MQTT publish or HTTP POST to your server
            else:
                logging.warning("No valid external IP detected.")
                indicate_network_status(False)
            
            time.sleep(30) # Check every 30 seconds
            
        except KeyboardInterrupt:
            logging.info("Monitor stopped by user.")
            status_led.off()
            break
        except Exception as e:
            logging.critical(f"Main loop crashed: {e}")
            status_led.off()
            time.sleep(10)

Extending and Simplifying the Build

Depending on your project phase, you either want to simplify how you connect (so you don't need to look up the IP at all) or extend the build for permanent deployment.

Simplify: Rely on mDNS (.local)

Raspberry Pi OS ships with the Avahi daemon enabled by default. This broadcasts the hostname over Multicast DNS. Instead of finding the IP, simply SSH using the hostname:

ssh pi@raspberrypi.local

Troubleshooting tip: If this fails on Windows, ensure the "Bonjour Print Services" or "mDNS Responder" is running, or simply use Windows 10/11's built-in OpenSSH client which usually handles mDNS natively if the network router allows multicast traffic.

Extend: Assign a Static IP via NetworkManager

For permanent installations (like a Pi running Home Assistant or a 3D printer OctoPrint server), DHCP leases can expire and change, breaking your port forwards or local DNS. Because Bookworm uses NetworkManager, do not edit /etc/dhcpcd.conf. Use the nmcli command-line tool instead.

To set a static IP of 192.168.1.50 on your Ethernet connection (usually named eth0 or Wired connection 1):

# 1. Find your exact connection name
nmcli connection show

# 2. Modify the connection to use manual IP assignment
sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.50/24
sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1
sudo nmcli con mod "Wired connection 1" ipv4.dns "1.1.1.1,8.8.8.8"
sudo nmcli con mod "Wired connection 1" ipv4.method manual

# 3. Apply the changes
sudo nmcli con up "Wired connection 1"

This writes the configuration directly to NetworkManager's persistent storage in /etc/NetworkManager/system-connections/, surviving reboots and OS upgrades without the risk of legacy config file overwrites.