1

I've read several threads out there regarding Raspbian WiFi connectivity problems. I've solved many of my problems, but I'm not figuring out why (or how?) I can't restart WiFi.

Upon reboot, WiFi is connected fine, I just can't manually restart it.

The Problem

$ sudo ifdown wlan0

ifdown: interface wlan0 not configured

$ sudo ifup wlan0 --force -v

ifup: reading directory /etc/network/interfaces.d
ifup: parsing file /etc/network/interfaces.d/lo
ifup: parsing file /etc/network/interfaces.d/wlan0

ifup: configuring interface wlan0=wlan0 (inet)
/bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/wireless-tools
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
wpa_supplicant: wpa-driver nl80211,wext (default)
wpa_supplicant: /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf
Starting /sbin/wpa_supplicant...
wpa_supplicant: /sbin/wpa_supplicant daemon failed to start
run-parts: /etc/network/if-pre-up.d/wpasupplicant exited with return code 1
ifup: failed to bring up wlan0

After reading some of the logs I found that there are state files in /var/run/network/ifstate.wlan0 and /var/run/wpa_supplicant/wlan0.

Is this correct? Perhaps in wpa_supplicant.conf file I'm pointing ctrl_interface to the wrong place? What are the different purposes of those two different wlan0 state files?

What is the correct way to restart networking without reboot?

My Configurations:

$ ifconfig -a

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
    inet 127.0.0.1  netmask 255.0.0.0
    inet6 ::1  prefixlen 128  scopeid 0x10<host>
    loop  txqueuelen 1  (Loopback Local)
    RX packets 400  bytes 118100 (115.3 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 400  bytes 118100 (115.3 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.1.104  netmask 255.255.255.0  broadcast 192.168.1.255
    inet6 fe80::e9c2:462e:7e58:2755  prefixlen 64  scopeid 0x20<link>
    ether b8:27:eb:81:62:76  txqueuelen 1000  (Ethernet)
    RX packets 5027  bytes 6582631 (6.2 MiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 2057  bytes 273735 (267.3 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ iwconfig wlan0

wlan0     IEEE 802.11  ESSID:"MySSID"  
      Mode:Managed  Frequency:2.412 GHz  Access Point: 84:16:F9:FC:36:54   
      Bit Rate=65 Mb/s   Tx-Power=31 dBm   
      Retry short limit:7   RTS thr:off   Fragment thr:off
      Power Management:off
      Link Quality=70/70  Signal level=-28 dBm  
      Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
      Tx excessive retries:0  Invalid misc:0   Missed beacon:0

$ cat /etc/wpa_supplicant/wpa_supplicant.conf

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

network={
    ssid="MySSID"
    psk="MyPassword"
}

$ cat /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

$ ls -la /etc/network/interfaces.d

total 16
drwxr-xr-x 2 root root 4096 set 25 17:33 .
drwxr-xr-x 7 root root 4096 set 25 15:15 ..
-rw-r--r-- 1 root root   31 ago 31 19:44 lo
-rw-r--r-- 1 root root   95 set 25 15:10 wlan0

$ cat /etc/network/interfaces.d/lo

auto lo
iface lo inet loopback

$ cat /etc/network/interfaces.d/wlan0

allow-hotplug wlan0
iface wlan0 inet dhcp
    wireless-power off
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
ffleandro
  • 113
  • 6
  • I don't know what your problem is (or even if it is due to the Pi) BUT I do know that filling your configuration files with collections of stuff you found on the web is only going to make it worse. In particular dhcp will disable the default network manager dhcpcd and decrease robustness. Put the settings back to those in How do I set up networking/WiFi/Static IP which work for everyone else. THEN explain WHY you think "WiFi is off" – Milliways Sep 25 '17 at 23:54
  • Well, manual addresses is not common in a normal network scenario. I thought that the dhcp option is to let the network router assign the ip as it does to every other device on his network. Why should I assign a static address? If I have 10 RPis on the same network with dozens of other devices, that becomes impractical to maintain. I have a static ip assigned by the router, but I don't agree that the device should specify it's own IP as the normal scenario. – ffleandro Sep 26 '17 at 12:02
  • @Milliways if neither dhcp and manual configurations are adequate for my scenario, what other option there is? – ffleandro Sep 26 '17 at 19:56
  • I did not suggest static - manual lets the network manager handle DHCP rather than your (incorrect) use of dhcp – Milliways Sep 26 '17 at 21:36
  • In fact if you delete the 'interfaces' file it will just work – Milliways Sep 26 '17 at 21:38

1 Answers1

2

On the Pi Zero W, what worked for me was the sequence of: sudo ifconfig wlan0 down sudo ifconfig wlan0 up

(no delay or polling required between those)

For my purposes I was able to do it on one line as: sudo ifconfig wlan0 down; sudo ifconfig wlan0 up

I know it has been a while since it was asked, but this was a long standing frustration for me, as I had reverted to using a Pi B which seems to accept all common suggestions in other posts.

I hope this one does it for you!

dingles
  • 121
  • 3