I have a LeMaker Guitar with Lemuntu installed. My wpa_supplicant.conf file looks like this:

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


and my /etc/network/interfaces file looks like this:

auto wlan0
iface wlan0 inet dhcp
pre-up wpa_supplicant -B -i wlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf
pre-down killall -q wpa_supplicant

When I boot up my Guitar and the wi-fi router is already running the wi-fi connects just fine. But when I boot up my Guitar and power up router after, it does not connect. I tried to create cron job that every minute does dhclient wlan0 but it didn't work.

So my question is, how to connect automatically to this wi-fi if it goes up after I booted the Guitar.

  • Welcome , restart the wpa_supplicant then run dhclient : systemctl restart wpa_supplicant
    – GAD3R
    Nov 23, 2018 at 13:39
  • @GAD3R can you elaborate a little please? should I do this periodically with cron or just once?
    – muliku
    Nov 23, 2018 at 13:48
  • You can adjust the cron job , a script to check the stat of wlan0 then run wpa_supplicant and dhclient.
    – GAD3R
    Nov 23, 2018 at 14:02

2 Answers 2


Solution: Network-Manager without GUI.

I tried half a dozen tutorials using wpa-supplicant, iw and /etc/network/interfaces. But they all did not work for me. Probably because they did not describe at all what they were doing. So I always ran into a point where it did not work and there was no error message nor any way to find out the source of the problem.

Finally I simply tried installing the default network-manager. Which happens to be the gnome-network-manager but without the GUI components (-> --no-install-recommends).

So in short, the solution is:

sudo apt install --no-install-recommends network-manager
nmcli connection add ifname wlan0 type wifi ssid MySSID
nmcli connection edit wifi-wlan0

While editing the config file you have to set WPA-PSK and the plain text password:

nmcli> goto wifi
nmcli 802-11-wireless> set mode infrastructure 
nmcli 802-11-wireless> back 
nmcli> goto wifi-sec 
nmcli 802-11-wireless-security> set key-mgmt wpa-psk 
nmcli 802-11-wireless-security> set psk your-plain-text-password
nmcli 802-11-wireless-security> save 
nmcli 802-11-wireless-security> quit 

After that reboot and enjoy! The network-manager will take care of everything!

If it complains about permission, the recommended way seems to be to modify/overwrite the policykit rules from /usr/share/polkit-1/actions/org.freedesktop.NetworkManager.policy. I gave up on that and used sudo instead. If anybody knows a clean way to do it, tell us please!

Here is a very good guide, but it's in german: https://wiki.ubuntuusers.de/NetworkManager/NetworkManager_ohne_GUI/


This is a sample script to check the wlan0 stat , connecting and getting an IP address through dhcp:

/bin/ip link set wlan0 up
if grep -q 0 /sys/class/net/wlan0/carrier
killall wpa_supplicant
/sbin/wpa_supplicant -B -i wlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf  > /dev/null 2>&1
/sbin/dhclient -r
/sbin/dhclient  > /dev/null 2>&1

A cron job to run this script every minute.

* * * * * /path/to/script.sh

Edit : you can use ping to test the connectivity.

/bin/ping -q -c3  > /dev/null
if [ $? -ne 0 ]
killall wpa_supplicant
/bin/ip link set wlan0 up
/sbin/wpa_supplicant -B -i wlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf  > /dev/null 2>&1
/sbin/dhclient -r
/sbin/dhclient  > /dev/null 2>&1
  • I can't get it to work. first line prints out error: grep: /sys/class/net/wlan0/carrier: Invalid argument
    – muliku
    Nov 23, 2018 at 14:55
  • @muliku ls /sys/class/net/ to get the exact interfaces names.
    – GAD3R
    Nov 23, 2018 at 14:56
  • yeah I did that, it is named wlan0 alright..... The file /sys/class/net/wlan0/carrier exists but it gives me the invalid argument thingie. Same with cat command
    – muliku
    Nov 23, 2018 at 14:59
  • @muliku Answer edited.
    – GAD3R
    Nov 23, 2018 at 15:14
  • 1
    ok, one with the ping works. The previous one didn't work because wlan0 interface was down from previous execution of the script so it printed out that error. Anyways, thanks for your help!
    – muliku
    Nov 23, 2018 at 15:43

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.