Raspberry PI Raspbian Static IP Address Configuration

Glad you found this! If you just Google, you’ll find lots of bad advice. This article applies to Raspbian circa 7.0

$cat /etc/debian_version      # to see your release version

The Raspbian’s default image, as circulated via the Pi’s website, has dhcp configured and turned ON by default. It is, after all, designed for noobs. If you want to set a static IP address, you might be tempted to use ifconfig or the ip command to do so. Don’t! Here’s the correct way to do it:

$cd /etc/dhcp
$vi dhclient.conf

This will put you into the vi editor to edit dhclient.conf … if you can’t or won’t use vi, then use your favorite editor instead.

Take a look at the bottom of the file. What you want to do is uncomment either the alias section, or the lease section, and make the appropriate changes.

#alias {
#  interface "eth0";
#  fixed-address 192.5.5.213;
#  option subnet-mask 255.255.255.255;
#}

#lease {
#  interface "eth0";
#  fixed-address 192.33.137.200;
#  medium "link0 link1";
#  option host-name "andare.swiftmedia.com";
#  option subnet-mask 255.255.255.0;
#  option broadcast-address 192.33.137.255;
#  option routers 192.33.137.250;
#  option domain-name-servers 127.0.0.1;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
#}

So which should you chose? Are you sure you want to ask? If the answer is “yes”, do this:

$man dhclient.conf

I chose to use a lease for minimum impact on my network. I just wanted a simple setup: no bells and whistles.

lease {
  interface "eth0";
  fixed-address 192.168.1.99;
#  medium "link0 link1";
  option host-name "pi.mydomain.com";
  option subnet-mask 255.255.255.0;
  option broadcast-address 192.168.1.255;
  option routers 192.168.1.1;
  option domain-name-servers 8.8.8.8;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
}

Some explanation is called for here…

  • “option broadcast…” isn’t really necessary if you’re on a 192.168.x/24 subnet
  • “8.8.8.8” is one of the Google name servers. If you value your privacy, use Level(3) or the like instead