eat-sleep-code
Posts: 2
Joined: Thu Jul 03, 2014 9:30 pm

WiFi ONLY works if Ethernet is plugged in

Fri Jul 04, 2014 1:37 am

I have a headless Raspberry PI model B, with a RealTek 802.11n dongle, running the very latest version of Raspbian.

I would like to configure both the wired and wireless connections so that I can choose to plugin to the Ethernet if need be. However, most of the time I would like to connect via wireless. The wireless network utilizes WPA2 Personal with a hidden SSID.
  • If I boot with both the Ethernet and Wifi plugged in, the network connectivity will work over both Ethernet
    and WiFi.
  • If I boot without the Ethernet, I can not connect to the Pi via WiFi.
  • About 15-30 seconds after plugging in the Ethernet, both Ethernet and WiFi network connectivity will work.
  • If I unplug the Ethernet, I can no longer connect to the Pi via WiFi.
Below is my /etc/network/interfaces file. What changes do I need to make so I can use the Wireless connection without the wire? ;)

Code: Select all

auto lo
iface lo inet loopback

iface eth0 inet static
   metric 1
   address 192.168.0.144
   netmask 255.255.255.0
   gateway 192.168.0.1
   dns-nameservers 8.8.8.8 8.8.4.4

auto wlan0
iface wlan0 inet static
   metric 2
   address 192.168.0.244
   netmask 255.255.255.0
   gateway 192.168.0.1
   dns-nameservers 8.8.8.8 8.8.4.4
   wpa-scan-ssid 1
   wpa-ap-scan 1
   wpa-key-mgmt WPA-PSK
   wpa-proto RSN WPA
   wpa-pairwise CCMP TKIP
   wpa-group CCMP TKIP
   wpa-ssid SSIDWASHERE
   wpa-psk PSKWASHERE

User avatar
penguintutor
Posts: 358
Joined: Tue May 08, 2012 9:11 am
Location: UK
Contact: Website

Re: WiFi ONLY works if Ethernet is plugged in

Fri Jul 04, 2014 11:35 am

I expect that your default route is defined against the Ethernet port - in which case it is trying to channel all traffic through the ethernet port even if it's disconnected.

Easiest may be to reconfigure these as DHCP (you could perhaps set a static ip address in your router if you wanted to be able to use a fixed address), or at least set the Ethernet port to DHCP, so it doesn't try and route that way if it's not connected.


Alternatively you could manually change your routing table using the ip command

ip route

will show your current routes

eg.
default via 192.168.0.1 dev eth0
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.144


I'm not sure if it will create an entry for wlan0 if it already has one to 192.168.0.0.
Assuming not then you will need to remove the current and add a new one to point at the wireless lan

ip route del 192.168.0.0/24 dev eth0
ip route add 192.168.0.0/24 dev wlan0

Then do the same for the default route

ip route del default dev eth0
ip route add default via 192.168.0.1 dev wlan0

I have created these commands from memory - you may want to check that I have the syntax correct. The good thing is that these are dynamic so if you do mess it up just reboot and they'll be back to what they want before.


If that works then you can define the routes in the interfaces file so that they only come up when that link is active.

Remove the gateway entry from each section and add the commands above prefixed with up or down as appropriate:

eg. within the wlan0 section
up ip route add default via 192.168.0.1 dev wlan0

You will need to add all the routes against the relevant section depending upon whether the interface comes up or down.

MrEngman
Posts: 3578
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: WiFi ONLY works if Ethernet is plugged in

Fri Jul 04, 2014 2:35 pm

I have some Pi's that have both eth and wifi connections and I SSH into them from a windows laptop. They are all using raspbian,although all with different revisions with the oldest using 3.10.25+ and the newest 3.12.23+, and use either Realtek rtl8188cus or rtl8188eu wifi modules.

I normally connect to them using their hostnames but if I want to disconnect the eth I SSH into the Pi using the wifi IP. When I disconnect the eth the wifi then appears to stop responding but I type Enter a few times on the terminal window and after about 10-15 seconds the wifi starts to respond again.

