Configure a Static IP Address for Raspberry Pi

September 28, 2015

The default behavior for most Raspberry Pi operating systems is to have the IP address assigned dynamically when connecting to a network. This is known as DHCP (Dynamic Host Configuration Protocol ) and is handled by the router. Left in DHCP mode, the address may change from one boot to the next.

It is also possible to assign a fixed IP address to the Pi. There are many reasons for doing this, especially if you connect to the Raspberry Pi in a headless mode where you need to know the IP in advance in order to connect.

Static IP Steps

1.  Connect the Pi to the network – either via Ethernet or WiFi.

2.  Determine the IP address you will set as static. This must be an IP that is not already in use by another device on the network. This can be done in a couple of ways.

a) The easiest way is to use the dynamic IP assigned to the Pi and make it static. Boot the Pi and find it’s dynamically assigned IP by entering “ifconfig” in the command line interface (or LXTerminal if running the Raspbian GUI desktop). Use the IP address next to “inet addr:” for either eth0 (Ethernet connection) or wlan0 (WiFi connection). Or you can do both if you have both an Ethernet and WiFi connection!

ifconfig screen image


b) Alternatively, you can install a network scanner, like Advanced IP Scanner or Network Mapper, on your computer or the Pi to map the network IP addresses in use. Use any IP within the subnet that is not already in use.

3.  Edit the interfaces configuration file.

  • From the command line interface (or LXTerminal) enter “sudo nano /etc/network/interfaces”.
  • Find the line that starts with “iface eth0 inet” for Ethernet or “iface wlan0 inet” for WiFi. The end of the line should be either “manual” or “dhcp”. Replace dhcp or manual with “static”.
interfaces file screen image

interfaces file

  • Your line should look like “iface eth0 inet static” without the quotes.
  • Add the address line below the iface line with “address <your ip address here>” as example: address
interfaces file screens

interfaces file – Ethernet config. For WiFi look for wlan0

  • Once changes are made, hold the Ctrl key down and press O to WriteOut (save) the file.
  • Press Ctrl key and X to exit.

4.  Reboot the Pi. Confirm the change by typing “ifconfig” to check your handy work. You should now be able to consistently connect your Pi to your network with its fixed, static IP address.

Article closing text image