
Time needed: 5 minutes
In this tutorial we’ll learn how to setup a static IP address on your Raspberry Pi.
By default, your Raspberry Pi attempts to get a random dynamic IP address by DHCP. This address could change later. But after completed this tutorial, your Raspberry Pi will have a static IP address which will always remain the same.
A static IP address makes it easier to access your Raspberry Pi remotely (from another computer for example). So, before setting up a VNC- or SSH-connection, it is advisable to give your Raspberry Pi a static IP address. This will avoid that the IP address changes and eliminate the risk for having to update the IP address of your Pi at the remote applications.
- Prepare your Raspberry Pi
For this tutorial, you need to have your Raspberry Pi running on Raspberry Pi OS. And to keep it simple in this tutorial, we’ll suppose your Pi is connected to the local network with an ethernet cable (wired connection). Nevertheless, the same principles could be applied for a WiFi connection.
- Open the terminal window
Click on the terminal icon on the taskbar (left upper corner of your screen), a terminal window will appear.
- Figure out your router’s IP address
To be able to assign a fix IP address to our Pi, we first need to know our router’s IP address. We can find it out by entering following command in the terminal window :
ip route
Our router’s IP address is the one within the red frame. In our example it is 192.168.0.1. Write this IP address down, as you’ll need it later.
By the way, the current (dynamic) IP address of your Pi is the one in the blue frame. - Open the network preferences app
In the past is was necessary to use a terminal window. Nowadays there is GUI tool which makes it easier to change our network preferences. To open the tool, right-click on the network icon on the taskbar (right upper corner of your screen). Select “Wireless & Wired Network Settings” in the pop-up menu.
- Select the type of configuration
In the “Network Preferences” window, we select the network connection we want to configure. As in this example we are using a wired connection, we have to choose “eth0” in the right listbox. In the case you’re setting up a wireless connection, change both listboxes.
- Complete the Network Preferences form
There are many possible options to configure our network preferences. In our case, we keep it simple and we only configure the minimum parameters:
– But first, we uncheck “Automatically configure empty options”.
– Next we enter our choosen static (fixed) IPv4 address. *
– Next, we enter our router’s IP address. We found this IP address in step 3.
Finally, we click on the “Apply” button to save the changes and close the form.
* Important remarks:
– It’s obvious, but first double checked if the choosen IP-address is still free. If you’re not sure, use a tool like “Advanced IP Scanner” to see the used IP-addresses of your network.
– Only change the last figure of the IP address, the 3 first figures should be the same as the original IP address. And respect the range (higher than 1 and lower than 255). - Reboot
Now we have to reboot our Pi in order for the changes to take effect: Click on the raspberry icon on the taskbar (left upper corner of your screen) , select “Shutdown”. And among the Shutdown Options we select the “Reboot” button.
- Check the IP address
We can check if the IP address has effectively been changed by hoovering (do not click!) over the network icon (right upper corner of your screen) .
We check now the first IP address after “eth0”. As we can see in our case, the IP address has indeed been changed to the one we’ve completed in the Network Preferences.
Great! We made it! It’s much easier now to access our Raspberry Pi from another computer !
Remarks
To retrieve more information regarding your network connections, open a terminal window and enter following command :
ifconfig
The network configurations we managed earlier in the “Network Preferences” app are kept in a file which you can access in a terminal window with following command :
sudo nano /etc/dhcpcd.conf
For more information regarding network configurations, check the official Raspberry Pi documentation : https://www.raspberrypi.org/documentation/configuration/tcpip/
And by the way, if you are interested in learning to program electronic components on your Raspberry Pi, visit our shop. We have a nice kit which contains all the things you need to start.