By default the Raspberry Pi is set up to obtain an IP address from your wired or wireless network automatically.
This method of obtaining an IP address is called referred to a dynamic IP or DHCP. The IP address for your Raspberry Pi is much like a house address. Imagine that a postman needs to deliver a package. He will read the address on the package and deliver it to the house number, in a street and in a particular area. When information is sent to your Raspberry Pi it needs to know which Raspberry Pi to send it to. Your Raspberry Pi must have an IP address so that it can receive this information. An IP address looks something like this.
This type of IP address is called IPV4. IPV6 is now available but we will be using IPV4 in our examples. You will also want a static IP address if you want to connect to your Raspberry Pi. The DHCP method will change your Raspberry Pi’s IP address almost every time you restart which can cause a problem if you are connecting to it using an IP address of 192.168.100.1. At the next reboot, it may change it to 192.168.100.2. In order to do this we need to edit the interfaces file. Enter the following command in the terminal window.
$ cat /etc/network/interfaces
This will list the network interfaces available.
iface lo inet loopback
iface eth0 inet dhcp
This file currently reads ‘iface’ meaning interface followed by ‘eth0’ which is you’re the built in network connection on your Raspberry Pi. Next we have ‘dhcp’ which means that we want to use DHCP to obtain an IP address.
Let’s edit the following file so we can use a static IP address.
Enter the following command into the terminal window.
$ sudo nano /etc/network/interfaces
This will allow you to edit the file using nano. Change the line that reads
iface eth0 inet dhcp
iface eth0 inet static
Below this line enter the following.
I have used my network settings but you will need to find out your network settings of your own network. I will list the main points in this file. The IP address of 192.168.100.1 is the address I am giving the Raspberry Pi. The network is the network identification that we are using and the gateway is 192.168.100.254. The gateway is important and in most cases will always point to your firewalls, switch or routers IP address. All traffic from your Raspberry Pi will exit your network via the gateway.
Assuming you have used your own network settings and they are correct, you will need to restart the Raspberry Pi.
Enter the follow
$ sudo reboot
Your Raspberry Pi should now have a static IP address. To test this log back into your Raspberry Pi and at the terminal enter
You should see a line that reads
eth0 Link ………
inet addr:192.168.100.1 ……..
The ‘inet addr’ should be the IP address that you have assigned to your Raspberry Pi. To confirm that this is true you should ping your Raspberry Pi from another PC or Raspberry Pi. If you ping the IP address you have assigned to your Raspberry Pi and you get a reply then everything worked as planned. Note that the Raspberry Pi or computer you are pinging from must be on the same network range. For example your PC’s IP address must be 192.168.100.2, 192.168.100.3, 192.168.100.4 and so on.
You can also ping your gateway from your Raspberry Pi to check that the Raspberry Pi being recognised on your network.
$ ping 192.168.100.254
Remember to replace any network IP addresses with your own network settings.