RaspberryPI Tutorials

Assign a Static IP on your Raspberry PI

By on 21 Dicembre 2014

When you use your raspberry pi in your home(connected via wifi or ethernet) this has got an ip address like 198.162.1.x (where x is a number between 2 and 254). You can read this value directly on your PI console with the command:


the result will be something like this:

pi@raspberrypi ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:b0:c2:85
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:  Mask:
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:31 errors:0 dropped:0 overruns:0 frame:0
          TX packets:31 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2260 (2.2 KiB)  TX bytes:2260 (2.2 KiB)

wlan0     Link encap:Ethernet  HWaddr 80:1f:02:e2:63:2d
          inet addr:  Bcast:  Mask:
          RX packets:6273 errors:0 dropped:479 overruns:0 frame:0
          TX packets:1946 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:606342 (592.1 KiB)  TX bytes:1966328 (1.8 MiB)

If you use ethernet cable, you ip will be at the line 3, in my case (i use wifi) the if is at the line 18 and actually is

But this IP actually  is not static !!!

If you turn off your PI and you connect a tablet or smartphone to you wifi network, this IP could be allocated for these devices. IP is assigned randomly to your devices every time they will be connected to your wifi network !

If your IP is dynamic, is impossible to know what IP has got today or tomorrow ! You need to convert in static !!

Is very easy. Open the console on your PI and edit the file intefaces with the command:

nano /etc/network/interfaces

here you can write your static IP with this code:

auto lo
iface lo inet loopback
  iface eth0 inet static

#allow-hotplug wlan0
iface wlan0 inet static
  address put.static.ip.here  #<-- In my case i like
  netmask put.net.mask.here   #<--
  gateway put.gate.way.here   #<-- Ypur router address

#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

Then reboot your device with:

sudo reboot

If the IP in not static yet you can edit the same file with this:

auto lo
iface lo inet loopback

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet static
address   #<-- Your Static IP


Reboot your device and check the IP with ifconfig.

You can try this with every number between 2 and 254. I have choose 31 because PI=3,1 !!! 🙂




Turin, Italy

Hi my name is Falcy and this is my World! I use this blog theme to tell people my story. Through all the places and things I see around the world, there isn't a best way to share my experience! Follow my daily updates and discover with me the essence of traveling!

Visited Places