Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save helloromero/5a2ba205a53e94a183f8a96f5679a839 to your computer and use it in GitHub Desktop.

Select an option

Save helloromero/5a2ba205a53e94a183f8a96f5679a839 to your computer and use it in GitHub Desktop.
πŸš€ Raspberry Pi Zero 2 W – Headless Setup Guide (with Static IP) and Pi Hole

Raspberry Pi OS SSH Ready

A quick and clean guide to set up your Raspberry Pi Zero 2 W headlessly with Wi-Fi, SSH, and a static IP – perfect for IoT and embedded projects.


🧰 Requirements

  • Raspberry Pi Zero 2 W
  • microSD card (β‰₯8GB)
  • Card reader
  • Computer with internet access
  • Wi-Fi credentials
  • Optional: your SSH public key

πŸ“₯ Step 1 – Download & Launch Pi Imager


βš™οΈ Step 2 – Configure and Flash OS

  • Choose device: Raspberry Pi Zero 2 W
  • Choose OS: Raspberry Pi OS Lite (64-bit)
  • Choose storage: your microSD card

Then click on βš™οΈ Advanced options (Ctrl + Shift + X) and set:

  • βœ… Hostname (e.g. rpi-zero)
  • βœ… Username & Password
  • βœ… Wi-Fi SSID & password
  • βœ… Enable SSH
    • You can also generate a key pair
    • Paste your public SSH key
  • Click Save and then Write

Once completed: SD card is ready to boot.


πŸ”Œ Step 3 – Boot the Pi

  • Insert the SD card
  • Plug in the Pi
  • Wait 1–2 minutes

πŸ” Step 4 – Connect via SSH

ssh your-username@your-pi-ip-address
# or (if your router supports mDNS)
ssh [email protected]

πŸ“¦ Step 5 – Update the System

sudo apt update && sudo apt full-upgrade -y
sudo apt autoremove -y
sudo apt clean

🌐 Step 6 – Set a Static IP

  1. Launch the network manager UI:

    sudo nmtui
  2. Then:

    • Choose Edit a connection
    • Select your Wi-Fi interface
    • Go to IPv4 Configuration
    • Change method to Manual
    • Fill in:
      • Address: (e.g. 192.168.1.42/24)
      • Gateway: your router (e.g. 192.168.1.1)
    • Save and exit
  3. Reboot:

    sudo reboot

🧱 Install Pi-hole (Network-wide Ad Blocker)

Pi-hole is a powerful network-wide ad blocker – perfect for a headless Raspberry Pi setup!

  1. Connect to your Pi:

    ssh your-username@your-pi-ip-address
  2. Run the official installer:

     curl -sSL https://install.pi-hole.net | bash
  3. Follow the installer steps:

    • Choose the correct network interface (usually wlan0)
    • Enter upstream DNS providers (Cloudflare, Quad9, etc.)
    • Confirm static IP configuration
    • Note the web interface address (e.g. http://192.168.1.42/admin)
  4. Once installed, access the web UI:

    http://your-pi-ip/admin
    
  5. Change the admin password if needed:

    pihole -a -p

πŸ’‘ You can now set your router or devices to use your Pi’s IP as their primary DNS server.


βœ… You're Good to Go!

Your Pi now:

  • Boots without screen or keyboard
  • Connects to Wi-Fi on startup
  • Allows SSH login (with password or key)
  • Uses a static IP on your network

πŸ› οΈ Ready for your next project?

You can now:

  • Host lightweight apps
  • Run sensors or automations
  • Create a custom NAS, VPN, or local server
  • Or just have fun tinkering!

Happy Hacking! πŸ€–πŸ”§

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment