Open In App

How to configure network interfaces in CentOS?

A network interface is a link between a computer and another network(Private or Public). The network interface is basically a card which is known as NIC or Network Interface Card, this does not necessarily have to be in a physical form instead, it can be inbuilt into the software. If we take the example of some loopback addresses such as and ::1(IPv6), these are not in physical structure but they are pieces of code written on the system.

There are two ways to Configure network interfaces in CentOS:

Both ways will be discussed in the article. But before starting that let us first understand a little bit about how the Network Interface naming works so that the different network names don’t sound weird to us.

Network Interface naming

While naming the network interfaces, the virtual and physical aspects of them are considered. The names assigned to the physical networks are based on the slot number given on the adapter. Virtual interfaces are named by the combination of interface name and VLAN ID. The names of the physical interfaces are assigned on the basis of the slot where the adapter is installed. The physical interfaces are identified by the following format:

e <slot_number_on_adapter> <port_number_of_adapter>

Interface group names

These group names are user specifies and they must follow the below criteria:

The Format of the VLAN interface is as follows;


Below are some examples of interface names, formats, and their examples:

  1. The physical interface on a single port adapter: e0,e1
  2. The physical interface on a multiple port adapter: e0c,e0d
  3. Interface group: web_ifgrp, ifgrp3
  4. VLAN: ifgrp1-2, e7-2

Now let us discuss the ways to configure the network interfaces.

Method 1: The Command line way

We will be configuring network interfaces for static Ip and DHCP. It is noteworthy that in older versions of CentOS(below CentOS 9) the configuration files for the network were stored in ifcfg format but now that method is deprecated. The newer version of CentOS follows keyfile system. Below given is the difference in the format of both versions:


Since the CentOS version in this article is “9” we will be using the key file format of network configuration.  

1. Configuration of  a static IP and DHCP:

Follow the below steps to configure the network interface through CLI:

Step 1: List out all the devices which are present:

For configuring the network, we have to have knowledge of the network devices that our system has, use the below command to list them all:

nmcli  d 


Now that we have found out the device name, we have to edit the network configuration file to set up the network interface. Keep in mind that your system can have a different device name it doesn’t need to be the same as in this article.

Step 2: Visit the network configuration file (which has a keyfile format) 

Change the directory to /etc/NetworkManager/system-connections this is where the keyfile resides. There you can see the current information about your network.

cd  /etc/NetworkManager/system-connections



Step 3: Configuring the Network interfaces:

Let us configure the network interfaces such as IP address, gateway, DNS, and Netmask.

Follow the below commands :

A. Setting IPv4 address.

nmcli connection modify enp0s3 ipv4.addresses  


B. Setting Gateway.

nmcli connection modify enp0s3 ipv4.gateway 


C. Setting DNS.

nmcli connection modify enp0s3 ipv4.gateway
nmcli connection modify enp0s3 ipv4.gateway ""  (For setting multiple DNS)


D. Setting Interface as Static or DHCP:

nmcli connection modify enp0s3 ipv4.method manual( For static it is manual)
nmcli connection modify enp0s3 ipv4.method auto (For DHCP it is auto)


To configure the changes for DHCP just change manual to auto.

Step 4: Shutdown the connection and restart it:

Now that the interfaces are configured let us restart the service, using the below commands.

nmcli connection down enp0s3
nmcli connection down enp0s3


Step 5: Confirm the settings:

Confirm the changes made by typing down the below command:

nmcli device show enp0s3


Method 2: GUI( Graphical user interface way)

Most people are comfortable with the graphical user interface and in this article, we will also cover the GUI approach. Before we proceed you must have the Network Manager tool ( nmtui) so that you can follow the next steps. It can be installed by using the yum package manager.

sudo yum -y install NetworkManager-tui


Now that the Network Manager tool is installed follow the below steps to set the interface through GUI.

Step 1: Open the Network Manager:

After writing the below command a window will appear with some options.



Step 2: Choose to edit a connection and select the link:


Step 3: Add the Network interface information:


In the above image, the IPv4 configuration is set to the manual which means it is for a static IP address, if you want to configure the network as DHCP set it to automatic.


Step 4: Check out a few essential boxes:

Make sure that the following checkboxes are ticked for the smooth function of the network.


Step 5: Save the changes, Exit, and restart the network service.

After all the changes have been made save them and restart the service so that the changes are applied.

service network restart


So this is how the network interfaces can be configured on the CentOS distro using the CLI as well as the GUI method. Hope you like the article.

Article Tags :