{"id":2624,"date":"2019-04-17T20:37:53","date_gmt":"2019-04-17T17:37:53","guid":{"rendered":"https:\/\/kifarunix.com\/?p=2624"},"modified":"2024-03-11T22:38:50","modified_gmt":"2024-03-11T19:38:50","slug":"connect-to-wifi-in-linux-using-nmcli-command","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/connect-to-wifi-in-linux-using-nmcli-command\/","title":{"rendered":"Connect to WiFi in Linux Using NMCLI command"},"content":{"rendered":"\n<p>This tutorial will guide you on how to connect to WiFi in Linux using NMCLI command. NMCLI is a command-line tool for controlling NetworkManager and reporting network status. It can be utilized as a replacement for nm-applet or other graphical clients. It is used to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.<\/p>\n\n\n\n<p>Typical uses include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scripts: Utilize NetworkManager via nmcli instead of managing network connections manually.  nmcli supports a terse output format which is better suited for script processing<\/li>\n\n\n\n<li>Servers, headless machines, and terminals: nmcli can be used to control NetworkManager without a GUI, including creating, editing, starting and stopping network connections and viewing network status.<\/li>\n<\/ul>\n\n\n\n<p>Want to use NETPLAN on Ubuntu 18.04 to check set static IP address? Check our previous guide by following the link below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-configure-static-ip-addresses-on-ubuntu-18-04-server-using-netplan\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"How to Configure Static IP Addresses on Ubuntu 18.04 Server using Netplan (opens in a new tab)\">How to Configure Static IP Addresses on Ubuntu 18.04 Server using Netplan<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"> Connecting to WiFi in Linux using NMCLI command<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Check Wi-Fi Radio Status<\/h4>\n\n\n\n<p>Well, before you can connect to a wireless network in Linux, you need to check if WiFi radio status.<\/p>\n\n\n\n<p>This can be done by executing the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli radio wifi<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>enabled<\/code><\/pre>\n\n\n\n<p>If the WiFi radio is disabled, then you can enable it by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli radio wifi on<\/code><\/pre>\n\n\n\n<p>You can as well check status of the network interface cards by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli dev status<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>DEVICE  TYPE      STATE         CONNECTION \nwlp2s0  wifi      disconnected  --         \nenp1s0  ethernet  unavailable   --         \nlo      loopback  unmanaged     -- <\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Check Available Wi-Fi Access Points<\/h4>\n\n\n\n<p>NetworkManager scans Wi-Fi networks periodically. To check if the SSID of Wi-Fi access point you want to connect to can be seen your Linux system, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli dev wifi list<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>SSID            MODE   CHAN  RATE       SIGNAL  BARS  SECURITY \nKmibey          Infra  2     54 Mbit\/s  100     \u2582\u2584\u2586\u2588  WPA2     \nNcheches house  Infra  1     54 Mbit\/s  37      \u2582\u2584<em>_   <\/em>WPA2 <\/code><\/pre>\n\n\n\n<p>If you are unable to see the SSID of the Wi-Fi access point you want to connect to, you can run a rescan by executing the command below. After that, check again to if you can see the Access point SSID by re-executing the command above.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli dev wifi rescan<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Connect to WiFi using NMCLI<\/h3>\n\n\n\n<p>Assuming that you already have the SSID and the connection password for the Access point you want to connect to, then execute the command below to connect.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nmcli dev wifi connect Kmibey password 'mypassword'<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Device 'wlp2s0' successfully activated with 'a1900bed-baa9-47a3-affb-b640d0effe5d'.<\/code><\/pre>\n\n\n\n<p>If you do not want to display password in plain text, then you can pass the <strong>&#8211;ask<\/strong> option as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nmcli --ask dev wifi connect Kmibey<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Password: ENTER PASS\nDevice 'wlp2s0' successfully activated with 'f747251b-1346-48a2-ae25-1b6fd6243984'.<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Check Device status<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli dev status<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>DEVICE  TYPE      STATE        CONNECTION \n<strong>wlp2s0  wifi      connected    Kmibey  <\/strong>   \nenp1s0  ethernet  unavailable  --         \nlo      loopback  unmanaged    -- <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Check Active Connections<\/h3>\n\n\n\n<p>Once you have successfully connected to your AP, then you can check active connections using the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli con show --active<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME    UUID                                  TYPE             DEVICE \nKmibey  a1900bed-baa9-47a3-affb-b640d0effe5d  802-11-wireless  wlp2s0<\/code><\/pre>\n\n\n\n<p>You can as well omit the <strong>&#8211;active<\/strong> option to list all the connections and their status.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Delete Established Connections<\/h3>\n\n\n\n<p>If you need to delete the connection that is already established, you can specify the connection UUID or the connection name. To obtain the connection UUID or the username, run the <strong>nmcli con show<\/strong> command as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli con sh<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME                UUID                                  TYPE             DEVICE \nKmibey              41dc9830-dd20-4deb-92be-371bfb5d16f0  802-11-wireless  wlp2s0 \nBeats               949762b0-c6e0-4004-918a-55fb6bcf6610  802-11-wireless  --<\/code><\/pre>\n\n\n\n<p>To delete using a connection using connection name;<\/p>\n\n\n\n<pre id=\"block-7f73dfab-f7dc-4521-b36b-ab558eadef88\" class=\"wp-block-code\"><code>sudo nmcli con del Kmibey<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Connection 'Kmibey' (41dc9830-dd20-4deb-92be-371bfb5d16f0) successfully deleted.<\/code><\/pre>\n\n\n\n<p>To delete a connection using connection UUID;<\/p>\n\n\n\n<pre id=\"block-304763e0-87c7-4ec8-9d8b-91619f56ff73\" class=\"wp-block-code\"><code>sudo nmcli con del 41dc9830-dd20-4deb-92be-371bfb5d16f0<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Connection 'Kmibey' (41dc9830-dd20-4deb-92be-371bfb5d16f0) successfully deleted.<\/code><\/pre>\n\n\n\n<p>You can also take down or bring up a previous connection using the commands below respectively.<\/p>\n\n\n\n<pre id=\"block-b08e5095-ac3c-4eea-9a16-e46f61724f5f\" class=\"wp-block-code\"><code>nmcli con down &lt;SSID or UUID&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli con up &lt;SSID or UUID&gt;<\/code><\/pre>\n\n\n\n<p>That is all about connecting to WiFi in Linux using NMCLI command. <\/p>\n\n\n\n<p>Read more on:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"https:\/\/linux.die.net\/man\/1\/nmcli\" target=\"_blank\" rel=\"noreferrer noopener\">man nmcli<\/a><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>man nmcli-examples<\/code><\/pre>\n\n\n\n<p>Other Tutorials<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-use-nmcli-tool-on-debian-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and use NMCLI tool on Debian Linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/create-virtual-secondary-ip-addresses-on-an-interface-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create Virtual\/Secondary IP addresses on an Interface in Linux<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will guide you on how to connect to WiFi in Linux using NMCLI command. NMCLI is a command-line tool for controlling NetworkManager and<\/p>\n","protected":false},"author":1,"featured_media":10635,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[63,121,49,671,672],"tags":[4169,4165,4167,4164,673,4155,4168],"class_list":["post-2624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-networking","category-howtos","category-command-cheatsheets","category-nmcli","category-nmcli-networking","tag-connect-to-wifi-on-command-line-linux","tag-connect-to-wifi-using-nmcli-command","tag-how-to-use-nmcli-command-in-linux","tag-linux-network-manager","tag-nmcli","tag-nmtui","tag-wifi","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2624"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=2624"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2624\/revisions"}],"predecessor-version":[{"id":21144,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2624\/revisions\/21144"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/10635"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=2624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=2624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=2624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}