Skip to content

Anass-23/NetworkManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

NetworkManager

NetworkManager, nmcli essential guide

Table of Contents

  1. 1) connection
    1. Show details of connection profiles
    2. Up, activate a connection on a device
    3. Down, deactivate a connection from a device
    4. Add a new connection profile
    5. Modify one or more properties of a connection profile
    6. Clone an existing connection profile
    7. Delete a connection profile
    8. Reload all connection files from disk
    9. Load or reload one or more connection files from disk.
  2. 2) device
    1. Show details of device(s)
    2. Status for all devices
    3. Set device properties.
    4. Connect the device.
    5. Disconnect the device
    6. Modify one or more properties on an active device
    7. Delete the software devices
    8. Perform operation on Wi-Fi devices
  3. 3) general
    1. Show overall status of NetworkManager.
  4. 4) networking
    1. Switch networking on.
    2. Switch networking off.
    3. Get network connectivity state.
  5. 5) radio
    1. Get status of all radio switches, or turn them on/off.
    2. Get status of Wi-Fi radio switch, or turn it on/off.
    3. Get status of mobile broadband radio switch, or turn it on/off.
This document contains the essential information for using ***NetworkManager***, a basic instruction guide set for operating with ***nmcli***.

For fully detailed information, please see man nmcli.

1) connection

Show details of connection profiles

nmcli con show [--active, --show-secrets] [id | uuid | path] <ID>

The flag '–active' will only show the profiles of the current active profiles.

For displaying also the associated secrets use the '–show-secrets' option.

Up, activate a connection on a device

nmcli con up ifname <ifname> [ap <BSSID>] [nsp <name>] [passwd-file <file with passwords>]

Down, deactivate a connection from a device

nmcli con down [id | uuid | path | apath] <ID>

Add a new connection profile

This option is crucial since we manually define an entire profile for an interface.

The basic interfaces we'll be defining are

  • Ethernet profiles
  • Wi-Fi profiles
  • Bridge (master device) profiles
  • Bridge Slaves (slave devices) profiles

By adding a new connection profile we can define many properties (everything on the man page) as the IPv4 addresses and gateways, automatic addresses (from the DHCP) for dynamic IPs or static IPs with manual configuration, we can define the DNS configuration, and so on.

Basic properties:

  1. con-name: The connection profile name
  2. ifname: The interface name where the profile will be applied
  3. type: The type of profile (ethernet, wifi, bridge, bridge-slave, …)
  4. ipv4.addresses (or ip4): The IPv4 address
  5. ipv4.gateway (or gw4): The IPv4 gateway adress
  6. ssid: The SSID of a network (also if it is hidden)
  7. wifi-sec.key-mgmt: The key management as wpa-psk (preshared-key), wpa-eap, …
  8. wifi-sec.psk: The SSID preshared key (the "password" of the wifi network)

Examples:

  • Define a ethernet profile

    nmcli con add con-name ethProfile ifname eth0 type ethernet ip4 192.168.1.14/24 gw4 192.168.1.1
    
  • Define a wifi profile

    nmcli con add con-name wifiProfile ifname wl0 type wifi ip4 192.168.1.14/24 gw4 192.168.1.1 ssid "MiFibra-5C60" wifi-sec.key-mgmt wpa-psk wifi-sec.psk "password"
    
  • Define a bridge profile

    nmcli con add con-name myBridge type bridge ip4 192.168.1.14/24 gw4 192.168.1.1
    
  • Define a bridge-slave profile

    nmcli con add con-name brSlave type bridge-slave ifname eth0 master myBridge
    

Modify one or more properties of a connection profile

nmcli con modify [id | uuid | path] <ID> ([+|-]<setting>.<property> <value>)+

Clone an existing connection profile

nmcli con clone [--temporary] [id | uuid | path] <ID> <new name>

Delete a connection profile

nmcli con delete [id | uuid | path] <ID>

Reload all connection files from disk

nmcli con reload

Load or reload one or more connection files from disk.

nmcli con load <filename>

2) device

