DEV Community

Messin
Messin

Posted on • Edited on • Originally published at circuitdigest.com

Master Your Raspberry Pi: Set a Static IP for Rock-Solid Networking

Are you tired of your Raspberry Pi's IP address changing every time you reboot? Whether you're running a home server, IoT project, or a custom dev environment, a static IP is your ticket to reliable networking. Let’s make your Pi’s network setup as stable as your coding passion!

Why Set Static IP on Raspberry Pi?

A static IP ensures your Raspberry Pi keeps the same address on your network, making it easier to:

  • Access your Pi consistently for SSH or remote desktop.
  • Run servers (like web or game servers) without IP conflicts.
  • Simplify IoT or home automation projects.

No more hunting for your Pi’s new IP after a router restart—let’s lock it down!

Step-by-Step: Setting a Static IP on Raspberry Pi

  1. Connect to Your Pi

Fire up your terminal and SSH into your Pi or use its desktop terminal. Not sure how? Check your router’s connected devices list for your Pi’s current IP.

ssh pi@

  1. Check Your Network Details

Run the following to find your current IP, gateway, and DNS servers:

ip addr
route -n
cat /etc/resolv.conf

Note your:

  • IP address (e.g., 192.168.1.100).
  • Gateway (usually your router, e.g., 192.168.1.1).
  • Subnet mask (e.g., 255.255.255.0).
  • DNS servers (from resolv.conf).
  • Edit the DHCP Configuration

Raspberry Pi OS uses dhcpcd for network configuration. Open its config file:

sudo nano /etc/dhcpcd.conf

Scroll to the bottom and add the following, replacing the values with your network details:

interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8

For Wi-Fi, replace eth0 with wlan0. The /24 denotes a subnet mask of 255.255.255.0. Add multiple DNS servers for redundancy (e.g., Google’s 8.8.8.8).

  1. Save and Reboot

Save the file (Ctrl+O, Enter, Ctrl+X) and reboot your Pi:

sudo reboot

  1. Verify the Static IP

After reboot, check if your static IP is active:

ip addr

You should see your chosen IP (e.g., 192.168.1.100) under eth0 or wlan0. Test connectivity:

ping 8.8.8.8.

Pro Tips for Raspberry Pi Networking

  • Backup First: Always back up /etc/dhcpcd.conf before editing (sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak).
  • Router Reservation: Alternatively, reserve an IP for your Pi in your router’s DHCP settings for a similar effect without touching the Pi’s config.
  • Troubleshooting: If connectivity fails, double-check your IP isn’t already in use and ensure your subnet mask and gateway are correct.

A static IP is a game-changer for developers working on Raspberry Pi projects. Whether you’re hosting a Flask app, running a Minecraft server, or building a smart home hub, a consistent IP saves time and frustration. Plus, it’s a great way to level up your Linux networking skills!

Top comments (0)