Linux networking Using NMCLI

There are multiple articles in this site related to Linux networking, based on ifcfg configurations and ifconfig commands. This article is focused on Network Manager CLI, called as “nmcli”.  nmcli is a command‐line tool to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.

Here is the usage instructions of “nmcli”. The ojbects that can be controlled by this utility is – general, networking, radio, connection, device and agent.

This article will primarily focus on device and connection objects. To list all network interfaces in the system, use the “nmcli device” command.

To know the details of an interface, like mac, mtu, ipaddress, state, dns resolvers, domainname and gateway, use the “nmcli device show” command.

To disconnect an interface and make it unpingable, use the “device disconnect” command. This command will disconnect a device and prevent the device from automatically activating further connections without user/manual intervention. It should be noted that changes made with nmcli are persistent – NetworkManager will write them to the files on disk.

To Enabling the interface, use the “device connect” command. NetworkManager will try to find a suitable connection that will be activated. It will also consider connections that are not set to auto connect.

NetworkManager stores all network configuration as connections, which are collections of data (Layer2 details, IP addressing, etc.) that describe how to create or connect to a network.  A connection is active when a device uses that connection’s configuration to create or connect to a network.  There may be multiple connections that apply to a device, but only one of them can be active on that device at any given time. The additional connections can be used to allow quick switching between different networks and configurations.

To see a list of connections available and the detail of a specific connection, use the below commands.

NetworkManager is not automatically aware of the change that are made to ifcfg files manually. For example, if configuration files have been changed using an editor, NetworkManager must be told to read the configuration files again. To do that, issue the following command.

Setting IP using NMCLI : To add a connection and set ipv4 properties, use the “nnmcli connection add type ethernet” command.

Bonding using NMCLI : Network bonding also can be configured using nmcli. To enable bonding, load the bonding module and create the bond (bond0) as specified in this example.

This will create the bond0 and now to add the slave interface to the bond, use the following bond-slave commands.

Enable the slaves and the bond.

Now you can set an IP address to the bond and start using it. Hope this helps in starting to use nmcli as an alternative to the commands we have been using to manage the Linux networking.