Connecting to Wifi by Command Line with nmcli


Basic usage for lazy people

All you have to do is;
  1. Get if-name,
  2. Add network,
  3. Edit password,
  4. Connect.

1. Getting if-name

Open up terminal and use ifconfig command. (Do not use the $ sign, it means, you are normal user) Or you can use ip a . Its output will be similar.

$ ifconfig 

output of ifconfig , should be like this;

eth0      Link encap:Ethernet  HWaddr b8:27:eb:bf:29:a3  
          inet6 addr: fe80::2ca2:37c8:4331:ac8a/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:328 errors:0 dropped:0 overruns:0 frame:0
          TX packets:328 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:27024 (26.3 KiB)  TX bytes:27024 (26.3 KiB)

wlan0     Link encap:Ethernet  HWaddr c8:3a:35:ca:4f:2c  
          inet addr:10.12.6.237  Bcast:10.12.7.255  Mask:255.255.248.0
          inet6 addr: fe80::b2e0:75f9:351a:7d0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9136 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3779 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12830711 (12.2 MiB)  TX bytes:350802 (342.5 KiB)

In this case, wifi card's name is  wlan0 .


2. Adding Network

For addding network, You need to use this template;

$ sudo nmcli c add type wifi con-name <name> ifname <ifname> ssid <ssid>

For example, if your network's name is  My_Home-Network ,

$ sudo nmcli c add type wifi con-name My_Home-Network ifname wlan0 ssid My_Home-Network

 and can be same for easy usage.

3. Edit Password

Template;
$ sudo nmcli c modify <name> wifi-sec.key-mgmt wpa-psk wifi-sec.psk <password>

Now, we need to add password to it before connecting, Our network name was My_Home-Network ,

 And let's make password 123my456perfect789pass , so;

$ sudo nmcli c modify My_Home-Network wifi-sec.key-mgmt wpa-psk wifi-sec.psk 123my456perfect789pass

4. Connecting to Network

Now, all you need to do is;

$ nmcli c up My_Home-Network 



Cheers!


Comments