Just one problem and that is after disconnecting the eth the wifi connection will only connect me with my local network and I cannot connect to the internet. With the eth connected I could connect to the internet via the wifi but I assume the connection was being redirected via the eth. To get the wifi to reconnect to the internet I use the command sudo ifup --force wlan0. After the command terminates the wifi can then access the internet normally.

My /etc/network/interfaces is fairly simple, and so makes life a little easier for me. There's really no point in making things overly-complicated when not necessary

Code: Select all

auto lo

iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "network-name"
wpa-psk "network-password"

allow-hotplug wlan1
iface wlan1 inet dhcp
wpa-ssid "network-name"
wpa-psk "network-password"
Note there are two wifi entries as I happen to have two wifi modules connected to the Pi I'm using at the moment. One uses an rtl8188cus chip and the other an rtl8188eu chip. The other Pi's have only one wifi module connected but they all behave the same if the eth happens to be connected and I then disconnect it.

I have also tried fixed IPs with similar results and tested with hidden ssid a long time ago but can't remember how that behaved but it was configured using wpa_supplicant.conf. Rather pointless using a hidden ssid these days.

Not sure why you're adding this

Code: Select all

   wpa-key-mgmt WPA-PSK
   wpa-proto RSN WPA
   wpa-pairwise CCMP TKIP
   wpa-group CCMP TKIP
into your /etc/network/interfaces file. I would expect your wifi to behave the same wihout them.



MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

eat-sleep-code
Posts: 2
Joined: Thu Jul 03, 2014 9:30 pm

Re: WiFi ONLY works if Ethernet is plugged in

Fri Jul 04, 2014 5:22 pm

@penguintutor, I configured the DHCP reservations in my router and changed my /etc/network/interfaces to this:

Code: Select all

auto lo
iface lo inet loopback

iface eth0 inet dhcp

iface wlan0 inet dhcp
   wpa-scan-ssid 1
   wpa-ap-scan 1
   wpa-key-mgmt WPA-PSK
   wpa-proto RSN WPA
   wpa-pairwise CCMP TKIP
   wpa-group CCMP TKIP
   wpa-ssid SSIDWASHERE
   wpa-psk PSKWASHERE
Now, the Ethernet continues to operate like before, but wireless doesn't work at all and the wlan01 doesn't even appear to exist when I do ifconfig.

@MrEngman, these lines:

Code: Select all

wpa-key-mgmt WPA-PSK
   wpa-proto RSN WPA
   wpa-pairwise CCMP TKIP
   wpa-group CCMP TKIP

were added because my SSID is "hidden". In the tutorial on Adafruit, this is what they said to use if your SSID was hidden.

User avatar
penguintutor
Posts: 358
Joined: Tue May 08, 2012 9:11 am
Location: UK
Contact: Website

Re: WiFi ONLY works if Ethernet is plugged in

Mon Jul 07, 2014 10:41 am

I notice that you don't have the entry:

allow-hotplug wlan0

I'm not sure if that could be your problem, but there shouldn't be a problem with putting it in.
Add it before the definition for the wlan0 device. That way if it detects the wireless device being removed and reconnected then it will try and bring it up (if it's already connected at boot time then it may not be needed, but if the usb device isn't picked up initially it may fix it).

MrEngman
Posts: 3578
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: WiFi ONLY works if Ethernet is plugged in

Mon Jul 07, 2014 11:09 am

penguintutor wrote:I notice that you don't have the entry:

allow-hotplug wlan0

I'm not sure if that could be your problem, but there shouldn't be a problem with putting it in.
Add it before the definition for the wlan0 device. That way if it detects the wireless device being removed and reconnected then it will try and bring it up (if it's already connected at boot time then it may not be needed, but if the usb device isn't picked up initially it may fix it).
I agree

allow-hotplug wlan0

is a requirement. No wonder it doesn't work.

