Low Orbit Flux Logo 2 F

How To Set A Static IP On A Raspberry Pi

Setting up a static IP for your Raspberry Pi is really easy. The first thing you should know is that these instructions are completely OS dependent. We’re going to assume that you are running Raspbian. We’ve tested this with the February 2020 version which is based on Debian Buster. These instructions should be almost identical for anything based on Debian or Ubuntu. Other Linux distros or non-Linux OSes will be different.

WARNING - If you are doing this remotely ( SSH or VNC ) you might want to be careful. Making a simple mistake or typo could result in not being able to access your devices. If you’re using a keyboard and mouse, don’t worry so much.

NOTE - Any IP or interface name used in this guide will likely need to be changed for your network.

Why would you want a static IP on your Raspberry Pi?

There are multiple different ways to configure your network on a Debian system. We’re going to show you the “correct” / modern way that people do this on Raspbian.

How To Set A Static IP On A Raspberry Pi - Getting Started

Edit your dhcpcd.conf file ( use nano if you prefer it over vi ):


sudo vi /etc/dhcpcd.conf

Add the following lines to the file. Swap in your desired IP information.


interface eth0
static ip_address=192.168.0.4/24
static routers=192.168.0.1
static domain_name_servers=8.8.8.8 8.8.4.4

Reboot to make sure everything comes up as it should.


sudo reboot

You don’t need to reboot. If you want your changes to go into effect but don’t want to reboot you can just flush the interface with the following command.


ip a flush dev eth0

You don’t need to restart these and it doesn’t seem to update your current IP when you do restart them:

If you don’t want to edit configuration files and you are using a graphical desktop, you can just use network configuration GUI. You can find this on the taskbar. The GUI basically writes your changes to /etc/dhcpcd.conf similar to if you had done it manually. If you do use the GUI to change your network settings you will still need to either flush the interface or reboot the system as shown above. At least that is what I had to do.

Legacy Configuration

You can still use the legacy configuration file if you want to.

You can edit the interfaces file:


sudo vi /etc/network/interfaces 

This is how it will look for the eth0 interface:


allow-hotplug eth0
iface eth0 inet static
 address 192.168.11.100
 netmask 255.255.255.0
 gateway 192.168.11.1
 dns-domain example.com
 dns-nameservers 8.8.8.8 8.8.4.4

Using /etc/network/interfaces works but seems to cause dhcpcd.service to fail to start. On reboot you will see that the network configuration GUI has two big red ‘X’s and doesn’t launch.

If you really want to use the interfaces file but you don’t like seeing dhcpcd.service in a failed state you can just stop and disable dhcpcd.service.


systemctl stop dhcpcd
systemctl disable dhcpcd

This still won’t fix the network configuration GUI but you could just remove that from the bar if you don’t like it.

References