How to give a static IP address to a Raspberry Pi

If you plan on frequently accessing your Raspberry Pi on your network, you’ll want to have a Raspberry Pi static IP address. This is so when you try to access your Raspberry Pi, it will have the same IP address every time. If you just use it of the box with an IP address that your router has set via DHCP, its lease may expire and IP address will change. When that happens, you won’t know what IP address your Raspberry Pi has unless you do additional research, or hook up a monitor and keyboard to it, which can be a bit annoying if you have a ‘headless’ setup.



1. Install Raspbian OS

First, you must install the Raspbian OS on your Raspberry Pi. Check out the official guide here.

2. Set a static IP address

Open up a new terminal and type the following command:

You will get a screen similar to this:

If your Raspberry Pi is connected via ethernet, see what follows ‘eth0’ instead of ‘wlan0’

Note the IP address that follows “inet”. Jot this down or remember it.

Next, type the following command to get your router’s gateway address.

Note the IP address under gateway. This is our routers address.

raspberry pi static ip address

In the terminal, type:

Use your arrow keys to go navigate to the bottom of the file. Set your static IP address like this (change ip_address and routers values):

After you are done, press CTRL+X then Y then ENTER to save the file. You may need to reboot your Raspberry Pi for these changes to take effect.