One of the systems I am currently developing involves connecting a lot of Pis (>40) to a network and then interfacing with them simultaneously from a single host machine on the network using Java RMI to do some complex automation and distributed computing.

All of the Pis are configured to run completely headless but there are two main operational paradigms:

  • Development: the Pi is sitting on my desk and connected to the network via the Ethernet network adapter; the advantage here is largely speed for VNC and live debugging.
  • Deployment: the Pi is in the lab and connected the network via a wireless USB network adapter


I'd like to configure the Pi to preferentially use the Ethernet network adapter and to only use the wireless adapter when no Ethernet connection is available automagically on boot. In loose psuedocode:

if(eth0 is available)
  disable wlan0
else if( wlan0 is available)
  disable eth0

I don't really require any sort of hotswap functionality but if it's easily achieved it could be convenient.

I've been messing around in /etc/network/interfaces but I'm a little scrubby with Linux and cant seem to achieve the desired functionality. Any help is greatly appreciated!


[wicd][1] might be what you're after. It provides interface management with both GUI and CLI options for configuration. By default, it will disable wireless if the wired Ethernet interface becomes active and re-enable it when the wired interface drops. You can configure this behavior.

I use the wicd-curses package under Raspbian on my RPis to do exactly what you are describing. wicd also gives a host of other helpful options for connecting to multiple SSIDs or specific APs.

  • Thanks! wicd-curses worked great and gave me the bonus hot swap capability. – Automaton Jun 29 '15 at 15:33
  • @Automaton I really want to know how you went about doing this. A little more details please – DollarAkshay Mar 12 '16 at 10:16

one way would be to use 'pre-up' in /etc/network/interfaces. (with the one caveat being that if you start the config manually, then you'll need to finish the wlan0 config manually...) In your /etc/network/interfaces, try (under the 'iface wlan0 inet...' line)-

pre-up [ -z "$(ifconfig eth0 | grep 'inet addr:')" ]
#only if the above returned 0 will the following lines execute
pre-up /sbin/iwconfig eth-wlan essid MY_SSID
pre-up /sbin/iwconfig eth-wlan enc on
pre-up /sbin/iwconfig eth-wlan key MY_KEY

(this works because pre-up checks the exit status of each command it executes. So if the grep doesn't find the string 'inet addr:' then the it returns zero and the rest of the pre-up commands execute.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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