etc/network/interfaces multiple connections (wired static + wifi dhcp), how?

0

I would like to configure /etc/network/interfaces so that it connects to wifi when the cable is not connected, is it possible?

Following is the content of /etc/network/interfaces (Ubuntu 15.04):

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 140.136.38.16
    netmask 255.255.0.0
    network 140.136.1.0
    broadcast 140.136.1.255
    #gateway 140.136.38.254
    dns-nameservers 140.136.73.154 140.136.13.4

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp 
    wpa-ssid WIFI
    wpa-psk  WIFIWIFI

With the above configuration and cable not connected I still need to do # ifconfig eth0 down to have access the internet.

KcFnMi

Posted 2016-05-11T19:07:54.773

Reputation: 396

A similar question was asked and answered here: http://askubuntu.com/questions/112968/automatically-disable-wifi-wireless-when-wired

– TheStarvingGeek – 2016-05-11T19:43:27.197

Well, that answer uses /etc/NetworkManager/dispatcher.d/99-disable-wireless-when-wired (which seems to be a pretty exotic thing), I'm asking about /etc/network/interfaces. – KcFnMi – 2016-05-11T20:19:29.283

You could do this with bonding - as long as it's not a problem that your wifi adapter would still connect even when your wired connection is online (it just wouldn't be used for any traffic). See http://serverfault.com/questions/657783/how-do-i-bond-eth0-to-failover-to-wlan0-after-wan-connection-loss

– Carcer – 2016-05-11T20:51:02.360

Ah, sorry, I realise an issue with your network config! Answering... – Carcer – 2016-05-11T20:56:20.097

Answers

0

Your actual issue is your "auto eth0" stanza. This means that the eth0 interface will always be brought up, even if there is no cable connected - and because you have statically configured the interface, it will not time out trying to DHCP, it will just be up and any attempt to send traffic on it will fail. This is why you have to manually ifdown the interface before your system tries to use the wlan. You should only have the "allow-hotplug eth0" stanza, which will tell the system to attempt to bring up the interface only if the cable is actually connected (and also to drop it if the cable goes away). Then your system should start choosing which interface to use a bit more sensibly.

You should probably likewise get rid of the "auto wlan0" stanza and leave it with "allow-hotplug wlan0".

Carcer

Posted 2016-05-11T19:07:54.773

Reputation: 146

I commented both, auto eth0 and auto wlan0, but nothing changed, still the same behavior. I was expecting not to see eth0 in the return of ifconfig, but it is still there. I guess there is some high level ubuntu stuff going on. – KcFnMi – 2016-05-12T11:19:14.250