Show details of device(s)

nmcli dev show [<ifname>]

The command lists details for all devices, or for a given device.

Status for all devices

nmcli dev status

By default, the following columns are shown:

  • DEVICE - interface name
  • TYPE - device type
  • STATE - device state
  • CONNECTION - connection activated on device (if any)
DEVICE TYPE STATE CONNECTION
ens33 ethernet connected Wired connection 1
lo loopback unmanaged --

Set device properties.

nmcli dev set [ifname] ifname [autoconnect {yes | no}]
nmcli dev set [ifname] ifname [managed {yes | no}]

Connect the device.

nmcli dev connect [<ifname>]

NetworkManager will try to find a suitable connection that will be activated.

It will also consider connections that are not set to auto-connect.

Disconnect the device

nmcli dev disconnect [<ifname>]

The command disconnects the device and prevents it from auto-activating further connections without user/manual intervention.

Modify one or more properties on an active device

Modify one or more properties currently active on the device without modifying the connection profile. The changes have immediate effect.

nmcli dev modify <ifname> ([+|-]<setting>.<property> <value>)+

NOTE: The changes do not modify the connection profile!

Delete the software devices

nmcli dev delete [<ifname>]

The command removes the interfaces. It only works for software devices like:

  • Bonds
  • Brigdes
  • etc.

NOTE: Hardware devices cannot be deleted by the command!

Perform operation on Wi-Fi devices

  • List available Wi-Fi access points

    nmcli dev wifi list [ifname <ifname>] [bssid <BSSID>] [--rescan yes|no|auto]
    

    The options 'ifname' and 'bssid' can be used for listing and showing APs (access points) for a particular 'ifname'.

    The –rescan flag tells if a new scan should be done for listing APs.

  • Connect to a Wi-Fi network specified by SSID or BSSID

    sudo nmcli dev wifi connect connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]
    		[bssid <BSSID>] [name <name>] [private yes|no] [hidden yes|no]
    

    The most common use would be:

    sudo nmcli dev wifi connect <"SSID"> password <"PASSWORD">
    

    And for security purposes, for not displaying the 'SSID' network password we should run:

    sudo nmcli --ask dev wifi connect <"SSID">
    
  • Re-scan for available access points.

    nmcli dev wifi rescan [ifname <ifname>] [[ssid <SSID to scan>] ...]
    

    The option 'ssid' allows scanning for a specific SSID, which is useful for APs with hidden SSIDs.

    NOTE: Performing a rescan would not show the APs!

  • Create a Wi-Fi hotspot

    nmcli dev wifi hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>]
    		[band a|bg] [channel <channel>] [password <password>]
    

    Parameters:

    • ifname: Wi-Fi device to use
    • con-name: Hotspot connection profile name
    • ssid: SSID of the hotspot
    • band: Wi-Fi band to use
    • channel: Wi-Fi channel to use
    • password: Password for the hotspot

    NOTE: Use 'connection down' or 'device disconnect' to stop the hotspot.

  • Show a password of an interface

    nmcli dev wifi show-password <ifname>
    

3) general

Show overall status of NetworkManager.

We can check the status by doing:

nmcli gen status

Or also:

nmcli gen

4) networking

Switch networking on.

nmcli net on

Switch networking off.

nmcli net off

Get network connectivity state.

nmcli net connectivity [check]

The optional check argument makes NetworkManager re-check the connectivity.

Possible states are:

  • none: The host is not connected to any network.

  • portal: The host is behind a captive portal and cannot reach the full Internet.

  • limited: The host is connected to a network, but it has no access to the Internet.

  • full: The host is connected to a network and has full access to the Internet.

  • unknown: The connectivity status cannot be found out.

5) radio

Get status of all radio switches, or turn them on/off.

nmcli radio all [on | off]

Get status of Wi-Fi radio switch, or turn it on/off.

nmcli radio wifi [on | off]

Get status of mobile broadband radio switch, or turn it on/off.

nmcli radio wwan [on | off]

About

NetworkManager, nmcli essential guide

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published