How to connect to Wifi in Linux with nmcli

Let’s see how we can connect to a Wifi Network via Network Manager (nmcli).

First, we will have to scan the networks, nmcli will provide some useful information like SSID, Channel, Rate, Signal.

nmcli dev wifi

Scan Wifi in Linux with nmcli

If you wish to display more information you can use the “-f ALL” flag.

nmcli -f ALL dev wifi

Scan Wifi networks in Linux with nmcli full view

Now you can connect to you wireless network, in my case the SSID it’s Test-Wifi, you will be prompted for the password.

nmcli --ask dev wifi connect Test-Wifi
Password: ••••••••
Device 'wlan0' successfully activated with '14321ac3-05d5-422e-8117-ae13a9a13f76'.

You have successfully connected to the wireless network, you can display the current settings for the connection as described below:

nmcli connection show Test-Wifi

Check and enable wake on lan in Linux

You can checked if WOL is enabled with ethtool

sudo ethtool enp4s0 | grep -i wake
	Supports Wake-on: pumbg
	Wake-on: d

As you can see in my case wake-on its d (disabled)
Other possible values, the wake on can be triggered by p (PHY activity), u (unicast activity), m (multicast activity), b (broadcast activity), a (ARP activity), and g (magic packet activity).

The value g is required for WOL to work and we can change it with ethtool or NetworkManager.

Ethtool, the change it’s not reboot proof

sudo ethtool -s enp4s0 wol g

Network Manager, the change is reboot proof

sudo nmcli connection modify enp4s0 802-3-ethernet.wake-on-lan magic
sudo nmcli connection up enp4s0

After applying the setting you can check again with ethtool

sudo ethtool enp4s0 | grep -i wake
	Supports Wake-on: pumbg
	Wake-on: g