Lately, I arrange Jellyfin media server on my Raspberry Pi. My Pi is wirelessly linked to the router and one drawback I confronted with this setup is accessing the media server on the TV or different gadgets.
Why? As a result of the Pi acquired assigned a random IP tackle at occasions between reboots. And since I used to be attempting to entry the media server working on Raspberry Pi although the IP tackle, it grew to become a problem.
I needed to manually enter the IP tackle on the TV each time the IP tackle modified. Discovering the IP tackle of the Raspberry Pi was one other problem.
That is the place static IP comes into play. If you happen to Pi makes use of static IP, the IP tackle stays the identical between the reboots.
This is likely one of the many situations the place you’re higher off with a static IP assigned to your Pi. And on this tutorial, I am going to talk about how one can obtain that.
Assigning static IP on Pi gadget vs on the router
Sure! There are two approaches to your Pi to have a static IP.
You’ll be able to set static IP on the Raspberry Pi itselfYou can have your router assign a static IP to the Pi
Each strategies have their execs and cons.
As an example you set the static IP on the Raspberry Pi. Your Pi will all the time search the identical IP tackle from the router (to illustrate 192.168.1.51). That is nice so long as the router stays the identical. If you happen to change your router and the brand new router insists on utilizing a distinct subnet (to illustrate within the 172.16.12.0/32 vary), then your PI will not be linked to WiFi like earlier than. You will need to manually replace the community settings on the Pi once more to make use of the brand new IP vary. This might work once you simply a few Pi gadgets and you’ll instantly login to them (as an alternative of SSH) or connect with them by way of Ethernet cable. For a fleet of Pis in random areas in the home.
As an example you need to assign the Pi a static IP from the router. This manner, you’re altering nothing on the Pi. If you happen to change the router, the Pi will get an IP tackle assigned robotically by means of the DHCP server. The issue is that it is not simple to assign static IP to gadgets on all of the routers. Some web firms present routers with little or no scope of configuration modifications.
📑
To summarize, you must set a static IP on the Raspberry Pi itself when you can simply entry the gadget bodily at any time sooner or later.
I can not present easy methods to assign static IP to totally different gadgets on the router, because it is dependent upon what sort of router you’ve got. So, I am going to talk about how one can set static IP on the Raspebrry Pi itself.
Setting static IP on Raspberry Pi
The process contains the next 4 steps:
Get the present IP tackle of the Pi (if you wish to use this one as static IP)Get the gateway IP (router’s IP)Get the DNS server tackle (optionally available)Use the above data to vary community configuration
The primary three steps will be simply completed within the command line. The third step will be completed simply in each the command line and GUI.
📑
Ensure that your Pi is linked to the router. You may also observe these steps when you connect with Pi by way of SSH.
Step 1: Get the IP tackle of Pi
If you wish to use the present IP tackle because the static IP,
That is quite simple. Within the terminal, kind the next command:
hostname -I
You may additionally use this command:
ip a
Each provides you with the present IP tackle of the Raspberry Pi.
As you may see within the screenshot above, my Raspberry Pi’s IP tackle is 192.168.1.34.
Step 2: Get the gateway IP
That is additionally fairly easy. To get the gateway IP tackle (your router’s IP tackle), use this command:
ip route | grep default
As you may see within the screenshot beneath, the gateway IP in my case is 192.168.1.1.
Step 3: Get the DNS server particulars (optionally available)
Some folks wish to hold the identical DNS server which is presently getting used on the system. I feel you are able to do with out that as effectively. Most dwelling customers have the DHCP server deal with it robotically anyway.
Nonetheless, if you would like, you will get the DNS server tackle with:
grep nameserver /and so on/resolv.conf
📋
By now you should have realized that you just set static IP for a specific community connection. If you happen to join the Raspberry Pi to another community, it will not use the identical static IP tackle.
Step 4 (Terminal Technique): Change community configuration to set static IP
If you’re accessing Raspberry Pi by way of SSH or when you favor the command line, you should utilize the nmtui (community supervisor in terminal) software.
✋
These steps have been examined on Raspberry Pi 5. In case your system does not have nmtui bundle put in, it’s possible you’ll set up it and proceed following the directions.
Run this command:
sudo nmtui
You will see an interface like this. Right here, choose Edit a connection and press Enter.
💡
In a TUI (Terminal Person Interface) software, use the up and down arrow keys to maneuver between the choice. You may additionally want to make use of the tab key to maneuver to different choices. Press enter in your chosen possibility.
It’ll present the connections you’ve got had previously in your Pi. I consider you need to set the static IP for the presently linked community. Transfer right down to the suitable community. Now press tab a few occasions to pick out the Edit possibility and press enter.
Use the arrow key to scroll right down to the IPv4 CONFIGURATION possibility. Change it from Computerized to Handbook.
Subsequent, choose the Present possibility of IPv4 CONFIGURATION line.
Use the arrow keys to maneuver down once more and attain the IPv4 CONFIGURATION part once more. This time you may see possibility so as to add Tackle, Gateway and DNS servers.
Go to the Addresses line and click on enter key. It might take you to the start. Scroll down again once more.
✋
It is very important enter the IP tackle of your selection with the subnet masks within the format IP_address/24.
Fill all the main points comparable to IP tackle with masks, Gateway IP and DNS.
If you happen to discover above, I used the gateway IP in DNS too. I additionally added 1.1.1.1, DNS of Cloudflare in its place.
After filling all the main points, scroll right down to the underside, choose OK and press enter.
Your modifications are saved. You’ll be able to exit the nmtui interface the identical approach (press Again after which Give up choices).
Restart your Pi for the modifications to take impact. You will have efficiently arrange static IP on Raspberry Pi.
Step 4 (GUI Technique): Change community configuration to set static IP
The identical will be achieved from the graphical interface of Raspberry Pi OS.
First, click on on the community icon after which go to the Superior choices and click on Edit connections.
Right here you go to IPv4 Settings, set it to handbook after which add all the main points comparable to IP tackle, masks, gateway IP, DNS server and so on. You will have all the main points.
Restart your system and you’ll see that the static IP is now set in your Pi.
Going again to non static IP
If you happen to do not need to use static IP anymore on Raspberry Pi, you may simply revert the steps and return to dynamic IP.
How? Merely edit the community connection in query once more. This time, change the IPv4 configuration to ‘automated’ and save your modifications. And that is it. You do not have to offer IP tackle, gateway IP and so on anymore.
Conclusion
As I discussed in the beginning of this tutorial, you must use a static IP from the router finish specifically in case your Pi will not be simply accessed bodily.
But when your gadget is in your arms on a regular basis, you’ve got the freedom of accessing and altering its configuration.
I hope you discover this tutorial on setting a static IP on Raspberry Pi useful. Please let me know when you’ve got any questions.