I have this configuration in /etc/network/interfaces:

auto lo
iface lo inet loopback

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

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan0
#iface wlan0 inet dhcp
        iface wlan0 inet static
        address 192.168.0.110
        netmask 255.255.255.0
        network 192.168.0.1
        gateway 192.168.0.1
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp


iface eth0 inet static
    address 192.168.0.115
    netmask 255.255.255.0
    network 192.168.0.1
    gateway 192.168.0.1

The wireless static IP worked, but the eth0 didn't.

So I tried to do the config in /etc/dhcpcd.conf:

interface eth0
static ip_address=192.168.0.115/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

And it worked. I am confused and here are several questions:

  1. When to use which file?

  2. Why the wifi worked with /etc/network/interfaces but the eth0 didn't?

  3. Does dhcpcd has somehow priority over /etc/network/interface?

  4. How to check which service has priority or someting? And which service uses /etc/network/interface?

  • 3
    Great question and something I was about to ask on #raspbian. As a Un*x admin of many years, I find this fundamental change baffling compounded by an absolute dearth of documentation. I happened to find this question after spending an hour of trial and error. I wish I'd found raspberrypi.stackexchange.com/questions/37920/… earlier – Alastair McCormack Jan 16 '16 at 14:06
up vote 52 down vote accepted

There are good points in all the answers to this question, but I think that there is some scope for addressing your specific questions directly.

  1. When to use which file?

I'm going to make the assumption that you are suffering from a general degree of confusion that is occurring at the moment (in the wider Raspberry Pi community) with the introduction of Debian 'Jessie' in place of Debian 'Wheezy'. This change has made a large number of tutorials at worst obsolete and at best confusing.

The answer to the question is that when using Wheezy it was normal to make changes to the /etc/network/interfaces file for the purposes of setting up network interfaces (go figure). When using Jessie, it will be necessary to make changes to '/etc/dhcpcd.conf'. However, if making changes to a wireless connection (wlan0) you will also need to make changes to /etc/wpa_supplicant/wpa_supplicant.conf which is where you add the network ssid and password.

  1. Why the wifi worked with /etc/network/interfaces but the eth0 didn't?

I'm not sure how the wifi connection could have worked since there is some information missing from your files (ssid at the least). As janos pointed out, the priority of the etho connection details coming after the wlan0 details probably made them operative (since they would have been seen last by the process reading the file).

  1. Does dhcpcd has somehow priority over /etc/network/interface?

No, they're different and are designed to suit different purposes under Jessie. For the purposes of using Jessie in a fairly simple way you can pretty much ignore the interfaces file and work with dhcpcd.conf and wpa_supplicant.conf.

  1. How to check which service has priority or someting? And which service uses /etc/network/interface?

Again I'm going to make the assumption that the question is more of a 'Which file do I use and if I have to use one which takes priority?' question. The answer is that with the change from Wheezy to Jessie (and in a broader sense with the adoption of systemd) the configuration of `dhcpcd.conf' and 'wpa_supplicant.conf' will be the norm and the 'interfaces' file will be left to it's own devices.

What does this mean for you?

Well (again) making an assumption that you're trying to set up a hard wired (eth0) and wireless (wlan0) connections with static IP addresses, you would want your interfaces file to be the default as it was initially installed;

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

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

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

You would want your dhcpcd.conf file to include the connection details at the end of the file for both interfaces and the additional entries would probably look a bit like this;

# Custom static IP address for eth0.
interface eth0
static ip_address=192.168.0.115/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

# Custom static IP address for wlan0.
interface wlan0
static ip_address=192.168.0.115/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

Lastly you would want to edit your wpa_supplicant.conf file so that it includes the ssid for the wifi network and the password. It should probably look a bit like this;

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="homenetwork"
    psk="h0mepassw0rd"
}

I hope that covers it off. There is the very real possibility that my assumptions are incorrect, but since I recently went through a similar learning curve I'm hoping the data is useful.

I've actually written this up and you can get the information in the free ebook Just enough Raspberry Pi from Leanpub.

  • 1
    Don't work. If we bring up both interfaces with.e.g., ifconfig eth0 up ping to outside and ssh from outside not work. If we put one of the interfaces into dhcp all work. – giuseppe Oct 7 '16 at 9:55
  • Hopefully someone will be able to assist with your question – d3noob Oct 7 '16 at 18:58

The priority has to do with your init or systemd configuration. With regards to dhcp: if you have s statically or manually configured interface, and dhcp starts requesting an address afterwards, it will override what you already have. On Debian, dhcp is started for interfaces for which you specify dhcp, and not just magically by itself. If you have unexpected behavior you may have a different system running in the background like NetworkManager.

Per point:

  1. don't use dhcpcd.conf at all, leave it be.
  2. You don't have a eth0 allow hotplug line.
  3. If dhcpcd is started after networking and you have it set to take over an interface, it will.
  4. Check the order in which you start those services.

The wireless static IP worked, but the eth0 didn't.

The eth0 interface was probably not brought up at system boot because it's not listed on the auto line. From man interfaces:

Lines beginning with the word "auto" are used to identify the physical interfaces to be brought up when ifup is run with the -a option. (This option is used by the system boot scripts.) Physical interface names should follow the word "auto" on the same line. There can be multiple "auto" stanzas. ifup brings the named interfaces up in the order listed.

Change this line:

auto lo

To this:

auto lo eth0

And then it should work.

The other answers have addressed your other questions. I hope this helps.

  • 2
    THIS is the answer. The OP has other problems too, but for people like me who followed other guides which just added the static information to /etc/network/interfaces, the missing piece was just auto eth0 and restart networking or reboot! – Adam Kaplan Jul 17 '16 at 22:14

See How do I set up networking/WiFi/Static IP for details of how to set up networking.

You can use the older /etc/network/interfaces method if you want. Unfortunately the file you have listed contains many errors. You should stick with one of the standard configurations.

If you really want to use /etc/network/interfaces (other than its default) you would need to disable dhcpcd.

An explanation of dhcpcd is too complex for this Forum, but the link https://wiki.archlinux.org/index.php/dhcpcd provides a good summary.

First, get the /etc/network/interfaces file back to its original version...

interfaces(5) file used by ifup(8) and ifdown(8)

Please note that this file is written to be used with dhcpcd

For static IP, consult /etc/dhcpcd.conf and man dhcpcd.conf

Include files from /etc/network/interfaces.d:

source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

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

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Then, keep your changes to the /etc/dhcpcd.conf file simple and just for wireless...

(at the bottom of the file...)

nohook lookup-hostname

interface wlan0
    static ip_address=192.168.0.53/24
    static routers=192.168.0.1
    static domain_name_servers=8.8.8.8

/etc/wpa_supplicant/wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
    ssid="The SSID of your Router"
    psk="daPassword"
    scan_ssid=1
    key_mgmt=WPA-PSK
}

Be aware that the latest version of Raspbian Jessie (12/30/2016) contains a flaw in the second line of the interfaces file. The second line is missing the leading # symbol to designate the line as a comment. This problem causes the interfaces file to be unreadable by the system. I spent many hours trying to get my wifi to work before I found this error.

To fix it, simply add a # symbol to the start of the line.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.