How to configure IP addressing with NetworkManager (nmcli)

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • NetworkManager

Issue

  • Need to configure a static IP on an interface in RHEL 7/8
  • Want to assign an IP address to a NIC.

Resolution

  • To begin, it is best to remove any existing connection profiles which are associated with the interface to be used. The following command will list all the existing connection profiles (connection.id) as well as any interface and MAC address they are associated with (connection.interface-name and 802-3-ethernet.mac-address). If there are any matches for the interface to be used, delete the matching profile (or at least set its connection.autoconnect property to no and note the profile name so it is not accidentally reused):

    # for connection in $(nmcli -t --fields uuid con) ; do echo ; nmcli con show uuid $connection | egrep "connection.id|connection.interface-name|802-3-ethernet.mac-address:" ; done
    
  • If an existing profile needs to be removed, do so with the following command where $PROFILE is the connection.id seen in the output from the command above:

    # nmcli connection del "$PROFILE"
    

Dynamic addressing with DHCP

  • Create a new connection profile using nmcli. Simply specify a name for the connection profile (con-name) and the interface the profile should be applied to (ifname). The connection profile name can match the interface name. The connection will be activated as soon as it is created:

    # nmcli connection add type ethernet con-name connection1 ifname eno1
    Connection 'connection1' (45bbd382-c6f0-4cbf-af80-625c7ce564da) successfully added.
    

Static addressing

  • Create a new connection profile using nmcli. Specify a name for the connection profile (con-name), the interface the profile should be applied to (ifname), the IP address (ip4) and optionally, the gateway (gw4). The IP address must be specified with the network prefix. The connection profile name can match the interface name. The connection will be activated as soon as it is created:

     # nmcli connection add type ethernet con-name connection2 ifname eno2 ip4 192.168.100.10/24 gw4 192.168.100.1
     Connection 'connection2' (4cb72f52-dbca-422a-8eae-b2f107513bc8) successfully added.
    # nmcli connection m connection2 ipv4.method manual
    

Root Cause

  • It can be confirmed to be working by checking command output from tools such as ip address and nmcli connection show connection1.

  • ip address shows the current state of every network interface recognized by the system and its IP addressing (if any):

    # ip address
    
  • nmcli connection show "connection name" will show all properties of a connection profile. If the profile is active, it will show the active parameters as well (given in upper case at the end of the output):

    # nmcli connection show "my connection"
    

Diagnostic Steps

  • Confirm the system is using NetworkManager:

    # systemctl status NetworkManager.service
    
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.