=^.^=

Basic Network Interface Confguration with NetworkManager via nmcli

Introduction

I have always favoured directly editing network configuration flat 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 and obnoxious and annoying to disable such that it does not interfere with manual configurations (lookin' at you, Ubuntu). So this is my attempt to find religion.

Unless there is 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.