Setting static IP for Raspberry Pi

By default Raspberry Pi uses dhcp to obtain IP from the router. IP may change each time you connect to the router. There are two ways in which you can give a static IP to a Raspberry Pi.

The simple method is to assign a static IP for your raspberry pi MAC address from your router admin console.Most modern router will have this feature. In this way you can easily avoid  any IP conflicts in your network.

If for some reason you don’t have access to the router or your router doesn’t support the first method you can follow this method.

$cat /etc/network/interfaces

The file contents should look like bellow



You need edit this file with desired IP address.The IP address should be unique in your network and should be valid range for your router. iface etho inet dhcp this line indicates that pi is using dhcp to get ip form router. we need to get some information about the network before enabling the static ip. Run the following commands


netstat -nr

you will get the following out put. This will give us the all the information that we need to setup the static ip.



you need change the line  iface etho inet dhcp into following content.

iface eth0 inet static






these are my network parameters, you need to change these according to your network. here address is the IP address that you want to give to pi. it is good idea to take backup of the file before you make any changes to it, so that if some thing goes wrong you can revert back to the original file. you need to have a way to access your pi other than ssh if the pi fails to connect to the network. run the following command to  take backup.

cp /etc/network/interfaces /etc/network/interfaces.bak

now run the following command to add changes

$sudo nano /etc/network/interfaces

after editing the file ,it should like bellow

static IP for Pi

static IP for Pi

don’t forget to save the file after editing it.

Add a Comment

Your email address will not be published. Required fields are marked *