In this tutorial I will teach you how to make your IP static on Raspbian installation.
This means, every time you turn off and or restart the Raspberry Pi you IP will remain the same.
Ok. Lest do this!
Find your current IP address by running the following command:
or this one
and look at the part where it says inet addr
If we execute:
cat /etc/network/interfaces | grep 'iface eth0'
we will see the following result:
iface eth0 inet dhcp
The eth0 interface (the LAN port on the Raspberry Pi) is set to DHCP, which means it takes his Internet access address from the DHCP server.
This is usually a DHCP server located on your router.
Therefore, the DHCP server is the one that decide the IP addrss of your Raspberry.
To set a static IP, we have to edit the /etc/network/interfaces file. We will replace the text – static with dhcp, and below, will enter our network info.
First lets open this file with the Nano text editor and set the data.
sudo nano /etc/network/interfaces
Once we have opened the file, it is time to make the edits.
iface eth0 inet static
What did we do?
First we changed the text of iface eth0 inet dhcp to iface eth0 inet static.
Then at the bottom we added a couple of new lines with settings about our network.
The first line is the actual static IP address.
Once you’re done, press CTRL + X then Y and hit ENTER.
If you want to enter e specific DNS server, then run this command:
sudo nano /etc/resolv.conf
and put the new DNS server inside.
Example: nameserver 18.104.22.168
The final step is to restart the network components for all the changes to take effect.
sudo /etc/init.d/networking restart
Use /etc/init.d/networking restart if you are using SSH.
The safest method is to simply reboot your Raspberry Pi using:
Then reconnect with you Raspberry through SSH, but don’t forget to change your IP address to the new one.
The other option is to run:
Once again you have connected with the PI do the following:
to see your new IP in action!