Static IP address for your Raspberry Pis, and disable IPv6
Actually, I do not like the idea and work of assigning static IP addresses to the gadgets in my home network. I would prefer to keep everything flexible and have my clever router and networked gadgetry figure the details out by themselves, behind the curtain.
I've tried a fair number of things to have my network recognize my Raspis by their hostname rather than their IP address. Nothing seemed to work. When addressing the Pis by their hostname, the Pis refused to see each other, and I could not access the Pis from my Windows 10 computer either. So I gave up on that route.
The remaining option is to address the Pis by their IP address. By default, they come with their IP address set to 'dynamic'. The router is fine with that. The effect is that whenever you reboot the Pi or reboot the router, your Pis will probably be assigned a new random IP address. That's a pain in the neck because you will first need to find out what that new IP address is with an IP scanner tool, and then edit the settings of all the software tools you're using. Massive waste of time. Not workable.
So that leaves but one option, which is: assigning static IP addresses to all your Raspberry Pis. If you want the Pis to directly talk to some of your other network gadgetry (in my case, the WDMyCloud NAS drive), you will want to assign a fixed IP address to those, too.
Here's how to set up static IP addresses for your new PIs.
1. Make a plan of how you want to structure your home IP range. I like to have my available IP range a little bit organized rather than just assign a random static IP address to my gadgets. First, you need to get an overview of all your gadgets that are currently connected to your home network, computers, Raspis, mobile phones and all.
First, you need to know what local IP address range your router is using. On your Windows computer, press "Win" & "r" keys simultaneously, and enter "cmd" into the popup run window. The black cmd.exe windows pops up, type:
You will get an output that will look something like this:
The "Default Gateway" number is what you are looking for. It is the routers own IP address in the home network. In the case above, it is 192.168.1.1, a fairly common IP address for many home routers. This also tells us that the home networks IP range available to us is 192.168.1.1 to 192.168.1.254. Knowing that we can now proceed to see what IP addresses the router has automatically assigned to all gadgets that are connected to the router either by WiFi or Ethernet. I am using a nice free tool called Advanced IP Scanner to do that. Run that tool and tell it to scan our home networks IP address range that we just determined.
You will find that the router has automatically connected all of your gear using addresses at the low end of the IP range, usually in the x.x.x.10 to x.x.x.30 range.
Now, next step - planning a good and logical map of static IP addresses.
In my home, I know I will never have more than two or three mobile phones connected to the router, one or two TV screens, one PC, one NAS drive... so I'll just let the router automatically assign IP addresses to all gear except the Raspberries. For that, I will instruct my router to only use the address range of 192.168.1.2 to 192.168.1.50 for automatic assignment of IP addresses via its 'DHCP' functionality. That gives the router 49 addresses it can play with to automatically connect all my gear except the Raspberries. Instructing the router to only use that address range for its DHCP functionality works a little bit different in each router type. You need to login into your router's admin panel and search for something like "IPv4 configuration", usually in the LAN settings tab. On my ZTE router, it looks like this:
In the settings, I have told the router to use DHCP address assignments, but only for the range of 192.168.1.1 to 192.168.1.50. Which means that I have now reserved the range of 192.168.1.51 to 192.168.1.254 for my own purpose of static IP setting fully under my control. I don't know how many Raspis will eventually run in my home. But I figure it certainly won't be more than 10 Raspberry Pi 3's, and certainly not more than 10 to 20 Raspberry Pi Zeros. So I decided to assign the IP range of 192.168.1.51-192.168.1.60 to my current and future Raspberry Pi 3's, and the range of 192.168.1.61 and above to my current and future Raspberry Pi Zeros.
Now we can proceed to set static IP addresses for each of the Raspberries. Let's say, I want to assign the static IP of 192.168.1.81 to my Raspi. SSH into your Raspberry, enter
and add the following lines at the end of the file:
interface wlan0
static ip_address=192.168.1.81/24
noipv6
Save the file with ^X and Enter, reboot the Pi.
This tells the Raspi to set itself to a static IP of 192.168.1.81 using the router's subnet mask of 255.255.255.0 (that's what the /24 stands for). The next line of "noipv6" tells the Raspi to not use IPv6 when connecting to the router. This is not really necessary, but we sometimes will need to check what the Raspi's actual current IP is - and I find IPv6 address impossible to read, type and remember...
After reboot, check the new Wifi connection with
Done! You now have a Raspi with a static, unchanging IP even after rebooting the Raspi and/or router.
I've tried a fair number of things to have my network recognize my Raspis by their hostname rather than their IP address. Nothing seemed to work. When addressing the Pis by their hostname, the Pis refused to see each other, and I could not access the Pis from my Windows 10 computer either. So I gave up on that route.
The remaining option is to address the Pis by their IP address. By default, they come with their IP address set to 'dynamic'. The router is fine with that. The effect is that whenever you reboot the Pi or reboot the router, your Pis will probably be assigned a new random IP address. That's a pain in the neck because you will first need to find out what that new IP address is with an IP scanner tool, and then edit the settings of all the software tools you're using. Massive waste of time. Not workable.
So that leaves but one option, which is: assigning static IP addresses to all your Raspberry Pis. If you want the Pis to directly talk to some of your other network gadgetry (in my case, the WDMyCloud NAS drive), you will want to assign a fixed IP address to those, too.
Here's how to set up static IP addresses for your new PIs.
1. Make a plan of how you want to structure your home IP range. I like to have my available IP range a little bit organized rather than just assign a random static IP address to my gadgets. First, you need to get an overview of all your gadgets that are currently connected to your home network, computers, Raspis, mobile phones and all.
First, you need to know what local IP address range your router is using. On your Windows computer, press "Win" & "r" keys simultaneously, and enter "cmd" into the popup run window. The black cmd.exe windows pops up, type:
ipconfig | findstr /i "Gateway"You will get an output that will look something like this:
You will find that the router has automatically connected all of your gear using addresses at the low end of the IP range, usually in the x.x.x.10 to x.x.x.30 range.
Now, next step - planning a good and logical map of static IP addresses.
In my home, I know I will never have more than two or three mobile phones connected to the router, one or two TV screens, one PC, one NAS drive... so I'll just let the router automatically assign IP addresses to all gear except the Raspberries. For that, I will instruct my router to only use the address range of 192.168.1.2 to 192.168.1.50 for automatic assignment of IP addresses via its 'DHCP' functionality. That gives the router 49 addresses it can play with to automatically connect all my gear except the Raspberries. Instructing the router to only use that address range for its DHCP functionality works a little bit different in each router type. You need to login into your router's admin panel and search for something like "IPv4 configuration", usually in the LAN settings tab. On my ZTE router, it looks like this:
In the settings, I have told the router to use DHCP address assignments, but only for the range of 192.168.1.1 to 192.168.1.50. Which means that I have now reserved the range of 192.168.1.51 to 192.168.1.254 for my own purpose of static IP setting fully under my control. I don't know how many Raspis will eventually run in my home. But I figure it certainly won't be more than 10 Raspberry Pi 3's, and certainly not more than 10 to 20 Raspberry Pi Zeros. So I decided to assign the IP range of 192.168.1.51-192.168.1.60 to my current and future Raspberry Pi 3's, and the range of 192.168.1.61 and above to my current and future Raspberry Pi Zeros.
Now we can proceed to set static IP addresses for each of the Raspberries. Let's say, I want to assign the static IP of 192.168.1.81 to my Raspi. SSH into your Raspberry, enter
sudo nano /etc/dhcpcd.conf
interface wlan0
static ip_address=192.168.1.81/24
noipv6
Save the file with ^X and Enter, reboot the Pi.
This tells the Raspi to set itself to a static IP of 192.168.1.81 using the router's subnet mask of 255.255.255.0 (that's what the /24 stands for). The next line of "noipv6" tells the Raspi to not use IPv6 when connecting to the router. This is not really necessary, but we sometimes will need to check what the Raspi's actual current IP is - and I find IPv6 address impossible to read, type and remember...
After reboot, check the new Wifi connection with
ifconfig wlan0
Done! You now have a Raspi with a static, unchanging IP even after rebooting the Raspi and/or router.
Comments
Post a Comment