3

Simple question:

How do I set my Raspberry Pi to only connect to my WiFi network if the Ethernet is disconnected?

So it should be something like:

  1. Booting up
  2. Checking if ethernet is connected
  3. Try for 30 seconds or so
  4. If no ethernet, try to connect to Wifi
  5. Try for 30 seconds
  6. if still no connection go back to 2.

Can I do that via crontab and a shell script?

I don't have a screen, keyboard or mouse attached to my RPi and it happened before that it refused to connect to any network. Maybe a priority conflict in the settings?

Running Raspberry Pi 3 Model B, on Rasbian Jessie, headless mode.

Thanks

Paul
  • 133
  • 4
  • 1
    Why do you want to do this? – Steve Robillard Jul 16 '17 at 07:39
  • @SteveRobillard because otherwise my RPi always connects to WiFi, even if a cable is plugged in... – Paul Jul 16 '17 at 11:57
  • 1
    @Paul You can find a professional solution to failover with bonding at [Howto migrate from networking to systemd-networkd with dynamic failover](https://raspberrypi.stackexchange.com/a/78788/79866) and at [How to automatically connect to a known wifi and if it doesn't find it, connect to LAN Ethernet?](https://raspberrypi.stackexchange.com/a/78707/79866) – Ingo Feb 04 '18 at 10:27

1 Answers1

3

This sounds like a job for the NetworkManager (https://en.m.wikipedia.org/wiki/NetworkManager). It does handle activation and deactivation of "connections", such as wired and wireless ones. It prefers wired ones over wireless, and it is able to switch forth and back. But it's kind of a beast, be warned.

The Raspbian base installation comes without NetworkManager and only uses dhcpcd which can't do the things you are asking for. NetworkManager can be installed separately; it's widely used in desktop distributions, such as Ubuntu.

The NetworkManager consists of the daemon, with optional GUIs on top. There's also a CLI, nmcli, which should suit your headless operation.

TheDiveO
  • 1,551
  • 1
  • 9
  • 15
  • Thanks for pointing me into the right direction. Still have some conflicts between ifplugd, wpa_supplicant and nmcli. But shouldn't be too complicated from here – Paul Jul 16 '17 at 13:32