nmcli

nmcli is a command-line interface for managing NetworkManager, a tool used to manage network connections on Linux-based systems. It provides a convenient way to configure network interfaces, Wi-Fi connections, VPNs, and other networking configurations directly from the command line.

Key Features and Subcommands

Here’s a breakdown of some common nmcli commands and their usage:

1. nmcli general

Used to display general system network settings and manage NetworkManager.

  • Show general status of NetworkManager:

    nmcli general status

    This command shows the overall status of NetworkManager (e.g., whether it's running).

  • Show the NetworkManager version:

    nmcli general version
  • Enable/Disable NetworkManager:

    nmcli general enable
    nmcli general disable

2. nmcli device

Manages network devices and shows their status.

  • Show all network devices:

    nmcli device status

    Displays the status of all network devices (e.g., Ethernet, Wi-Fi, etc.).

  • Bring a device up or down:

    nmcli device connect eth0
    nmcli device disconnect eth0
  • Show detailed information about a device:

    nmcli device show eth0
  • Change device connection:

    nmcli device wifi connect SSID password "yourpassword"

3. nmcli connection

Used to manage network connections (Ethernet, Wi-Fi, VPN, etc.).

  • Show all connections:

    nmcli connection show
  • Show a specific connection:

    nmcli connection show <connection-name>
  • Activate a connection:

    nmcli connection up <connection-name>
  • Deactivate a connection:

    nmcli connection down <connection-name>
  • Add a new Wi-Fi connection:

    nmcli connection add type wifi ifname wlan0 con-name mywifi autoconnect yes ssid MySSID
  • Delete a connection:

    nmcli connection delete <connection-name>
  • Edit a connection:

    nmcli connection modify <connection-name> ipv4.addresses 192.168.1.100/24

4. nmcli networking

Used to control the overall networking status.

  • Enable or disable networking:

    nmcli networking off
    nmcli networking on

5. nmcli radio

Used to control the wireless radio (Wi-Fi) state.

  • Enable Wi-Fi radio:

    nmcli radio wifi on
  • Disable Wi-Fi radio:

    nmcli radio wifi off
  • Enable/Disable Bluetooth radio:

    nmcli radio bluetooth on
    nmcli radio bluetooth off

6. nmcli vpn

Manages VPN connections.

  • Show VPN connections:

    nmcli vpn show
  • Add a VPN connection:

    nmcli connection add type vpn vpn-type openvpn con-name myvpn ifname -- vpn-service-type org.freedesktop.NetworkManager.openvpn
  • Activate a VPN connection:

    nmcli connection up myvpn

7. nmcli monitor

Monitors network status in real-time.

  • Monitor changes to connections:

    nmcli monitor

This command will keep the terminal open and monitor any network changes in real-time.

8. nmcli wifi

Manages Wi-Fi connections and networks.

  • List available Wi-Fi networks:

    nmcli device wifi list
  • Connect to a Wi-Fi network:

    nmcli device wifi connect SSID password "yourpassword"
  • Disconnect from the current Wi-Fi network:

    nmcli device disconnect wlan0

Examples of nmcli Usage

  1. Check the current connection status:

    nmcli connection show --active
  2. Change the IP address of an interface:

    nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.0.100/24
  3. Create a new Ethernet connection:

    nmcli connection add type ethernet con-name "MyEthernet" ifname eth0 ipv4.addresses 192.168.0.101/24
  4. Enable and disable Wi-Fi:

    nmcli radio wifi off
    nmcli radio wifi on
  5. Activate or deactivate a connection:

    nmcli connection up "MyWifi"
    nmcli connection down "MyWifi"

Conclusion

nmcli is a powerful and flexible tool for managing network connections on Linux systems. Whether you're configuring an Ethernet connection, connecting to Wi-Fi, managing VPNs, or even controlling network device states, nmcli provides a comprehensive set of commands to handle all your network configuration needs from the command line.

Last updated