loading
********NOTE********
This method doesn't work on the latest version of Raspbian OS. For the newer method go to : https://youtu.be/dfZlMvzQVsI
**********************
Normally when devices connect to the network they are assigned IP address by the router which does so sequentially (in the order of devices being connected) or randomly. The same goes with your Raspberry Pi. But if you wish to use your Pi without a display (for e.g. via SSH, as a Web Server, or any remote project) then letting the router assign a IP address is generally not a good idea. In such cases you should give your Pi a static IP so that it is always accessible on the same address. That is what we are going to do in this Instructables.

Watch the video above or continue reading for Step-By-Step Instructions.

Watch The Video HERE

Step 1: Getting Ready

What You Will Need:

- Raspberry Pi

- A MicroSD card with Raspbian installed.

 To see how to install Raspbian read This Instructables or watch This Video

- Connection to the router (The router doesn't need to have a internet connection).

- A USB keyboard and Mouse (not needed if you want to SSH into the pi)

- A Display (not needed if you want to SSH into the pi)

- A power adapter.

Setting Up The Pi:

- Connect all the peripherals to the Pi and connect power.

- Log in and open command line or the terminal (if you are in the desktop enviornment).

- Proceed to the next step.

Step 2: Gathering Intelligence

Before we change any settings on the pi, we need to collect some information regarding our network.

- In the command line type the following command and hit enter.

ifconfig

- From the info that comes up, note down the following things:

-> inet addr

-> Bcast

-> Mask

- When you have got all this information, you need even more information. Enter the following command and hit enter

netstat -nr

- From the table that comes up note down the following:

-> Destination

-> Gateway

This is what I got:

  • inet addr : 192.168.137.82
  • Bcast : 192.168.137.255
  • Mask : 255.255.255.0
  • Destination : 192.168.137.0
  • Gateway : 192.168.137.1
These numbers will most probabaly will be different for you so don't copy mine by mistake.

After you have got all this, you can proceed to the next step.

Step 3: Execution

Now we can finally get a Static IP.

Enter the following command and hit enter.

sudo nano /etc/network/interfaces

A file editor will open up.

- In the third line, 'dhcp' means that we are currently getting our IP address from the router.

iface eth0 inet dhcp

- In this line replace 'dhcp' with 'static'

iface eth0 inet static

- Now in the line below this you need to write type the following

<p>address [your inet addr]<br>netmask [your mask address]
network [your destination address]
broadcast [your bcast address]
gateway [your gateway address]</p>

Finally your whole document will look something like this:

<p>auto lo</p><p>iface lo inet loopback
iface etho inet static
address 192.168.137.82
netmask 255.255.255.0
network 192.168.137.0
broadcast 192.168.137.255
gateway 192.168.137.1</p><p>allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp</p>
Be careful to enter YOUR addresses, don't use my numbers by mistake

- Save the file by pressing cntrl + X , then Y , then enter.

- Restart the pi by running the command.

sudo reboot

- After the reboot is complete, you should have a static IP address!!!!

Your Static IP will be the inet address that you noted down earlier.

Step 4: Alternative

While the above mentioned method will certainly work in almost all scenarios irrespective of your router and network, a better method to assign a static IP would be to do it through your router settings.

All the routers, even of different models from the same company, have very different setting layout and option availability. Thus there cannot be a unified guide for all the routers. You should check out the user manual that came with your router to see how to assign a static IP through your router. Doing so will require you to know the MAC Address of your Pi. You can know the MAC address by running the command "ifconfig", in the first line, the HWaddr if your MAC address.

You need to assign the static IP to the MAC address of your Pi.

Thanks for reading this Instructables!!

Take a look at my other Instructables.

Checkout the youtube video for clearer instructions here

You can follow me on Twitter

Also checkout my Youtube Channel

You can even follow me on Google+

<p>Actually a faster and easier way would be to have the router assign it a statis IP by going into the DHCP setup of the router and have it assign a statis IP to the MAC address of your Rasberry Pi,.</p>
<p>The router method was much easier approach for me. Thanks for that suggestion.</p>
I actually mention in my video that the better way to do this is through your router but since the settings on every router differ hugely, I avoided that method because it can become pretty confusing. I'll also update the Instructable to mention this method.<br>Thanks for your comment.
<p>In step 3, under &quot;Finally your whole document...&quot; you have:</p><p>iface etho inet static</p><p>I think you meant that &quot;etho&quot; should be &quot;eth0&quot;.</p>
<p>Well done. Good instructable.</p>
<p>Good job :)</p>

About This Instructable

47,458views

292favorites

License:

Bio: I am student learning computer science and dig electronics and tech. Follow me on Twitter : https://twitter.com/LiveSparking Check out my YouTube channel : https ...
More by LiveSparks:How To Use SSH with Raspberry Pi 2 How To Assign A Static IP to The Raspberry Pi How to Install and configure Raspbian on Raspberry Pi 2 (Linux/windows/mac) 
Add instructable to: