Basic Network Configuration

The default network service in Red Hat Enterprise Linux 7 and CentOS 7 is provided by NetworkManager (formerly known as Network), a daemon that dynamically controls and configures the network. It is used to keep current network devices and connections working. It provides tools such as nmCLI (command line tool for configuring the network) that make it easy to manage the network.

The NetworkManager configuration file is stored in /etc/sysconfig/network-scripts/.

Multiple connections can exist for any one device to facilitate switching between devices, but only one connection can be active at any one time.

The device refers to the network interface, and the connection represents the set of Settings that can be configured for the device.

Viewing Network Information

The nmcli dev status command displays the status of all network devices.

The nmcli con show command displays a list of all connections. If only active connections are listed, add the –active option.

Adding a Network Connection

Nmcli con add Is used to add a new network connection.

Control network connection

The nmcli con up command activates the specified connection by specifying the name of the connection instead of the name of the network interface.

The nmcli dev dis command is used to close the connection of the network interface. You can specify the name of the network interface to close the connection.

Modify the connection configuration file

NetworkManager connections have two types of Settings, one is static connection, which is configured by the administrator and stored in the /etc/sysconfig/network-scripts/ifcfg-* configuration file, and the other is active connection data. The data is obtained from the DHCP server and does not persist. To view the information, run the nmcli con show (with connection name) command.

The nmcli con mod command is used to change the connection Settings, and these changes are saved to the corresponding configuration file (/etc/sysconfig/network-scripts/ifcfg-*).

Deleting a Network connection

The nmcli con del command can be used to delete the connection, delete the corresponding configuration file, disconnect the connection from the device, and delete the connection by specifying the name.

Summary of common key NmCLI commands

The command use
nmcli dev status The NetworkManager status of all network interfaces is displayed
nmcli con show List all connections
nmcli con show name Lists the current configuration for the connection named Name
nmcli con add con-name name Add a new connection named name
nmcli con mod name Example Modify the configuration of connection name
nmcli con reload The configuration file was reloaded
nmcli con up name Activate the connection named name
nmcli dev dis dev Deactivate dev’s network interface and disconnect the current connection
nmcli con del name Delete the connection and configuration file named name, and disconnect the current connection

Edit a network configuration file

The configuration modified by using the nmcli con mod command is automatically saved to the corresponding configuration file, but you can also manually modify the configuration file and restart the configuration.

The configuration file is stored in /etc/sysconfig/network-scripts/ and is named ifcfg-name.

Using nmcli versus modifying files directly

nmcli con mod Ifcfg – * files impact
ipv4.mothod manual BOOTPROTO=none IPv4 is configured in static mode
ipv4.mothod auto BOOTPROTO=dhcp Look for the configuration from the DHCPv4 server. If a static address is also set, the static address will not be activated until the information is obtained from the DHCP server
Ipv4. addresses “192.0.0.1/24 192.0.2.254” (Older versions may need to use ipv4.gateway separately) 24 GATEWAY IPADDR = 192.0.2.1 PREFIX = = 192.0.2.252 Set the static IPv4 address, network prefix, and default network. If multiple IPv4 addresses are configured, the values end with 1, 2, and 3 in sequence
Ipv4. DNS 8.8.8.8 DNS = 8.8.8.8 Modifying a DNS Server
ipv4.dns-search example.com DOMAIN=example.com Set the DOMAIN
ipv4.ignore-auto-dns true PEEERDNS=no Ignore the DNS server information from the DHCP server
ipv6.method manual IPV6_AUTOCONF=no The IPv6 address is configured in static mode
ipv6.method IPV6_AUTOCONF=yes Use SLAAC in router broadcast to configure network Settings
ipv6.method dhcp IPV6_AUTOCONF=no DHCPV6C=YES Use DHCPv6 instead of SLAAC to configure network Settings
ipv6.addresses “2001:db8::a/64 2001:db8::1” IPV6ADDR=2001:db8::a/64 IPV6_DEFAULTGW=2001:db8::1 Set the static IPv6 address, network prefix, and default gateway. If multiple IP addresses are set, separate them with Spaces
ipv6.dns … DNS= … With IPv4
ipv6.dns-serach … DOMAIN=… With IPv4
ipv6.ignore-auto-dns true IPV6_PEERDNS=no Ignore the DNS information from the DHCP server
connection.autoconnect yes ONBOOT=yes This connection is automatically activated when the system boots
connection.id exx NAME=exx The name of this connection
connection.interface-name ens3 DEVICE=ens3 The connection is bound to a network interface with this name
802-3-ethernet.mac-address … HWADDR= … The connection is bound to the network interface that has this MAC address