How to use nmcli to add new Ethernet connection?
Environment
- Red Hat Enterprise Linux 7 and Above
- NetworkManager
Issue
- How to use nmcli to add an Ethernet connection with manual or via DHCP configuration?
Resolution
- Use nmcli with the object
connection
and commandadd
. (This can be abbreviated to con add). The first step should be to have the latest version ofNetworkManager
package, thus upgrade the same if its not latest;
# yum update NetworkManager
-
Another suggested package is to have the latest version of
bash-completion
for auto-completion ofnmcli
command when tab key is pressed. This helps in displaying availablenmcli
command options on screen and reduces the chances of an administrator manually adding wrong options. -
To setup ethernet, configure following command options:
- con-name - The connection name is the name of a connection profile and should not be confused with the interface name that denotes a device
- ifname - Interface name
- type - Allowed values are: ethernet, wifi, wimax, gsm, cdma, infiniband, bluetooth, vlan, bond, bond-slave
- ipv4.method - To specific if interface configuration is via
dhcp
(auto
) or static (manual
). - ipv4.address - IPv4 address in CIDR representation.
- ipv4.gateway - IPv4 Gateway address.
- ipv6.address - IPv6 address(optional if IPv6 enabled)
IP configuration via DHCP
# nmcli connection add type ethernet ifname <interface-name> con-name <connection-name> ipv4.method auto
Static IP configuration
# nmcli connection add type ethernet ifname <interface-name> con-name <connection-name> ipv4.method manual ipv4.address <IP>/<prefix> ipv4.gateway <GW-address>
- DNS nameservers can only be added after the connection has already been created.
# nmcli connection modify <connection-name> ipv4.dns "DNS1-IP DNS2-IP"
- Bring UP or the load the configuration.
# nmcli connection up <connection-name>
Root Cause
-
The
NetworkManager
command line tool,nmcli
, provides those who prefer to use the command line way to configure networking by controlling NetworkManager. It is installed along with NetworkManager. -
More information can be found at 7.3. Network Bonding Using the NetworkManager Command Line Tool, nmcli or nmcli(1), nmcli-examples(5)
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.
Comments