CentOS Networking

How to Configure The Network on CentOS7

CentOS 7 uses Network Manager to manage the network. It is a great tool that makes configuring the network on CentOS easy. It has graphical and commands line based utilities.In this article, I will talk about different network terms, how to find network related information and CentOS 7 network configuration. Let’s get started.

Network Configuration Tools on CentOS 7:

On CentOS 7, if you have graphical desktop environment such as GNOME installed, then you can configure the network using the graphical user interface.

The graphical network configuration utility is available in Applications > System Tools > Settings > Network as you can see in the marked section of the screenshot below.

From the command line, you can use nmtui and nmcli commands to configure networking through Network Manager.

nmtui may not be installed by default on CentOS 7. You can run the following command to install them.

$ sudo yum install NetworkManager-tui -y

Understanding Network Interface Naming:

On modern Linux including CentOS 7, network interfaces have names such as ens33. If your network interface name starts with en, then it’s an Ethernet cable directly plugged in. If your network interface name starts with wl, then it’s a WiFi interface.

Then there are some other letters and numbers in the name such as pN, sM, oX indicating Nth PCI bus or USB, Mth hot plug slot, Xth onboard device respectively.

So, wlp1s2 means, it’s a WiFi interface (wl) on the 1st USB/PCI bus, on the 2nd hot plug slot.

To find out the name of your installed network interfaces, run the following command:

$ ip a

Static vs Dynamic IP Addresses and DHCP:

Static IP address is fixed. It does not change with time. On the other hand, dynamic IP addresses may change with time.

When a DHCP client requests a DHCP server for an IP address, the DHCP server leases an IP address from a range of IP addresses for a certain time (TTL). After that certain time, the DHCP client must request the DHCP server for an IP address again. So each DHCP client gets a different IP address and there’s no guarantee that a certain DHCP client will get the same IP address each time. So the IP addresses you get from the DHCP server is called dynamic IP addresses.

To learn how to configure Static IP address, see my other article at [How to Setup a Static IP on CentOS 7]

You can find out what your IP address is whether it’s static or dynamic with the following command on CentOS 7:

$ ip a

As you can see from the marked section of the screenshot below, my IP address is and it’s dynamic.

Working with DHCP Client:

If your network interface is configured to use DHCP, then you can use dhclient to renew IP addresses. Let’s

First, release the IP address of your network interface with the following command:

$ sudo dhclient -v -r ens36

NOTE: Here, ens36 is the network interface name.

Now renew the IP address with the following command:

$ sudo dhclient -v ens36

DNS and /etc/hosts Files:

Domain Name System or DNS in short is used to resolve host names to IP addresses and vice versa.

Here’s how DNS works, when you visit google.com, your computer looks up a DNS server you set or your ISP set to find the IP address of google.com, then it connects to that IP address and downloads the webpage to your browser. Without DNS, you would have to know the IP address of google.com and remember it, which is a nearly impossible task in today’s world.

Before DNS server existed, /etc/hosts file was used to do name resolution. It still is useful for local name resolution. For example, when you are developing a website, you may prefer typing in mywebsite.com instead of typing the IP address of your webserver

To do that, open /etc/hosts file with the following command:

$ sudo vi /etc/hosts

Now add the following line there and save the file: mywebsite.com

Now you can access your local webserver from the web browser very easily.

Default Gateway:

If you’re using a router, then you’re already using a gateway. It’s usually the IP address of your router that you have on your home. Technically, it’s the outgoing path that a packet originated from your computer takes. The default gateway is the path that packet will go to by default.

For example, if you go to google.com, then the request is sent through the IP address of your router, the default gateway.

Run the following command to find your default gateway on CentOS 7:

$ ip route show

As you can see, my default gateway is

Connecting to a WiFi Network:

You can connect to a WiFi network using the graphical user interface as you can see from the screenshot below.

You can also use nmtui to connect to a WiFi network.

First find out your network interface name with the following command:

$ sudo ip a | grep wl

My WiFi interface name is wls34u1

Now open nmtui:

$ sudo nmtui

Go to Edit a connection.

Now go to

Now select Wi-Fi and then go to <Create>

Now enter your Profile name, Device name, Wi-Fi SSID, Security type and Password. Then go to <OK>.

Wi-Fi connection should be created.

Now press <Esc> to go back and go to Activate a connection.

Now select your Wi-Fi connection and go to <Activate>.

It should be activated.

Now press <Esc> several times to exit nmtui.

Now to test whether the internet is working, run the following command:

$ ping google.com

The internet is working as you can see.

Common Problems:

Even if you’re able to connect to your Wi-Fi or network, internet may not work. The most common problem is that the DHCP server returns invalid DNS server.

To fix that, run the following command:

$ echo "nameserver" | sudo tee -a /etc/resolv.conf

Your default gateway may not be set at times. You can add a default gateway with the following command:

$ sudo ip route add default via dev wls34u1

NOTE: Here is the IP address of my router and wls34u1 is the Wi-Fi network interface name.

So that’s how you configure network settings on CentOS 7. Thanks for reading this article.

About the author

Shahriar Shovon

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.