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.
- From the info that comes up, note down the following things:
-> inet addr
- When you have got all this information, you need even more information. Enter the following command and hit enter
- From the table that comes up note down the following:
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
gateway 192.168.137.1</p><p>allow-hotplug wlan0
iface wlan0 inet manual
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.
- 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+