Ultimate nmcli Cheat Sheet for Linux Network Management - howtouselinux (2024)

By: Author David Cao

Posted on Last updated:

1 Comment

Categories DevOps, Linux

Table of Contents

Introduction to the nmcli Command

The nmcli command is a powerful command-line tool in Red Hat Enterprise Linux (RHEL) used to manage network connections through the NetworkManager service.

It provides a comprehensive interface for configuring, monitoring, and troubleshooting various network aspects, from basic Ethernet connections to advanced features like bonding, VLAN tagging, and more.

Key Capabilities of nmcli:

  • Device Management: nmcli lets you view the status of network devices, including their type, state, and connection information. It allows you to temporarily disable NetworkManager’s control over a device, enabling manual configuration if required.
  • Connection Profile Management: A central concept in NetworkManager is the connection profile, which stores all settings for a network connection. nmcli enables you to:
    • List all existing connection profiles.
    • Show details of a specific profile, including IP configuration, DNS settings, gateway, and more.
    • Create new connection profiles for various connection types (Ethernet, Wi-Fi, bonds, VLANs, etc.).
    • Modify existing profiles to change settings like IP addresses, DNS servers, or gateway.
    • Activate and deactivate profiles, bringing connections online and offline.
    • Rename and delete connection profiles.
  • Advanced Configuration: nmcli extends beyond basic connectivity to configure advanced networking features:
    • Bonding: Create and manage bonded interfaces, including setting the bonding mode and adding slave interfaces.
    • VLAN Tagging: Create and configure VLAN interfaces, specifying the parent interface and VLAN ID.
    • Static Routes: Add static routes to specific connection profiles, controlling network traffic flow.
    • Ethtool Settings: Fine-tune network interface card (NIC) parameters like offload features, interrupt coalescing settings (for optimizing performance), and ring buffer sizes.
  • Offline Mode: nmcli can operate in offline mode, allowing you to create and modify connection profiles even when the NetworkManager service is not running. This is valuable for pre-configuring network settings or working in environments where NetworkManager is unavailable.

Why Use nmcli?

  • Command-Line Control: nmcli offers a non-graphical way to manage network settings, making it ideal for headless servers or remote administration.
  • Scripting and Automation: The command-line nature of nmcli makes it well-suited for scripting and automation, enabling you to manage network configurations programmatically.
  • Detailed Information: nmcli commands often provide more detailed information than graphical tools, which can be essential for troubleshooting.

Alternatives to nmcli:

  • Graphical Tools: RHEL provides graphical applications like nm-connection-editor and nmtui for network management. These tools offer a more user-friendly interface but may not expose all the configuration options available through nmcli.
  • Network RHEL System Role (Ansible): This Ansible role provides a way to manage network settings in an automated and repeatable manner.
  • nmstate API: This declarative API offers a programmatic way to manage network configuration, ensuring consistency and providing rollback capabilities.

The choice of tool depends on your specific needs and preferences. nmcli provides a balance of power, flexibility, and scripting capabilities for managing network connections in RHEL.

Here’s a comprehensive nmcli cheat sheet based on the sources you’ve provided. It’s organized by key functionalities within NetworkManager to give you a structured overview of common operations:

Get Your Free Linux training!

Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!

General Network Management

  • List Network Interfaces:
    # nmcli device status

    This command shows you the status of all network devices recognized by NetworkManager, including their type, current state, and associated connection.

  • List Connection Profiles:
    # nmcli connection show

    This command lists all configured network connection profiles, providing details like the profile name, UUID, type (e.g., Ethernet, Wi-Fi), and the associated device.

  • Show Details of a Connection Profile:
    # nmcli connection show <connection_name>

    Replace <connection_name> with the actual name of the profile (e.g., ‘Wired connection 1’). This command provides a detailed view of the connection profile settings, including IP configuration, DNS, gateway, and more.

  • Activate a Connection:
    # nmcli connection up <connection_name>

    This command activates the specified connection profile.

  • Deactivate a Connection:
    # nmcli connection down <connection_name>

    This command deactivates the specified connection profile.

  • Modify a Connection Profile:
    # nmcli connection modify <connection_name> <property> <value>

    This is a versatile command to modify settings within a connection profile. Replace <property> with the setting you want to change (e.g., ipv4.method, ipv4.addresses, ipv6.gateway) and <value> with the new value.

  • Delete a Connection Profile:
    # nmcli connection delete <connection_name>

    Use this command to remove a connection profile.

  • Rename a Connection Profile:
    # nmcli connection modify "<old_name>" connection.id "<new_name>"

    This command renames a connection profile from <old_name> to <new_name>. Use quotes around names that contain spaces.

