Redhat – Configuring network interfaces – nmcli

redhat

NetworkManager Command Line Interface – The nmcli is a command-line utility which is used for controlling NetworkManager and reporting network status.

View status of physical network device attached to a system

  • [root@centos9vm ~]# nmcli device status

DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
lo loopback connected (externally) lo

Verify connection status

  • [root@centos9vm ~]# nmcli conn show
    • This will show the existing connection, may be names as ens160

One network interface can be configured with multiple connections, but only one will be active. The active connection can be verified by using the following connection:

  • [root@centos9vm ~]# nmcli conn show –active
    • The ens160 connection will be shown as active

How to another new IP address to an interface

  • [root@centos9vm ~]# nmcli connection add con-name myconnection type ethernet ifname ens160 ipv4.address 192.168.0.132/24 ipv4.gateway 192.168.154.1
  • [root@centos9vm ~]# nmcli conn show
    • The active connection ens160 will be highlighted
  • [root@centos9vm ~]# nmcli conn show –active
    • Out of the existing connections only one will be displayed, ens160
  • [root@centos9vm ~]# nmcli conn up myconnection
    • This will make myconnection as active
  • [root@centos9vm ~]# nmcli conn show –active
    • Out of the existing connections only one will be displayed, myconnection
  • [root@centos9vm ~]# nmcli conn up ens160
    • This will make ens160 active

Below command modifies an existing connection:

  • [root@centos9vm ~]# nmcli conn mod myconnection ipv4.address 192.168.0.210/24 ipv4.gateway 192.168.0.1
  • [root@centos9vm ~]# nmcli conn down myconnection
  • [root@centos9vm ~]# nmcli conn up myconnection

Below command disconnects a device and brings is back

  • [root@centos9vm ~]# nmcli device disconnect ens160
  • [root@centos9vm ~]# nmcli device connect ens160