Fix Ubuntu Wifi On but unable to connect

Ubuntu (including 18.04) has an issue on some computers that can’t handle MAC address randomization while Wifi scanning. Wifi MAC randomization is a good thing, but not totally debugged yet on Ubuntu.

Workarounds Ubuntu 18.04 Wifi dropouts

The telltale sign of this problem is seen by

dmesg -w

as messages like

mwifiex_pcie wlan0: already connected
ieee80211 phy0: mwifiex_cfg80211_sched_scan_start : Invalid Sched_scan parameters

Disable NetworkManager MAC randomization

Note: Ubuntu may have this already set from the factory install.

  1. add to /etc/NetworkManager/NetworkManager.conf

    [device]
    wifi.scan-rand-mac-address=no
       
    
  2. restart NetworkManager

    sudo service network-manager restart
       

Disable Wifi power management

  1. edit /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf

    wifi.powersave = 2 
       
    
  2. reboot

Wifi module reset

This technique works for Microsoft Surface Pro 3 for Wifi on Ubuntu (including 18.04). It removes / reinserts the Wifi kernel module and restarts Network Manager.

See “Notes” below to find your laptop WiFi kernel module name.

  1. create a script ~/wifi_reset.sh

    #!/bin/sh
    
    modprobe -r mwifiex_pcie
    modprobe mwifiex_pcie
    
    service network-manager restart
       
  2. make the script executable

    chmod +x ~/wifi_reset.sh
       
  3. Every time your Wifi disconnects due to the dmesg -w messages noted above, use

    sudo ~/wifi_reset.sh
       

Bluetooth tether

When all else fails, I Bluetooth tether to my Wifi-connected smartphone.

  • Bluetooth WPAN (tethering) in general is limited to 1.6 Mbps upload/download.
  • VPN works over Bluetooth WPAN.

Notes

Which Wifi kernel module am I using?

This is useful to know for the script involving modprobe above:

  1. find wireless device PCI address:

    lspci | grep -i wireless
       

The number at the front is the PCI address. 2. Assuming the PCI address is 00:0b.0:

   lspci -vv -s 00:0b.0 
   

look for “Kernel driver in use” and “Kernel modules”. It might be iwlwifi or mwifiex_pcie etc.