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.
Requirements
- Raspberry Pi 3 Kit
- 8GB microSD Card for Raspberry Pi OS
Instructions
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:
1 |
ifconfig |
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.
1 |
route -n |
Note the IP address under gateway. This is our routers address.
In the terminal, type:
1 |
sudo nano /etc/dhcpcd.conf |
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):
1 2 3 4 |
interface eth0 static ip_address=192.168.1.4 static routers=192.168.1.1 static domain_name_servers=8.8.8.8 |
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.