Raspberry Pi Static IP address

Give your Raspberry Pi 3 or an earlier version of the Pi a  Static IP address.

A static IP address is a pre requisite for most cases where you plan to use your Pi as server of some sorts. Or when you want to operate it from a remote PC using SSH. By default, the Pi is set to ask for a dynamic IP address from the router.

Overview :

  • Log into Pi.
  • Note down your network parameters
  • Edit the configuration file to set a Static IP address

Time and Difficulty :

  • Time : About 5 mins
  • Newbie Difficulty level : Easy (Basic terminal commands to be entered)

Assigning a Static IP address to the Pi can also be done at the Router level (which is fairly easy but the steps to do this are router’s model and brand specific).

Alternatively, follow the steps outlined below to give your Raspberry Pi a Static IP address :

Note :  replace the x in the lines below with what appears on your screen as you type in the commands.

Log on Raspbian and enter the following commands at the terminal :

  1. ifconfig” (ifconfig displays details of your current network connection )
  2. Write down the values next to inet add:192.168.x.xxx. These numbers is the IP address that your Pi is currently at.
  3. Also write down the Broadcast Range (Bcast) and Subnet Mask (Mask) that appear next to the inet add.
  4.  To get information from your router, type in “sudo route -n“.  This will give you the gateway and destination values.
  5. Write down the Gateway = 192.168.x.x & Destination = 192.168.x.x

We have now obtained all of the data that we need to setup our Raspberry Pi with a static IP address, it’s time to save it to a config file.

Donot edit the Interfaces file. If you have, restore it to the original state or do a fresh install!

We will need to edit dhcpcd.conf and add a few lines to it.

sudo nano /etc/dhcpcd.conf  ; edit the file using nano text editor

Navigate to the bottom of the file and add the following lines :

interface eth0   # eth0 for wired network interfaces

static ip_address=192.168.0.xxx/24  # replace xxx with the numbers you want to fix the pi to. Donot forget /24 at the end.
static routers=192.168.0.1  # Enter the  Gateway value noted earlier
static domain_name_servers=192.168.0.1 # Enter the  Gateway value noted earlier

interface wlan0  # wlan0  for wired network interfaces

static ip_address=192.168.0.xxx/24 # replace xxx with the numbers you want to fix the pi to. Donot forget /24 at the end.
static routers=192.168.0.1 # Enter the  Gateway value noted earlier
static domain_name_servers=192.168.0.1 # Enter the  Gateway value noted earlier

Save your file and exit out of nano by pressing ctrl+x

Reboot your Pi by typing in sudo reboot

Once rebooted, your Pi will be on a static IP address.

Leave a Reply