Setting up Static IP address for Raspberry Pi

A DHCP network makes network configuration easy. Any node (computer, laptop, or devices) connected to this network will automatically get IP address. A raspberry pi connected on DHCP network would also get the benefit. Using this method, we don’t need to set IP address manually.

Dynamic IP is good, but at some point we don’t need it. Even, it gives us troubles. In some case static IP address is convenient for deep inspection.

In this article we will discuss about how to set up static IP address for raspberry pi. The method we use is similar to Linux-based PC does, unless you use non Linux Operating System for your Pi.

In this article I use:

  1. Slackware64 14.0 for desktop OS
  2. Raspbian Wheezy for Raspberry Pi’s OS

Initial Connection, When and What

Where you want to connect or via what network. If you want to do the setting over network, this question must answered first before we proceed. There are two possibilities for doing static IP setup:

  1. DHCP network in which Raspberry Pi has been assigned with a dynamic IP address. In this scenario we want to set up the board to use a static IP (change from dynamic to static)
  2. Peer to peer or connecting your PC to Pi directly, in which raspberry pi request for dynamic IP but our desktop doesn’t provide any. This is difficult because your machine won’t be able to communicate to your pi
  3. peer to peer with DHCP server enabled on your machine. In this scenario the IP is provided by our machine but we need to know what IP it is.
  4. peer to peer, raspberry pi with static IP assigned before. This is the easiest method. In this scenario, we want to change the IP to something else.

If you don’t want to connect the Pi, we can do another thing. Insert your SD card to your machine host SD card reader. We then can configure the system from this.

Any method is fine and I assume you have known how to connect to your Pi. At least you can access the file system.

Configuration Begin

Now, here is the core for this article.

If you want to connect Raspberry Pi to internet via gateway (switch/router) then you should specify which router pi connect to. Find out what gateway address for your network by using route command. You should see a lines like this:

Kernel IP routing table

In this example, my default gateway for this network is 192.168.1.1. Save this information.

If your intention is only to set Pi’s IP for private connection from your machine to your Pi, you can pick any IP you like. However, make sure both Pi and your machine are on same network.

Now open /etc/network/interfaces file as super user. You can use text editos such as vi. Modify the file so it will similar to this one:

On above snippet, I set the Pi’s IP address to 192.168.1.113/24 with network 192.168.1.0.

Next, rewrite the content of /etc/resolv.conf so. Invoke following command:

That line will set our DNS resolver to our gateway.

Reboot your Pi and check whether you get the right IP address by invoking ifconfig command.

If you want to change it back to DHCP aware, change the /etc/network/interfaces content:

About Xathrya Sabertooth

A simple-minded person who loves tinkering in low level system.

, , , ,