In this tutorial we’ll learn how to setup a static IP address on your Raspberry Pi. After completed this tutorial, your Raspberry Pi will have a static IP address.
A static IP address makes it easier to access your Raspberry Pi from another computer. So, before setting up a VNC- or SSH-connection, it is advisable to give your Raspberry Pi a static IP address. This will avoid updating the IP address of your applications at the other computer.
What you’ll need for this tutorial
For this tutorial, you need to have your Raspberry Pi running on Raspbian. And to keep it simple, we’ll suppose your Pi is connected to the local network through a cable it this tutorial. Nevertheless, the same principles could be applied for a WiFi connection.
Figuring out your current IP address
We’ll start this tutorial to figure out the current (dynamic) IP address. For this we have to open a terminal window as shown below:
At the command line we enter:
This command give you lots of network related information.
Near to eth0 we can see the current IP address. In our example of the figure above it is 192.168.0.16. Write this IP address down, as you’ll need it later.
Opening the configuration file
Now we have to open the configuration file where we can make the changes for a static IP address. The filename is named dhcpcd.conf and it is stored in the folder named etc. To do make the necessary changes we’ll use the nano editor in our terminal window. For this, we enter the following command:
sudo nano /etc/dhcpcd.conf
This command allows you to edit the right configuration file. Don’t worry if you don’t understand this linux command. You’ll find more details on the internet or in our own tutorials soon.
If you wrote the command right, following screen should appear:
Change the configuration file
In this screen you have to scroll down until you see:
# Example static IP configuration
When you’re at this line:
- uncomment (remove the #) each line of this paragraph
- change the IP-address.
Remark: Only change the last figure of the IP address, the 3 first figures should be the same as the original IP address (the one you just wrote down). Be sure you don’t use another static IP address of your LAN and respect the range (ex: higher than 1 and lower than 255).
Once the changes made, use Ctrl + x to exit.
And save the changes by entering “Y”.
Now reboot the Raspberry Pi. So it can take into account the changes. Enter:
Check your Raspberry has the wanted static IP address
You can do this by opening a terminal window and re-enter:
As shown in the figure above, you should see the static IP address now.
Great! You made it much easier now to access you Raspberry Pi from another computer now!
Remark: In the case you want to have a dynamic IP address again, you can just comment (add “#” at the beginning of the line) the changed lines of the configuration file we mention here above.
And if you are interested in learning to program electronic components on your Raspberry Pi, don’t hesitate to visit our shop. We have a nice kit which contains all the things you need tot start.