RIGHT and WRONG ways to give a STATIC IP to your Raspberry PI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a little while ago I was at work and I got chatting to another guy there who happens to be another Raspberry Pi Enthusiast and he was boning the fact that once again the Raspberry Pi Foundation have changed the way that you set a static IP address on a Raspberry Pie so I got thinking about this and he's right they have so let me show you a few different ways that you can assign a static IP address to your raspberry piie [Music] hello once again P Geeks and techno nerds all over the world my name's Jeff and I'm an IT professional who's been in the industry for over 30 years I've been playing with Raspberry Pi since they first came out and I wanted to share with you some of the projects that I've done over the years if you like what you see on this channel please hit that Thumbs Up Button subscribe if you want to see more and also hit that notification Bell so you can be told when I put a new video out also in the comments let me know how you get on with this project and if you've got any ideas for other projects that You' like to see me do in the future put those in there as well now let's get on with today's project okay so I guess the first question is why would you want to set a static IP on your Pi well let's say you're running some kind of service a web server a webcam a NZ anything like that and you don't want the IP IP address to change because you want to be able to get to that device on your network and always use the same IP address for it now if you use DHCP straight out of your router it will merily give you an IP address and that will normally be guaranteed to last for at least 2 hours and most of the time so long as your Pi is left switched on it will keep on renewing to that same value however there is absolutely nothing guaranteeing this and especially if you end up with new devices coming onto your network now and again you could end up with the IP address being reallocated to something else so the way around this is to allocate your Pi static IP address and there are several ways that you can go about this and there's also a few ways that you should avoid as well so here I am on the desktop of a freshly installed Raspberry Pi now probably the easiest way to set a static IP address is to go up to the network settings in the system tray left click go to Advanced options and then edit connections that will bring up this box here now in this case I'm just going to play around with the wired connection but if you want to set a static IP for a wireless connection you can do it in the same way you just simply select the name of the connection that you wish to change and then click the settings icon from here you go to the ipv4 settings and change the method from automatic DHCP to manual you then click add to add an address and you type in the IP address that you wish to use you also have to provide the net mask and the default gateway and then finally provide the IP address of the DNS servers that you wish to use in my case there's only one and that's the IP address of my py hole DNS server once that's all done you just hit save now what's a little strange with this is that it hasn't actually applied this change if I open up a terminal window and then I look at the IP address for the eth zero interface you can see it still got the IP address 1 192.168.0.0 whereas in the settings I just tried to change that to 0.31 now in order for this to take effect you can can either reboot or you can just shut down and restart that particular link now that's restarted if I go to show the IP address again you can see now that it's changed and indeed if I reboot it should remain that way if I show the IP address you can see it's set at the static value that I wanted and that's great but what happens if you don't have the guey let's go and take a look at that here I've logged into the Wi-Fi connection on the Raspberry Pi so that I can play around with the wired connection without it kicking me off now where everything got kind of confusing with static IPS in the past was that for several iterations of Raspberry Pi OS the way that you configured a static IP address was by editing the file DHCP cd.com that's sat in thec directory now we're using Raspberry Pi OS Bookworm the big problem is that that file no longer exists now there is a kind of equivalent file if you go Toc DHCP DH client.com then in here there are some changes that you can make to configure an interface with a fixed IP in this case here I've set up the eth zero interface to have this static IP address of 192.168.0 32 I've then provided the default gateway as the option routers and the subnet mask and finally the DNS server now if I save that I can apply it with the command sudu DH client minus r e0 if I then look at the IP address you can see that the IP has changed successfully to the 32 address however now look at what happens when I reboot now the system's rebooted if I take another look of the IP address for the E zero interface you can see now it switched back to that 31 address that I set within the guey earlier that 32 address has just been entirely forgotten however if I go back to the DH client comp file all of the changes that we made earlier are still present so any changes that you make to this file won't survive a reboot it's a really important thing to know instead if you want to set a static IP address from the command line there's a whole bunch of commands that you have to run to do it now I'll put all of these in the description below so you get easy access to them but this is what you have to do first off it's important to understand that Raspberry Pi OS book worm makes use of a service called network manager and in order to interact with it from the command line you have to use a tool called NM CLI firstly I'm going to use this to provide a list of all of our interfaces here you can see that the first line it's returned is our e zero wired interface now I can run a command to set the IP address of that I can then use a similar command to set the Gateway and finally another command to set the DNS server now just like in the guey I could reboot in order for that to take effect or I can just bring the interface down and up again I'll do the lat and now if I look at the IP address you can see that it's been set to the 32 address and this time if I reboot that should persist now the Ros is rebooted let's just check the IP address again and sure enough that 32 address has now persisted now if you want to return to DHCP from the command line you do it like this now if I bring the connection down and up again now we can see that our original3 IP address has come back again however we also are left with the 32 address it hasn't got rid of that and indeed I've not found a way to do this successfully from the command line and the only way I found to delete the address is by going back into the guey and the edit connections window going back into the settings for my connection and then selecting the address and deleting that row and now if I reboot the Box finally we're left with just the IP address from the DHCP server now there is meant to be a way that you can delete the static IP addresses that were defined in theory if you use a command like this whereby you put a hyphen or a minus sign just before the parameter name and then you specify all of your parameters like that it should take all of that entry away leaving you just with the fact that it wants to use DHCP however I've not found that that works at all and the only way I could get it to work was through the guey it's absolute infuriating Madness that raspberry pios has become this complicated in doing something as simple as setting a static IP address so instead let me show you how I do this for my network here I'm logged into the router for my home network and I've gone to the DCP server settings now your router may be slightly different to this and you may find that these settings are in a different place but if you just look up the DHCP server settings and address reservation then you'll see what I'm looking for here now under address reservation for my home network I already have a number of IP addresses set and what this will do is for any of these boxes at the point where they boot they'll all be set for DHCP addresses however in this address reservation list they will always be given the same IP address every time that they boot so if I click on ADD here and then view connected devices I can select our Raspberry Pi and I can now say that I want that to be given an IP address of something completely different let's give it 234 as its IP address and save that now I'm going to reboot my Pi again and now the pi is rebooted one more time if we look at the IP address that it has we can see that we have our 234 IP address as we configured it in the router now I personally prefer this method above any of the others because it means that I can maintain the IP addresses for all of my devices in one central place on my router and I don't have to conf configure each of them independently in their own configuration files so I just find this much much simpler so there you go a few different ways of setting a static IP address on your Raspberry Pi that's running The Bookworm operating system now like I said I personally like to use my router to do this because it centralizes everything but no matter what your reasoning is for wanting a static IP address maybe it's because you're setting up a server maybe it's just because you've got a lot of devices on your network and you want to arrange different IP address PS for different types of device maybe all of the phones go between1 100 and 1110 maybe all of your servers go between 2000 and 220 whatever you want to do your network is your own business and I hope you found this useful as a means to simplify the allocation of IP addresses but also so that you know some of the things to avoid and some of the things not to use certainly some of the command line stuff just doesn't seem to work in the way that the documentation suggests it should maybe this just bugs in the software I really don't know but the only thing I found out for sure is if you leave all of the IP address management to your router everything seems to behave a whole lot better but that's it for this video if you liked what you saw please hit that Thumbs Up Button subscribe to see more and hit that notification Bell so you can be told when I put a new video out let me know in the comments how you get on with allocating static IP addresses for your network and if there's anything else that you'd like to see me do with a Raspberry p let me know in the comments there as well thanks so much for watching till the end and until next time bye for now [Music]
Info
Channel: Jeffs Pi in the Sky
Views: 1,093
Rating: undefined out of 5
Keywords: pi, pi5, raspberry pi, nas, network, attached, storage, tech, hobbies, data, safe, configuration, GUI, pi3b, pi4, pi zero 2w, pi zero w, pi zero, Internet Protocol, IP, TCP/IP, IP address, static, dynamic, address, networking, setup, change IP, configure IP
Id: VJtIedYfvSk
Channel Id: undefined
Length: 13min 28sec (808 seconds)
Published: Sun Jun 30 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.