Step by step network configuration settings for Raspberry Pi 2 to assign a internal static ip

Its always better to have a fixed IP for your Raspberry Pi within your network so that you no need to worry about the dynamic allocation of IP by your router for Pi which may at times break the headless connection to your Pi due to change of IP address.

You can assign a fixed IP to your Pi in 2 ways. One is setting it in the Pi itself and the other option is to set it in your network router. I would prefer the second option as this would avoid the possibility of assigning the Pi’s IP to some other device in your network by the router while the Pi is not available (switched off or disconnected) in the network.

Setting fixed IP in Pi

Open the terminal window and type “sudo leafpad /etc/network/interfaces“. This would open a window like the one displayed below.

Note : “sudo nano” is the usual command that you can see in all script samples. “nano” is the command line editor for Raspbian which opens directly within the console. I prefer “leaf pad” instead of “nano” as this gives you the flexibility and features of a typical windows text editor ( Impact of working in windows platform for years 🙂 ).

 image

Copy and modify the below lines according to your router settings and insert it after the lineiface wlan0 inet manual“.

address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1

To find the currently assigned IP address of your PI type “hostname -I” in the terminal. To view the full network connection details type the command “ifconfig”. The below image displays the details of “wlan0” segment in my Pi.

image

The updated file would look like the one shown below.

image

Note : The above settings is for wifi connection. If your Pi is connected by LAN cable,  add those line below “iface eth0 inet manual” instead of iface wlan0 inet manual

save the file and reboot the Pi. This would assign the new IP address with the netmask and gateway specified in this file.

Setting fixed IP in router

In this method you have to make changes in both the interfaces file in Pi and also you have to add a DHCP static entry in your router. 

Open up your router configuration page and assign a static IP for your Pi. This settings may change from router to router. The below screen shot is based on my home router.

image

As a next step, In the “interfaces” file of Pi change the “manual” mode to “dhcp” instead of adding address, netmask and gateway as shown below

image 

Save the changes and perform a reboot. This would force the router to assign a static IP ( mentioned in router)  for your Pi when ever its connected to your home network.

Leave a comment