As for

Code: Select all

wpa-key-mgmt WPA-PSK
   wpa-proto RSN WPA
   wpa-pairwise CCMP TKIP
   wpa-group CCMP TKIP
No matter what Adafruit says they should not be necessary as they have nothing to do with enabling the hidden ssid. That is done by these

Code: Select all

   wpa-scan-ssid 1
   wpa-ap-scan 1


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

Kisa_ua
Posts: 2
Joined: Wed Mar 11, 2015 6:43 pm

Re: WiFi ONLY works if Ethernet is plugged in

Sun Mar 15, 2015 6:31 pm

I had also the troubles with wifi (5370 Ralink Technology, Corp. RT5370 Wireless Adapter) settings on raspberry pi B+
if eth0 and wlan0 - both working
unplug eth0 and wlan0 stop respond
if start up with only wlan0 - nothing

i had tried a lot of diiferent solutions from this forum and just from gooooogle

but for my case i have add into /etc/network/interfaces in wlan0 section

Code: Select all

wireless-power off
hope this can help someone

alex999
Posts: 1
Joined: Mon Sep 21, 2015 10:13 pm

Re: WiFi ONLY works if Ethernet is plugged in

Mon Sep 21, 2015 10:15 pm

Hi,

same issue here. Is there something new on this topic (I'm using Edimax EW-7612UAn V2 wifi dongle)?

dersven
Posts: 2
Joined: Sat Nov 28, 2015 1:47 pm

Re: WiFi ONLY works if Ethernet is plugged in

Sat Nov 28, 2015 1:49 pm

Same here - with Edimax and a TP-Link TL-WN752N. :(

m0rph
Posts: 1
Joined: Fri Dec 18, 2015 8:13 pm

Re: WiFi ONLY works if Ethernet is plugged in

Fri Dec 18, 2015 8:23 pm

Hi Guys,

I am not sure if this has been solved but if you set wlan0 to not use DHCP then it should work ok. For example the 'interfaces' below sets the pi wifi ip to 192.168.1.76

Code: Select all

# /etc/network/interfaces

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
# iface default inet dhcp
iface default inet static
address 192.168.1.76
netmask 255.255.255.0
gateway 192.168.1.1

You also need to set /etc/wpa_supplicant/wpa_supplicant.conf as:

Code: Select all

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

network={
        ssid="YOUR-SSID"
        psk="PASSWORD"
}
I also set the DHCP to reserve .76 for this pi.

Hope this helps.

dersven
Posts: 2
Joined: Sat Nov 28, 2015 1:47 pm

Re: WiFi ONLY works if Ethernet is plugged in

Fri Dec 18, 2015 10:57 pm

using a static ip address doesnt help.... :(

guitarmaestro69
Posts: 1
Joined: Sun Dec 20, 2015 6:00 pm

Re: WiFi ONLY works if Ethernet is plugged in

Sun Dec 20, 2015 6:03 pm

Thanks so much for the tip about the routing table. I had my eth0 set to static and the Wifi set to dhcp and i had the same issue - wifi would not work without ethernet cable plugged in. I changed the eth0 to dhcp and it starting working just fine.

Thanks again.

notholmen
Posts: 31
Joined: Tue Dec 25, 2012 10:10 am

Re: WiFi ONLY works if Ethernet is plugged in

Sat Mar 19, 2016 2:40 pm

Hi everyone...
I have the same problem as everyone else in here...
I have an "old" minibian installation from a Pi B+ moved to a Pi 2 B which is why I have several ethX devices, still all should be DHCP, right?

Code: Select all

uname -a
Linux sniff 4.1.19-v7+ #853 SMP Wed Mar 9 18:09:16 GMT 2016 armv7l GNU/Linux
The WLAN has a static lease and I can see that it has picked it up the IP from the DHCP server.
Still as soon as I unplug the ethernet cord I loose ping and or connection.

This is my config in /etc/network/interfaces

Code: Select all

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

auto eth1
allow-hotplug eth1
iface eth1 inet dhcp

auto eth2
allow-hotplug eth2
iface eth2 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
        wpa-ssid "ZZZZZ"
        wpa-psk "XXXXX"
wireless-power off
ip route looks like this after reboot:

Code: Select all

default via 192.168.10.1 dev eth2 
192.168.10.0/24 dev eth2  proto kernel  scope link  src 192.168.10.79 
192.168.10.0/24 dev wlan0  proto kernel  scope link  src 192.168.10.11 
I tried the
ip route del 192.168.0.0/24 dev eth2
ip route add 192.168.0.0/24 dev wlan0
trick... that didn't do it for me, unfortunately.

Please help me to get my Wifi Working independent from the ethernet cable.
I appreciate your help!

Thanks!
/Robert


User avatar
DougieLawson
Posts: 30430
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: WiFi ONLY works if Ethernet is plugged in

Tue Mar 22, 2016 6:46 am

If you're going to do all your stuff in /etc/network/interfaces you should purge the raspberrypi-net-mods package. Alternatively you could rip all the junk out of /etc/network/interfaces and do it the right way using /etc/dhcpcd.conf.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

rpi2user19
Posts: 5
Joined: Sun Mar 27, 2016 7:26 pm

Re: WiFi ONLY works if Ethernet is plugged in

Mon Mar 28, 2016 4:58 pm

I have the same issue on RPI 2. WiFi only works when Ethernet cable is plugged in.

Reading through this thread, I still have not figured out how to resolve the issue.

From the discussions, it seems like the solution is somewhere in one of these files:
/etc/dhcpcd.conf
/etc/network/interfaces
probably not, but maybe: /etc/wpa_supplicant/wpa_supplicant.conf

Are there any other candidate files that may be tuned?

If anyone has succeeded in getting WiFi to work without plugging in Ethernet, I would appreciate a more precise explanation.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4731
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: WiFi ONLY works if Ethernet is plugged in

Tue Mar 29, 2016 8:22 am

rpi2user19 wrote:If anyone has succeeded in getting WiFi to work without plugging in Ethernet, I would appreciate a more precise explanation.
With the default setup, I either connect using the wifi applet on the desktop or put the appropriate network block in /etc/wpa_supplicant/wpa_supplicant.conf myself and it just works, with or without the ethernet cable being plugged in.

User avatar
SR-71
Posts: 16
Joined: Fri Nov 23, 2012 7:56 pm

Re: WiFi ONLY works if Ethernet is plugged in

Tue Mar 29, 2016 2:21 pm

rpi2user19 wrote:I have the same issue on RPI 2. WiFi only works when Ethernet cable is plugged in.

Reading through this thread, I still have not figured out how to resolve the issue.

From the discussions, it seems like the solution is somewhere in one of these files:
/etc/dhcpcd.conf
/etc/network/interfaces
probably not, but maybe: /etc/wpa_supplicant/wpa_supplicant.conf

Are there any other candidate files that may be tuned?

If anyone has succeeded in getting WiFi to work without plugging in Ethernet, I would appreciate a more precise explanation.
Workaround for SSH:
viewtopic.php?p=938236#p938236
Workaround for NTP:
viewtopic.php?p=938961#p938961

rpi2user19
Posts: 5
Joined: Sun Mar 27, 2016 7:26 pm

Re: WiFi ONLY works if Ethernet is plugged in

Tue Mar 29, 2016 3:16 pm

Thanks!
My problem is not with ssh or ntp, my problem is that the WiFi is unreliable on boot unless the Ethernet cable is also plugged in.

My first RPI2, bought about 10 months ago, WiFi works great.
This new CanaKit / Amazon RPI2 bought last week has unreliable WiFi even when using the same Edimax dongle.

One thing I noticed is that the old RPI2 runs different software, even though I have updated and upgraded (sudo apt-get update; sudo apt-get upgrade).

The wpa_supplicant daemon on the old RPI2 is invoked with the -W flag, the new RPI2 for some reason does not invoke that daemon with the -W flag.

When I checked man wpa_supplicant, the -W flag says:
-W Wait for a control interface monitor before starting.

I wonder if that is the issue, but I don't know how to test that.
If anyone knows how to invoke the wpa_supplicant daemon on startup with the -W flag,
I'd love to test that out.

This could be a subtle bug, but I would need to prove it.
If anyone can help, I would appreciate it.

lbog
Posts: 82
Joined: Sun Mar 06, 2016 9:44 am

Re: WiFi ONLY works if Ethernet is plugged in

Tue Mar 29, 2016 10:04 pm

rpi2user19 wrote: If anyone knows how to invoke the wpa_supplicant daemon on startup with the -W flag,
You could try that with the .service-file for wpa_supplicant:

Code: Select all

[Unit]
Description=WPA supplicant daemon (interface- and nl80211 driver-specific version)
Requires=sys-subsystem-net-devices-wlan0.device
After=sys-subsystem-net-devices-wlan0.device
Before=network.target
Wants=network.target
# NetworkManager users will probably want the dbus version instead.

[Service]
Type=simple
ExecStart=/sbin/wpa_supplicant -W -c/etc/wpa_supplicant/wpa_supplicant-nl80211-wlan0.conf -Dnl80211 -iwlan0

[Install]
Alias=multi-user.target.wants/wpa_supplicant-nl80211@wlan0.service

rpi2user19
Posts: 5
Joined: Sun Mar 27, 2016 7:26 pm

Re: WiFi ONLY works if Ethernet is plugged in

Wed Mar 30, 2016 1:57 am

Thanks for the information!

Where does this .service file reside?
This sounds good, but I am not sure where this file resides and how it works.
I would appreciate more details on how to try this out.

lbog
Posts: 82
Joined: Sun Mar 06, 2016 9:44 am

Re: WiFi ONLY works if Ethernet is plugged in

Wed Mar 30, 2016 7:53 am

rpi2user19 wrote: ...., but I am not sure where this file resides and how it works.
This file resides in "/lib/systemd/system" :

Code: Select all

sudo nano /lib/systemd/system/wpa_supplicant-nl80211@wlan0.service

Code: Select all

sudo systemctl stop networking.service

Code: Select all

sudo systemctl enable wpa_supplicant-nl80211@wlan0.service
sudo systemctl start wpa_supplicant-nl80211@wlan0.service
systemctl status wpa_supplicant-nl80211@wlan0.service
ps -fC wpa_supplicant

Code: Select all

sudo shutdown -r +1

Code: Select all

sudo systemctl disable networking.service
systemctl status networking.service

rpi2user19
Posts: 5
Joined: Sun Mar 27, 2016 7:26 pm

Re: WiFi ONLY works if Ethernet is plugged in

Wed Mar 30, 2016 2:49 pm

Thanks! This is great information. I don't fully understand it yet, but I have started to study it so I understand what I am doing before doing it.

notholmen
Posts: 31
Joined: Tue Dec 25, 2012 10:10 am

Re: WiFi ONLY works if Ethernet is plugged in

Wed Mar 30, 2016 8:08 pm

DougieLawson wrote:If you're going to do all your stuff in /etc/network/interfaces you should purge the raspberrypi-net-mods package. ...
Thanks!
I tried to find that package but I believe that it's not installed by default on Minibian which I'm running?
I don't even have dhcpd.conf in /etc/

Thanks for all of your time!
//Robert

fonzy35
Posts: 7
Joined: Sat Feb 27, 2016 3:02 am

Re: WiFi ONLY works if Ethernet is plugged in

Sat Apr 02, 2016 4:16 am

Over 6000 view.
I don't think you'r the only one with this problem.

Hope you find a solution and report back to forum.

Good luck

Return to “Troubleshooting”

Who is online

Users browsing this forum: asandford, portafreak and 42 guests