In CentOS 7 Linux, the default networking service is provided by a dynamic network control and configuration daemon named NetworkManager. The NetworkManager tries to keep network devices and connections up and active when they are available. Although NetworkManager is a new and active service for controlling network in CentOS 7 Linux, the traditional ifcfg type configuration files are still supported.
There are four methods to configure network in Centos 7:
- Using nmtui
- Using nmcli – network manager command line interface
- Modifying sysconfig files
- Using Graphical User Interface
In this article, we will go over two of the methods presented above, with a future article discussing the others coming soon.
NMTUI stands for Network Manager Text User Interface. It is a tool that provides a text interface to configure Centos 7 network by controlling NetworkManager.
First of all, we should check if the NetworkManager service is installed or not. Run the following command to check if the service is installed: rmp -qa | grep NetworkManager.
The output should be similar to this:
This package is installed by default on Centos 7. In case it is missing, nmtui is contained in the NetworkManager-tui package. To install it, run the following command: yum -y install NetworkManager-tui
Before doing any changes to the network configuration, check if the daemon is up and running. To do this, use systemctl to check the daemon’s status: systemctl status NetworkManager. Output should be similar to this:
To run the tool, issue the following command: nmtui
In this window, use the tab, up, down, left and right keys to navigate through the options.
To change an interface’s IP address, select “Edit a connection” option and select the interface which will be modified.
In the above image, the configuration is set to automatic. In this case, the IP is assigned dynamically through DHCP from a pool of available IP addresses. Dynamic IPs may change over time. If you want to set up a static IP (one which will not change over time), change the option from “Automatic” to “Manual”. After this, the “Address”, “Gateway”, “DNS servers” fields need to be configured with valid options.
For my machine, before modifying the network configuration, the IP is 192.168.43.41 (which is dynamically assigned).
In the image below, I’ve modified the configuration options, setting a new (static) IP address 192.168.43.99
After restarting the network daemon, the configuration has been validated, changing the machines IP address.
Changing network configuration through sysconfig files
Another way in which an administrator can change network configuration options is to modify the sysconfig files. These files are located in /etc/sysconfig/network-scripsts/
Interface configuration (ifcfg) files control the software interfaces for individual network devices. These files are used by the operating system to determine what interfaces should be brought up and how to configure them. Their name is follow the format ifcfg-name, where the suffix name is the name of the device that the configuration file controls.
To configure an interface with a static IP, for an interface names enp0s3, create or edit the file ifcfg-enp0s3 in the /etc/sysconfig/network-scripts/ :
A description of some of these configuration parameters follows:
- TYPE=device_type : type of the network interface device
: where protocol
is one of the following
- none : no boot-time protocol is used
- bootp : bootstrap protocol
- dhcp : use Dynamic Host Configuration Protocol
- yes : this interface is set as the default route for IPv4/6 traffic
- no : this interface is not set as default route
yes : enable IPv6 on this interface. In this case, the following
parameters could also be set :
- no : disable IPv6 on this interface
- yes : enable IPv6 on this interface. In this case, the following parameters could also be set :
answer is one of the following:
- yes : this interface is disabled if IPv4/6 configuration fails
- no : this interface is not disabled if configuration fails
- yes : this interface is activated at boot time
- no : this interface is not activated at boot time
- HWADDR=mac_address : hardware address (MAC address) of the ethernet device
In this case, the IP address is dynamically assigned. To set a static IP, we need to set BOOTPROTO to none (or comment the line entirely) and set valid IP addresses in the IPADDR and GATEWAY parameters. As an example, observe the following image: