The recommend OS for the Raspberry Pi devices is typically Raspbian.
By default a Raspbian install starts with the nework configured via DHCP. Raspbian is based on Debian, and does things a little differently than their cousins Fedora/RedHat. Instead of configuring resolv.conf directly, it needs to be included with the interfaces configuration file.
If you are running WHEEZY (older, but still common):
You’ll need to open the config file for editing.
sudo nano /etc/network/interfaces
Change the line with “iface eth0 inet dhcp” and add the lines similar to:
iface eth0 inet static
address 192.168.2.31
netmask 255.255.255.0
gateway 192.168.2.1
dns-domain yourdomain.com
dns-nameservers 192.168.2.1 8.8.8.8 4.2.2.1
This sets your desired static IP, and the appropriate settings for your resolv.conf You’ll notice it uses your local DNS, a Google DNS (8.8.8.8), and one of the Level 3 DNS servers commonly used (4.2.2.1).
UPDATE : As of the 2015-05-05 update, you’ll also need to disable the DHCPcd service as well, or you’ll end up with a static and dynamic IP assigned to the eth0 interface. You can disable it with:
sudo update-rc.d dhcpcd disable
This will disable dhcpcd from starting on next reboot.
Arguably, you could do all the static configuration in the dhcpcd.conf file as well, but it seems to be complicating things.
You should now reboot to test all of your changes.
sudo reboot
If you are running JESSIE (newer, but growing in usage):
You’ll need to open the config file for editing.
sudo nano /etc/dhcpcd.conf
At the bottom of the file you will need to add settings such as:
interface eth0
static ip_address=192.168.2.31/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1 8.8.8.8 4.2.2.1
static domain_search=example.com
static domain_name=example.com
This sets your desired static IP, and the appropriate settings for your resolv.conf You’ll notice it uses your local DNS, a Google DNS (8.8.8.8), and one of the Level 3 DNS servers commonly used (4.2.2.1). You will also want to change ‘example.com’ to be your local domain.
You should now reboot to test all of your changes.
sudo reboot
this is insane, isn’t it? Having to configure a static IP with dhcpcd
I agree, but it is the only reliable (and simple) method I’ve seen so far. I’d happily entertain other suggestions, but it does seem to work.
I am very disappointed with raspian jessie. I removed dhcp daemon to enable static ip and I cannot get nameservers into resolv.conf. Now I see, that everything that I learned in past is useless now and simple thing like static address is out of my reach. Who did this mess?
I am running Jessie, use a udev rules file to assign names (like enet0, net0, net1,etc.) and instead of eth0, wlan0, wlan1 I have my interfaces file using those names and just simply stating “address” and “netmask” in the iface definition for the net0 (the udev rule changed wlan0 to net0). I am experimenting at building a wifi extender with a Pi using 2 different wifi adapters. Have everything working, including logging in to the new access point, I just get weird 169.254.134.xxx addresses instead of what I thought they should be so the port forwarding isn’t working yet.
Ooooooppppppssssss – just found out my net0 actually WASN’T getting the assigned ip address and neither was my net1 – hence the 169.254.134.xxx addresses. So, while my udev rule works and the name changes in the interfaces file works, I need to set up the static ip addresses in the dhcpcd configuration file, and add my subnet definition there as well. I’m not sure yet, but I may not need the udhcpd package like before.
When I get this all working I could post the files here if you’d like
Whoa, this is absolutely insane, WTF^2
I concur, and the final reboot (for jessie setups) is required, restarting network through systemctl or /etc/init.d/networking didn’t work for me…
Argh, I’m going OpenBSD, at least it works properly without sinking days of howto-crawling for such nonsense.
Pingback: Configure a link with DSN in Respbian – MAKE IT A BETTER PLACE
/etc/udhcpd.conf has static ip’s assigned to mac’s, at the very end of that file. IP’s have to make sense, as far as what subnet on which interface, 192.168.1. 192.168.8. etc.