Raspberry Pi – Setting a static ip address

For most of what you do, letting the Raspberry Pi get its own address may be fine. there are times where you always need it to come up on the same address. Configuring your RPi for a static address is fairly straight forward process. This starts by using the following command – sudo nano /etc/network/interfaces. This should give you a display similar to this –

auto lo

iface lo inet loopback
iface eth0 inet dhcp

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

The iface eth0 inet dhcp is the line that specifies that the built in ethernet adapter on the RPi board is to get an ip address assigned by a DHCP server on your network. You will need to change the iface eth0 inet dhcp to the following –

iface eth0 inet static
address 192.168.15.10
netmask 255.255.255.0
gateway 192.168.1.1

You will need to change the ip address and subnet mask to what is being used on your network. You may also need to set or change the ip address of the DNS servers used by your Raspberry Pi. The first thing to do is to look at the config file where the dns server information is set – sudo /etc/resolv.conf.

My configuration looked like this –

pi@raspberrypi:~$ cat /etc/resolv.conf
domain local.tld
search local.tld
nameserver 192.168.15.1

I have found that using the router as a dns server usually sing the best option. I usually reference the opendns servers but have been moving to Google’s DNS servers – 8.8.8.8 and 8.8.4.4. After making those changes your resolve.conf file should look like this –

pi@raspberrypi:~$ cat /etc/resolv.conf
domain local.tld
search local.tld
nameserver 8.8.8.8
nameserver 8.8.4.4

To make the active, you do to one of the following actions –

1) sudo reboot

2) sudo ifdown eth0
sudo ifup eth0

3) sudo /etc/init.d/networking restart

4) sudo /etc/init.d/networking stop
sudo /etc/init.d/networking start

To see more of my posts about the Raspberry Pi, please go to http://www.ronnutter.com/category/raspberry-pi/

Send to Kindle
This entry was posted in Blog Entries, Raspberry Pi and tagged . Bookmark the permalink.