=^.^=

Basic Network Interface Confguration with NetworkManager via nmcli

karma
[attachment-qFVVzQ]
nmtui's ncurses interface

Preface

Having discovered nmtui only some time after familiarizing myself with nmcli - under the incorrect assumption that it would be necessary - I am adding this some time since publishing the body of the following article so that you might not make the same error:

I realize that for 99% of readers I am about to kill an article, but better for you to get the goods off the bat than to waste anyone's time. Before we dig into nmcli it would be remiss for me to not inform you of its menu-based ncurses relative that is so much easier that it does not even warrant its own article: nmtui. It is quick and feature-full enough to render knowing nmcli syntax relevant more-or-less exclusively to those looking to implement interfacing with Network Manager within shell scripts.

For those of you remaining so-inclined, I present the following...

Introduction

I have always favoured directly editing network configuration plaintext files (e.g: /etc/sysconfig/network-scripts/ifcfg-ifname on RedHat flavours). However it has for some time been more ideologically correct to manage the network configuration on many distributions via the NetworkManager daemon. More importantly, it is intrusive, obnoxious and annoying to disable NM such that it does not interfere with manual configurations (lookin' at you, Ubuntu). So this is my attempt to find religion.

Unless there is a crazy good reason, I don't do GUIs on servers. nmcli is provided to interface with NetworkManager from the command line. It can be used in CLI (direct) or shell (interactive) mode, as root/via sudo:

CLI

nmcli connection modify eth0 IPv4.address 192.168.0.100/24 nmcli connection modify eth0 IPv4.gateway 192.168.0.1 nmcli connection modify eth0 IPv4.dns 192.168.0.1,8.8.8.8,8.8.4.4 nmcli connection modify eth0 IPv4.method manual

To effect the changes you must raise or reload the interface, using nmcli:
nmcli connection up eth0
or on RedHat flavours simply:
ifup eth0

Note the following:

  • The interface's address is specified in CIDR notation (i.e. including the netmask)
  • Arrays of multiple addresses are defined as comma-delimited lists (e.g: IP1,IP2,IP3). Take care to not include spaces.

The IPv4.method property can be set to any one of: disabled, auto (dhcp), manual or link-local. For a complete list of IPv4 configuration options please see https://developer.gnome.org/NetworkManager/stable/settings-ipv4.html.

IPv6 is configured in the same way; see https://developer.gnome.org/NetworkManager/stable/settings-ipv6.html for IPv6 configuration options and modify your syntax accordingly.

Shell

As root/via sudo:
nmcli connection edit eth0 ===| nmcli interactive connection editor |=== Editing existing '802-3-ethernet' connection: 'eth0' Type 'help' or '?' for available commands. Type 'print' to show all the connection properties. Type 'describe [.]' for detailed property descrIPtion. You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, dcb, sriov, ethtool, match, IPv4, IPv6, tc, proxy nmcli> set IPv4.address 192.168.0.100/24 nmcli> set IPv4.gateway 192.168.0.1 nmcli> set IPv4.dns 192.168.0.1,8.8.8.8,8.8.4.4 nmcli> set IPv4.method manual nmcli> save Connection 'eth0' successfully updated. nmcli> quit

Again the connection must either be reloaded or raised to take effect:
nmcli connection up eth0 or ifup eth0

Comments

There are no comments for this item.