How to make your Raspberry Pi IP static

raspberrypi-terminal

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:

hostname -I

or this one

ifconfig eth0

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
address 192.168.1.99
netmask 255.255.255.0
gateway 192.168.1.1

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 8.8.8.8

The final step is to restart the network components for all the changes to take effect.

sudo /etc/init.d/networking restart

Attention!

Use /etc/init.d/networking restart if you are using SSH.

The safest method is to simply reboot your Raspberry Pi using:

sudo reboot

Then reconnect with you Raspberry through SSH, but don’t forget to change your IP address to the new one.

Attention!

The other option is to run:

netstat -ar

Once again you have connected with the PI do the following:

ifconfig eth0

to see your new IP in action!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>