Assign Your Raspberry Pi Static IP in Couple Steps

Due to its availability, Raspberry Pi is an ideal candidate to run a simple server. After the initial setup, it will use DHCP to connect to your network. That means, each time you restart the Pi or your router, it might end up with a different IP address. This not ideal, as you will need to take a note of the new IP to connect to your services. In order to avoid reconfiguring your computers all the time, you should assign your Raspberry Pi static IP. This post will show you how to do it for ethernet connection on Raspbian, but the steps are the same for a wireless connection. Start by connecting to your Pi. When you do, you can see the current network settings by running:

$ cat /etc/network/interfaces

It should look something like this:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo 
iface lo inet loopback
iface eth0 inet dhcp

The entry you need to change is for the eth0 interface. That is the default ethernet adapter. In order to use a static IP, you have to provide IP address, network, network mask, broadcast and default gateway. So, let’s get them.

Find network settings

First, use the ip command to get your IP address:

$ ip a
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  inet scope host lo 
    valid_lft forever preferred_lft forever
    ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
      link/ether 84:34:97:7e:61:00 brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0
      valid_lft forever preferred_lft forever
    inet6 :belllbelb/128 scope host
      valid_lft forever preferred_lft forever

In the eth0 section, after inet, you can find the IP address. Write it down. Next to it, after brd, is the broadcast. For the remaining the values, run:

$ ip r
default via
dev eth0 dev eth0 proto kernel scope link src

Default shows the default gateway. Just under it you can see the network ( As for the mask, common network masks are /24, which corresponds to, and /16, which stands for These are all things that you need, so onto the next part.

Assign Raspberry PI Static IP

Now, let’s go back to the /etc/network/interfaces. It is time to put in the new values. Change eth0 entry so it looks like this:

iface eth0 inet static

Go ahead and save the file. Lastly, delete the dhcp leases and reboot you Raspberry.

$ sudo rm /var/lib/dhcp/dhcpclient.leases?
$ sudo reboot now

After it boots up, check that the connection is running by pinging the gateway:

$ ping


Congratulations! You have successfully assigned a static IP address to your Raspberry Pi. From now on, you can connect to your services without having to worry about the ever-changing IP. If you have any questions, write them in the comments below.