The Wayback Machine - https://web.archive.org/web/20240926163922/https://www.geeksforgeeks.org/how-to-configure-network-interfaces-in-centos/
Open In App

How to configure network interfaces in CentOS?

Last Updated : 01 Dec, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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 127.0.0.1(IPv4) 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:

  • The Command line way
  • GUI( Graphical user interface way)

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:

  • They should begin with a letter.
  • Spaces are prohibited.
  • More than 15 characters are not allowed.
  • They must not be in use by any other interfaces. 

The Format of the VLAN interface is as follows;

<name_of_physical_interface>-<vlan_ID> 
<ifgrp_name>-<ID_of_vlan> 

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 10.0.2.15  

 

B. Setting Gateway.

nmcli connection modify enp0s3 ipv4.gateway 10.0.2.2 

 

C. Setting DNS.

nmcli connection modify enp0s3 ipv4.gateway 8.8.8.8
nmcli connection modify enp0s3 ipv4.gateway "8.8.8.8  8.8.4.4"  (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.

nmtui 

 

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.


Previous Article
Next Article

Similar Reads

Configure CGroups in CentOS Linux
"CGroups" or "Control Groups" is a feature of the Linux kernel that allows us to control and restrict system resources (like CPU, memory, disk I/O, and network) for individual processes or groups of related processes. One of the main objectives is to manage and control the resource allocation of processes, ensuring fair and efficient usage of resou
6 min read
CentOS Network Configuration without NetworkManager
As we know, to set up communication between the two systems we have to configure the network which means we have to define system IP, DNS, and gateway the communication can be through either Ethernet, Wi-Fi, or Bluetooth. Therefore a Linux user must know about the Network Configuration of any Linux Operating system so that the user can resolve some
4 min read
How to List Network Interfaces in Linux?
In Linux, a Network Interface serves as the communication link between a computer and a network. It is a crucial component that enables the transmission and reception of data between the system and external networks, such as the Internet or local area networks. Each network interface is associated with a unique identifier, often referred to as the
5 min read
How to reset the root password of RedHat/CentOS Linux
RedHat Linux is a worldwide used OS in servers and networking devices. Red Hat lists Adobe, Ampersand and many among the top 500 fortune companies. They list Cisco, Dell, HP, and IBM as partners. Resetting the root password of RHEL is not a difficult task but rather you need to know 4 commands and you are into the root account! Root account in Linu
2 min read
How to Install Cockpit on Linux CentOS 7?
The cockpit is a free, open-source Linux Server Management Tool which provides you the facility to control your server using the mouse on the web-interface. The cockpit can be used to perform any server related task such as start containers, storage administration, and network configuration and much more. It has a very beautiful user interface alon
3 min read
How to Add New Disk in Linux CentOS 7 Without Rebooting
Let's Say we hosted the DataBase on our Server Initially with 500GB given space and as we know Database should run 24/7 because the user's using it. One day it consumes space about 400GB only 100GB left Now we want to Increase the Space at the runtime only and In the case of static partitioning we need to restart the server but If we restart the se
3 min read
How to Install CentOS
CentOS is a popular open-source Linux distribution aimed at servers and provides compatibility with Red Hat's RPM package manager. It is built with the goal of providing a stable operating system that provided great compatibility with the upstream RHEL (Red hat enterprise Linux) CentOS is therefore one of the best free Linux distributions to utiliz
2 min read
How to Upgrade Linux Kernel on CentOS 7
The kernel is a central component of an operating system that manages the operations of the computer and hardware. It basically manages operations of memory and CPU time. It is a core component of an operating system. Kernel acts as a bridge between applications and data processing performed at the hardware level using inter-process communication a
2 min read
NTP Configuration in CentOS
NTP(Network Transfer Protocol) is a protocol that is used for the synchronization of time over a network. It provides the service of setting the current time on the client's request so that the client can set his clock on his system. There are three tiers of NTP servers: Tier 1: Connected to atomic clocks.Tier 2 and Tier 3: Carry the load of handli
3 min read
How to Compile Linux Kernel on CentOS 7
The kernel is the core of a computer's operating system that has complete control over the system and provides basic services for all other parts. The default kernel available in any distribution cannot be customized. We cannot enable or disable any feature on it. Running a custom-compiled Linux Kernel becomes very helpful in cases when the hardwar
3 min read
How to Audit Linux Process Using ‘autrace’ on CentOS/RHEL
Autrace is a command line tool that is used for the purpose of auditing processes on Linux. The audit rules which are created by autrace are stored in the /var/www/audit/audit.log file. Before autrace can work perfectly all the previous audit logs must be deleted. The syntax of autrace is given below: Syntax: autrace -r program program-args Note: H
3 min read
Set up HAProxy as a load balancer for Nginx on CentOS
In this article, we are going to see how to set up HAProxy as a load balancer for Nginx on CentOS. What is Load balancing? Load balancing, commonly referred to as server farming or server pools is the process of efficiently dispersing incoming network traffic among a collection of backend servers. Modern high-traffic websites must quickly and relia
2 min read
How to setup a PXE boot server with NFS on CentOS?
Pre-boot eXecution Environment, or PXE, is a protocol based on BootP, DHCP, and TFTP and is often used for remote booting and operating system installation on many connected machines to the same network. A PXE server supplies the boot and installs images for PXE, which operates in a client-server context. The client is essentially a Network Interfa
3 min read
Channel bonding (NIC Teaming) in CentOS
Network Interface Card (NIC) is a procedure that helps to configure the grouping of physical network adapters to improve our network system performance and redundancy. Channel Bonding Linux Channel bonding is a mechanism that allows the administration to combine, multiple network interfaces together into single logical interfaces. Network interface
6 min read
How to find the rpm package of a specific file or library in CentOS/RHEL
Software applications designed for Linux systems are distributed in the form of packages that contain pre-compiled binaries, libraries, configuration files, and other details about the package. In the short term, it is a collection or bundle of the below files archived together. Binary files: It is also known as executable like lscpu, cat, grep, fi
4 min read
Basic CentOS Linux Commands in linux
CentOS is a free and open-source operating system that aims to provide a stable reliable, and community-supported platform for servers and other enterprise applications. In this article, we will be covering CentOS Linux basics commands and functions of CentOS and also we will look into the advanced commands. These CentOS commands allow you to manag
3 min read
Getting Started with CentOS
CentOS, short for Community ENTerprise Operating System, is a powerful and widely used Linux distribution known for its stability, security, and open-source nature. Derived from the source code of Red Hat Enterprise Linux (RHEL), CentOS has become a popular choice for server environments and enterprise-level applications. In this article, we will d
7 min read
How To Install the Apache Web Server on CentOS 7
Apache Web Server, commonly known as Apache is a free, open-source, and one of the most widely used web servers in the world. Apache web server is developed and maintained by Apache Software Foundation. Apache is not any physical server, it is a software application running either on a physical/virtual machine, that facilitates web-hosting. Apache
4 min read
How to install and configure Docker on Arch-based Linux Distributions(Manjaro) ?
In this article, we are going to see how to install and configure Docker on Arch-based Linux Distributions. Docker is an open-source containerization platform used for building, running, and managing applications in an isolated environment. A container is isolated from another and bundles its software, libraries, and configuration files. Containers
2 min read
Installing and Configure vim Plugin in Ubuntu
There are several plugin managers like Vundle, Pathogen, Vim-plug, VAM which are used to install vim plugin, These plugin increase speed, productivity, and look and feel of vim text-editor but here we will use the Pathogen plugin manager. Prerequisites : VIM editor This is the command to install vim editor in the ubuntu. sudo apt-get install vim Pl
1 min read
Configure Passwordless Sudo For A Specific User in Linux
Linux has a tough permission rule. Being a root user you are permitted to do anything however the normal user has only some allowed permissions. To run many other commands, they required to ask permissions from the superuser, using keyword sudo after which they need to enter the password. This requirement of the password after sudo command can be r
1 min read
How to Install and Configure Fish Shell in Ubuntu?
Fish Shell is a unique user-friendly command-line shell for the different operating systems. fish includes some smart features like syntax highlighting, fancy tab completions and autosuggest-as-we-type that just works by default with no configuration required. fish is mostly written in shell script and in C++. Step 1: Install fish repository in ubu
1 min read
How to Install and Configure Synaptic Package Manager in Ubuntu?
Synaptic Package Manager is a GUI based package management tool that uses APT (Advanced Package Tool) to installing, updating or removing packages from the Linux system. Some of the feature given by Synaptic Package Manager are: Allow installing, updating or removing packagesUpgrading whole systemSearching and filtering the list of packages availab
1 min read
How to Install and Configure Apache Subversion(SVN) In Linux?
Apache Subversion (SVN), is a version control system like Git. it is distributed under an open-source license. SVN was created by CollabNet Inc. but now it is developed as a project of the Apache Software Foundation. Downloading and Installing Apache SVN Apache Subversion(SVN) can be easily downloaded and installed with the use of the command-line.
2 min read
How to Install and Configure Elasticsearch on Ubuntu ?
Elasticsearch is a Cross-platform search engine based on Apache's Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents. It is written in Java. Prerequisites: Java Installation on Ubuntu Step 1: First, update your system by using the following command: $sudo
1 min read
How to Install and Configure Nginx from Source on Linux
Nginx is written in C language by Igor Sysoev to overcome the C10K problem (i.e. Concurrently handling 10k(ten thousand) connections). The problem was how to optimize the network socket to handle numerous clients at the same time. Nginx is a solution to that problem. It is a free and open-source software for reverse proxying, load balancer, web ser
4 min read
How to setup and configure an FTP server in Linux?
FTP (file transfer protocol) is an internet protocol that is used for transferring files between client and server over the internet or a computer network. It is similar to other internet protocols like SMTP which is used for emails and HTTP which is used for websites. FTP server enables the functionality of transferring files between server and cl
9 min read
How to configure SSH Client in Linux ?
At times we may need to access multiple remote systems with different IP addresses/hostnames, usernames, non-standard-ports with various command-line options. One way is to create a bash alias for each remote connection. But we have an easy and much better solution to this problem. OpenSSH allows to create per-user configuration file to store diffe
4 min read
How to Install and configure MySQL on Arch-based Linux Distributions(Manjaro)
MySQL is an open-source relational database management system developed by Oracle based on structured query language (SQL). It is primarily written in C and C++ programming languages and licensed under the GNU Public License. The client-end API is used to query, filter, sort, group, and modify data stored in the database table in the form of rows a
2 min read
How to install and configure Docker on Godaddy server?
In this article, we will discuss how to install the latest version of Docker on GoDaddy VPS (Ubuntu). Installing Docker on Godaddy Server Step 1: Open your terminal and ssh into the GoDaddy Server. $ ssh [username]@[ip] Step 2: Update and upgrade the server by running. $ sudo apt update -y $ sudo apt upgrade -y Step 3: Now install the latest versio
1 min read