How to setup Static IP address on Raspberry Pi

Hello everyone, if you follow this website, I have written several posts about Raspberry Pi and Raspbian 9. And today, I am going to show you how to set the static ip address on Raspberry Pi. I assume you have installed Raspbian 9 on your Raspberry Pi. Well, Raspberry Pi is a great tiny devices that can be used to power up your network with a multimedia streaming service. Read our guide to install Plex Media Server on Raspberry Pi.

How to Set Static IP address on Raspberry Pi

To set the static IP address on Raspberry Pi (Raspbian 9), you can follow these steps. Open Terminal from your Raspberry Pi and then follow these steps below.

Step 1. Know your network device

We need to know the network device on your Raspberry Pi. Use this command to get information about your current network configuration.

ip addr

Output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 inet 127.0.0.1/8 scope host lo
 valid_lft forever preferred_lft forever
 inet6 ::1/128 scope host 
 valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 link/ether b8:27:eb:8f:67:a1 brd ff:ff:ff:ff:ff:ff
 inet 192.168.100.20/24 brd 192.168.100.255 scope global eth0
 valid_lft forever preferred_lft forever
 inet 192.168.100.20/24 brd 192.168.100.255 scope global secondary eth0
 valid_lft forever preferred_lft forever
 inet6 fe80::487d:6b63:fb10:badb/64 scope link 
 valid_lft forever preferred_lft forever

As you can see eth0 is my network device. This could be different in your current configuration. Make a note of this device. We will use it later.

Step 2. Edit the interfaces configuration file.

Now we need to do some editing to the file /etc/network/interfaces.

sudo nano /etc/networking/interfaces

Usually, you will see the following lines

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

Now we need to add some lines at the bottom of the file

#loopback
auto lo
iface lo inet loopback

#primary network interface
allow-hotplug eth0
iface eth0 inet static
 address 192.168.100.14
 netmask 255.255.255.0
 gateway 192.168.100.1

Change the IP address to match with your current network addresses. Close the file and we need to restart the networking service.

sudo systemctl restart networking
sudo ifup eth0

Done. Now check your IP address once again. Make sure your new IP address is shown. That’s it. Thank you for reading this how to set static IP address on Raspberry Pi.

Be the first to comment

Leave a Reply