A Step-by-Step Guide for Setting Up a Static IP on Raspberry Pi using Raspbian OS

Learn how to set up a static IP address on your Raspberry Pi with the Raspbian operating system. …


Updated September 5, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to set up a static IP address on your Raspberry Pi with the Raspbian operating system.

  1. Access the command line interface (CLI) on your Raspberry Pi:

    • Connect to your Raspberry Pi via an HDMI monitor and keyboard or SSH into it if you’re using headless setup.
    • Open a terminal window by clicking on the menu icon in the top left corner, then selecting “Terminal”.
  2. Check your current IP address:

    • To verify that your Raspberry Pi is currently using DHCP (Dynamic Host Configuration Protocol) for IP address assignment, run the following command:
      sudo nmap -sL 255.255.255.255
      
    • This will display a list of all devices on your network along with their assigned IP addresses. Find your Raspberry Pi in the list and note its current IP address. For example, let’s say your current IP is 192.168.1.100.
  3. Edit the network configuration file:

    • Open the network configuration file using a text editor by running the following command:
      sudo nano /etc/dhcpcd.conf
      
    • This will open the dhcpcd.conf file in the Nano text editor.
  4. Add your static IP address information:

    • At the bottom of the file, add the following lines to configure a static IP address for your Raspberry Pi’s eth0 interface (replace “192.168.1.x” and “255.255.255.0” with your desired IP address and netmask values):
      interface eth0
          static ip_address=192.168.1.x/24
          static routers=192.168.1.1
          static domain_name_servers=8.8.8.8.8 8.8.4.4
      
    • In this example, we’re setting the IP address to 192.168.1.x, subnet mask to 255.255.255.0, gateway (router) to 192.168.1.1, and using Google’s public DNS servers (8.8.8.8.8 and 8.8.4.4).
  5. Save the changes:

    • Press “Ctrl + X” to exit Nano, then press “Y” to save the changes.
  6. Restart the networking service:

    • Run the following command to restart the networking service and apply the new settings:
      sudo systemctl restart dhcpcd
      
  7. Verify your static IP address:

    • To check if your Raspberry Pi has received the static IP address you assigned, run the following command:
      ip addr show eth0 | grep "inet"
      
    • This should display your new static IP address in the format “inet 192.168.1.x/24 brd 192.168.1.255 scope global dynamic eth0”.

That’s it! Your Raspberry Pi now has a static IP address configured and should keep this address even after rebooting or losing network connection. If you ever need to revert back to DHCP, simply comment out the lines you added in step 4 by placing a “#” at the beginning of each line and restart the networking service again.

Remember that setting up a static IP address can have unintended consequences if done incorrectly, so make sure to double-check your network settings beforehand and plan for any potential issues. It’s also a good idea to keep note of your static IP in case you need to access the device remotely or troubleshoot networking issues.