RPi Ethernet and Wifi at the same time

May 25, 2014 at 9:34 pm (computers, internet, maker) (, , , )

This should have been a lot easier than it ended up being!  I wanted to turn one RPi into a router between its Ethernet and Wifi networks, so that a single wifi dongle could be shared across a few Ethernet devices (via a simple dumb Ethernet hub I had lying around).

Well there are lots of posts around the Internet showing how to configure the Pi as an Access Point or an Ethernet Bridge, but in all discussions of the /etc/network/interfaces file I’ve found, no-one has really (that I’ve found so far) mentioned quite how the wpa_supplicant, ifconfig and ifplugd systems all interact and fit together.

Whilst a number of people have speculated that there might be power supply issues that will knock out your Wifi if you plug in an Ethernet cable, I didn’t see any evidence of that.  What I was actually seeing is ifplugd detecting the plugging in of the cable and then running its action scripts in /etc/ifplugd/action.d.  On my version of Raspbian, one of these scripts is a symlink over to /etc/wpa_supplicant/action_wpa.sh which basically disconnects any wpa-roam managed interfaces if the Ethernet is plugged in.

This is the designed-in behaviour, as the basic idea is that if you are using Ethernet and Wifi, then typically it will be to the same network (and ultimately connected to the Internet) so it will only need Wifi when the Ethernet is not connected.  If you have a wired connection, it will disable the wireless connection to use the wired for preference, which is the desired behaviour in the vast majority of cases.

There are a number of “fixes” around the Internet, from killing ifplugd to removing or adding auto or hotplug related options in /etc/network/interfaces.  I’m sure there must be some magic combination of options that means that the hotplugging of cables and dongles can still work, but will not automatically turn the wifi on and off – but I haven’t found it yet.

Instead, I went for the very simple, but almost definitely “quick hack” version of including an “exit 0” command near the top of /etc/wpa_supplicant/action_wpa.sh before it actually did anything.  This way, I get to keep the automatic configuration on plugging cables and dongles in, but the arrival of a new interface does not automatically shutdown the wpa-roam managed ones.

This seems to work really well for keeping Wifi connections open when plugging in an Ethernet cable.  When plugging in a Wifi dongle, that also seems to work, in that both Ethernet and Wifi end up active – although I did get a break in continuity over the Ethernet when this happened – but it reconnected again fine.

Of course, this may well completely shaft true wifi roaming across networks – I don’t know – I don’t take this RPi out and about to test it and I haven’t read enough how the wpa-roam system is meant to work to see.

I expect there is a more elegant way to achieve this, but the Internet wasn’t providing it; the Debian networking configuration manual seemed to be suggesting that I should probably use the GUI and that everything else is legacy; and I’d had enough of reading man pages. If you know of a good reference for how these scripts all interact and how this can be achieved in a nicer way, I’d very much like to hear from you!

But, this will do for now for my relatively static setup of single Wifi network, routed across to the Ethernet network.

Kevin.

 

Permalink 1 Comment