In this post it will be shown how it is set an static ip for the Raspberry.
Panel PC: Panel PC
By default the Raspberry Pi is automatically set to obtain an IP address from a wired or wireless network. Then why do we want an static IP if the Raspberry automatically sets already one? The answer is because we need to have the same exact IP, not an automatic one. The reason of being automatic makes that the IP can be different each time the network process starts. If it is automatic it is impossible to communicate to a certain IP address because it is changing each time it starts the network.
This static address is needed so that any traffic destined for the Raspberry will be able to find it on the network at any time. An analogy for this would be a telephone number, if you want to communicate with someone using the mobile phone, it is impossible if he is changing his number every day. This is why it has an static number, so this way it can be contacted at any time.
This automatic method of obtaining an IP address is called DHCP or Dynamic Host Configuration Protocol. It is sometimes referred to as a dynamic IP. Your router will normally distribute these IP addresses but it isn’t guaranteed that it will get the same IP address every time. This can cause problems if you are trying to connect to your Raspberry Pi remotely.
Now we'll see how to set a static IP address
The first step is going to the terminal prompt and write the following command:
As it is been said, by default it gets automatically an IP address, this is configured on this interfaces file, in the following line:
iface eth0 inet dhcp
So this eth0 (Ethernet0) configuration needs to be changed in order to give a static IP. So it is needed to access to that file and change the configurations to achieve it. This is done using the following command:
sudo nano /etc/network/interfaces
This will open this document in the same terminal. Now it is time to remove the line that sets the IP address automatically for an static IP address. So:
Remove the line that reads
iface eth0 inet dhcp
And add the following lines
auto eth0 iface eth0 inet static address 192.168.1.25 netmask 255.255.255.0 gateway 192.168.1.1
Finally you need to save the file by pressing CTRL+X and select Y to save the changes.
With this we have configured the eth0 to have an static IP.
If we now use the command to see our interfaces we will see that the eth0 has now the IP we have assigned to. This is done using the command:
Now the Raspberry has an exact "Telephone Number" (IP) to be communicated with it at anytime. To apply these changes it must be done a reboot to the Raspberry.