|
| 1 | +# The `nmcli` command |
| 2 | + |
| 3 | +The `nmcli` command is used for managing network connections by controlling the NetworkManager, a daemon that handles networking, through command line. |
| 4 | +The command stands for Network Manager Command Line Interface. |
| 5 | + |
| 6 | +### Installation: |
| 7 | + |
| 8 | +The `nmcli` command is already installed by default on most Linux distros. To check if it is installed on your system type: |
| 9 | + |
| 10 | +``` |
| 11 | +nmcli --version |
| 12 | +``` |
| 13 | +If you don't have nmcli installed you can do it by using the package manager: |
| 14 | + |
| 15 | +Ubuntu or Debian: |
| 16 | + |
| 17 | +``` |
| 18 | +sudo apt install network manager |
| 19 | +``` |
| 20 | +This will install NetworkManageron in your system. |
| 21 | +Now we have to start the network managing service. |
| 22 | + |
| 23 | +``` |
| 24 | +sudo systemctl start NetworkManager |
| 25 | +``` |
| 26 | + |
| 27 | +Red Hat-based System(such as Fedora, CentOS, REHL): |
| 28 | + |
| 29 | +``` |
| 30 | +sudo dnf install NetworkManager |
| 31 | +``` |
| 32 | +This will install NetworkManager in your system. |
| 33 | +Now we have to start the network managing service. |
| 34 | + |
| 35 | +``` |
| 36 | +sudo systemctl start NetworkManager |
| 37 | +``` |
| 38 | + |
| 39 | +Arch Linux: |
| 40 | + |
| 41 | +``` |
| 42 | +sudo pacman -S networkmanager |
| 43 | +``` |
| 44 | +This will install NetworkManager in your system. |
| 45 | +Now we have to start the network managing service. |
| 46 | + |
| 47 | +``` |
| 48 | +sudo systemctl start NetworkManager |
| 49 | +``` |
| 50 | + |
| 51 | +### Examples: |
| 52 | + |
| 53 | +1. List all available Wifi networks |
| 54 | + |
| 55 | +``` |
| 56 | +nmcli device wifi list |
| 57 | +``` |
| 58 | + |
| 59 | +2. View Network Status |
| 60 | + |
| 61 | +``` |
| 62 | +nmcli device status |
| 63 | +``` |
| 64 | + |
| 65 | +3. Connect to a Wifi Network |
| 66 | + |
| 67 | +``` |
| 68 | +nmcli device wifi connect "SSID_NAME" password "YOUR_PASSWORD" |
| 69 | +``` |
| 70 | + |
| 71 | +4. Disconnect from a Wifi Network |
| 72 | + |
| 73 | +``` |
| 74 | +nmcli connection down "CONNECTION_NAME" |
| 75 | +``` |
| 76 | + |
| 77 | +5. Turn Wifi On/Off |
| 78 | + |
| 79 | +``` |
| 80 | +nmcli radio wifi on |
| 81 | +nmcli radio wifi off |
| 82 | +``` |
| 83 | +, respectively. |
| 84 | + |
| 85 | +6. Turn Bluetooth On/Off |
| 86 | + |
| 87 | +``` |
| 88 | +nmcli radio bluetooth on |
| 89 | +nmcli radio bluetooth off |
| 90 | +``` |
| 91 | +, respectively. |
| 92 | + |
| 93 | +7. To show all connections |
| 94 | + |
| 95 | +``` |
| 96 | +nmcli connection show |
| 97 | +``` |
| 98 | + |
| 99 | +8. To show detailed info about specific connections |
| 100 | + |
| 101 | +``` |
| 102 | +nmcli connection show "CONNECTION_NAME" |
| 103 | +``` |
| 104 | + |
| 105 | +### Syntax: |
| 106 | + |
| 107 | +The general syntax for the nmcli command is as follows: |
| 108 | + |
| 109 | +``` |
| 110 | +nmcli [OPTIONS...] { help | general | networking | radio | connection | device | agent | monitor } [COMMAND] [ARGUMENTS...] |
| 111 | +``` |
| 112 | + |
| 113 | +### Additional Flags and their Functionalities: |
| 114 | + |
| 115 | +#### Options |
| 116 | + |
| 117 | +| **Short Flag** | **Long Flag** | **Description** | |
| 118 | +| :------------- | :--------------------- | :------------------------------------------------------------------------------------------------------------- | |
| 119 | +| `-a` | `--ask` | nmcli will stop and ask for any missing required argument(do not use for non interactive options) | |
| 120 | +| `-c` | `--color`{yes/no} | It controls color output. yes enables colors, while no disables colors | |
| 121 | +| `-h` | `--help` | Prints help information | |
| 122 | +| `-p` | `--pretty` | This causes nmcli to produce more user friendly output, eg with headers, and values are aligned | |
| 123 | +| `-v` | `--version` | Shows the nmcli version | |
| 124 | +| `-f` | `--fields`{field1,...} | This option is used to specify what fields should be printed. Valid fields names differ for specific commands. | |
| 125 | +| `-g` | `--get-value`{field1,.}| This option is used to print values from specific field. It is a shortcut for --mode tabular --terse --fields | |
| 126 | + |
| 127 | +#### General Commands |
| 128 | + |
| 129 | +| **Command** |**Description** | |
| 130 | +| :----------------------------- | :------------------------------------------------------------------- | |
| 131 | +| `nmcli general status` | Show overall NetworkManager status | |
| 132 | +| `nmcli general hostname` | Display current hostname | |
| 133 | + |
| 134 | +#### Networking Commands |
| 135 | + |
| 136 | +| **Command** | **Description** | |
| 137 | +| :----------------------------- | :------------------------------------------------------------------- | |
| 138 | +| `nmcli networking on` | Enable all networking | |
| 139 | +| `nmcli networking off` | Disable all networking | |
| 140 | +| `nmcli networking connectivity`| Check network connectivity status | |
| 141 | + |
| 142 | +#### Radio Commands |
| 143 | + |
| 144 | +| **Command** | **Description** | |
| 145 | +| :----------------------------- | :------------------------------------------------------------------- | |
| 146 | +| `nmcli radio wifi on` | Enable Wi-Fi radio | |
| 147 | +| `nmcli radio wifi off` | Disable Wi-Fi radio | |
| 148 | +| `nmcli radio all` | Show status of all radio switches | |
| 149 | +| `nmcli radio wifi` | Show Wi-Fi radio status | |
| 150 | + |
| 151 | +#### Connection Management Commands |
| 152 | + |
| 153 | +| **Command** | **Description** | |
| 154 | +| :----------------------------------------------- | :------------------------------------------------- | |
| 155 | +| `nmcli connection show` | List all saved connection profiles | |
| 156 | +| `nmcli connection show --active` | List only active connections | |
| 157 | +| `nmcli connection show "NAME"` | Show detailed info about specific connection | |
| 158 | +| `nmcli connection up "NAME"` | Activate a connection | |
| 159 | +| `nmcli connection down "NAME"` | Deactivate a connection | |
| 160 | +| `nmcli connection modify "NAME" [OPTIONS]` | Modify connection settings | |
| 161 | +| `nmcli connection delete "NAME"` | Delete a connection profile | |
| 162 | +| `nmcli connection reload` | Reload all connection files from disk | |
| 163 | + |
| 164 | +#### Device Management Commands |
| 165 | + |
| 166 | +| **Command** | **Description** | |
| 167 | +| :----------------------------------------------- | :------------------------------------------------- | |
| 168 | +| `nmcli device status` | Show status of all devices | |
| 169 | +| `nmcli device show "DEVICE"` | Show detailed info for specific device | |
| 170 | +| `nmcli device disconnect "DEVICE"` | Disconnect from a device | |
| 171 | +| `nmcli device wifi list` | List all available Wi-Fi networks | |
| 172 | +| `nmcli device wifi connect "SSID" password "PWD"`| Connect to password-protected Wi-Fi | |
0 commit comments