Ethernet Connections

  • Add an Ethernet Connection (DHCP):
    # nmcli connection add con-name <connection_name> ifname <device_name> type ethernet

    This creates a new Ethernet connection profile with a default DHCP configuration.

  • Add an Ethernet Connection (Static IP):
    # nmcli connection add con-name <connection_name> ifname <device_name> type ethernet \ ipv4.method manual ipv4.addresses <IP_address>/<subnet_mask> ipv4.gateway <gateway_IP> \ ipv4.dns <DNS_server_IP>
  • Temporarily Disable NetworkManager Management for a Device:
    # nmcli device set <device_name> managed no

    This command tells NetworkManager to stop managing the specified device, allowing you to configure it manually if needed.

Network Bonding

  • Create a Bond Interface:
    # nmcli connection add type bond con-name <bond_name> ifname <bond_name>

    This command creates a bond interface named <bond_name>.

  • Set the Bonding Mode:
    # nmcli connection modify <bond_name> bond.mode <mode>

    Replace <mode> with the desired bonding mode (e.g., active-backup, balance-rr, 802.3ad). Refer to the bonding modes section of this cheat sheet for explanations of the different modes.

  • Add Slave Interfaces to the Bond:
    # nmcli connection add type ethernet port-type bond con-name <bond_name>-port<number> ifname <interface_name> controller <bond_name>

    Repeat this command for each interface you want to add to the bond, incrementing the <number> and replacing <interface_name> with the actual interface name.

VLAN Tagging

  • Create a VLAN Interface:
    # nmcli connection add type vlan con-name <vlan_name> dev <parent_interface> id <VLAN_ID>

    Replace <vlan_name> with the desired VLAN interface name, <parent_interface> with the physical interface on which the VLAN is based, and <VLAN_ID> with the VLAN identifier.

Static Routes

  • Add a Static IPv4 Route:
    # nmcli connection modify <connection_name> +ipv4.routes "<destination_network>/<subnet_mask> <gateway_IP>"

    This command adds a static route to the specified connection profile.

  • Add a Static IPv6 Route:
    # nmcli connection modify <connection_name> +ipv6.routes "<destination_network>/<prefix_length> <gateway_IP>"

Advanced Network Configuration

  • Ethtool Settings (Offload Features):
    # nmcli con modify <connection_name> ethtool.feature-<feature> on|off

    Replace <feature> with the specific offload feature you want to enable or disable (e.g., rx, tx, sg). This command allows you to manage offload features on the network interface.

  • Ethtool Settings (Coalesce Settings):
    # nmcli connection modify <connection_name> ethtool.coalesce-<parameter> <value>

    Replace <parameter> with a coalesce setting like rx-frames, tx-frames, rx-usecs, and <value> with the desired numerical value. This allows you to control interrupt coalescing behavior.

  • Ethtool Settings (Ring Buffer Size):
    # nmcli connection modify <connection_name> ethtool.ring-<parameter> <value>

    Replace <parameter> with either rx or tx to adjust the receive or transmit ring buffer sizes. Increasing the buffer size can potentially reduce packet drops.

nmcli Interactive Mode

  • Enter Interactive Mode:
    # nmcli connection edit <connection_name>

    This enters an interactive shell for the specified connection, allowing for step-by-step configuration.

  • Set a Property:
    nmcli> set <property> <value>
  • Print Current Settings:
    nmcli> print
  • Save Changes:
    nmcli> save persistent

    Persists the changes to the connection profile.

  • Activate Connection:
    nmcli> activate
  • Exit Interactive Mode:
    nmcli> quit

This cheat sheet covers a wide range of commonly used nmcli commands for network management in RHEL. You can refer to the man pages for more detailed information and options for each command.

Ultimate nmcli Cheat Sheet for Linux Network Management - howtouselinux (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 5259

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.