How to Configure CentOS Network Settings

March 25, 2020

Introduction

It is essential to know how to configure your network connections after installing CentOS. There are two ways to do so – via command line or the GUI. You can change network specifications and set up a static IP or configure the network interface for DHCP.

This tutorial shows you how to configure network settings on CentOS using a command line or the Network Manager TUI. 

Tutorial on how to configure CentOS network settings,

How to Configure Network Settings on CentOS 7 Using the Terminal

How Network Interface Naming Works?

RHEL introduced its new naming convention for network interfaces in version RHEL 6. However, the feature was enabled by default only with version 7, which meant that eth0 and eth1 were no more.

The names are now defined by a group of factors (device type, adapter, port/ID, and so on).

Based on the device type, the network interface name can start with:

Configuring a Static IP

You can set up a static IP via command line by modifying the network script of the interface.

1. First, find the name of the network interface you want to change using the network manager command-line tool. Prompt the system to list all network devices, along with network details:

nmcli d

In our example, we will change the configuration for the first network.

Display network devices on CentOS.

2. To do so, open the network’s configuration file by typing the following:

vi /etc/sysconf ig/network-scripts/ifcfg-[network_device_name]

3. A text editor with the network configuration opens.

4. To set a static IP for your network, you need to change the BOOTPROTO line to have the value "static". Also, modify the ONBOOT option to "yes" to enable the network when starting the system.

5. Then, add the following information about your network under the already existing text:

IPADDR=...

NETMASK=...

GATEWAY=...

DNS1=...

DNS2=...

The configuration file should be similar to the example below:

Configure a static IP address using the command line.


6. Save the file and exit the text editor, returning to the command line.

7. For these changes to take effect, you must restart the network with the command:

systemctl restart

Note: If you don’t have network details (such as the IP address, gateway, and so on), run the command nmcli dev show [network_device_name]. The output displays all the information it has on the network.

Configuring Network Interface for DHCP

You can configure a network for DHCP (Dynamic Host Configuration Protocol) via command line by changing the network configuration.

1. Instruct the system to list your network devices with the command:

nmcli d

Find the network you want to configure for DHCP and copy its name.

2. Then, open the appropriate configuration file. Use the following command and paste the device name at the end:

vi /etc/sysconf ig/network-scripts/ifcfg-[network_device_name]

3. A text editor with the network configuration opens.

4. The BOOTPROTO line should have the value "dhcp" and change the ONBOOT line to "yes" to enable the network. Also, add network details such as IPADDR, NETMASK, GATEWAY, and DNS.

Set network insterface for DHCP.

5. Save the file and exit to return to the command line.

6. Finally, restart the network with:

systemctl restart

How to Configure Network Settings on CentOS 7 Using GUI

To configure your CentOS network interface via GUI, you need to open the Network Manager and modify the configuration according to your needs.

1. Open the Network Manager by running the following command in the command line:

nmtui

2. The command prompts the NetworkManager TUI window, which appears as in the image below. Select Edit a connection to view configuration settings.

Configure network settings on CentOS using Network Manager.

3. Next, choose the network you want to configure.

Choose network interface which you want to configure.

You can now edit the given connection.

Configuring a Static IP

If you want to set the connection to have a static IP address, you can modify the configuration with the Network Manager.

1. First, open the required connection settings. If you have followed the steps outlined in the section above, you should already have the Edit a connection window in front of you.

2. To set a static IP address for the IPv4 configuration, open the drop-down menu next to the name of the appropriate connection.

3. By default, it is set to Automatic. Change the settings to Manual.

Configure a static IP address using the Network Manager.

4. Then, select the Show option for the given network to add the necessary information.

Show network configuration for IPv4.

5. Now you can add information related to your connection. This includes the addresses, gateways, DNS servers, and search domains. You don’t have to fill out all the fields.

6. Finally, make sure to enable the option for requiring IPv4 addressing for this connection and automatic connection.

Set a static IP address using GUI.

7. Select OK and Back to return to the main menu.

Configuring Network for Using DHCP

1. To configure a network as DHCP (Dynamic Host Configuration Protocol), you need to set the IPv4 configuration settings to Automatic.

Configure network for using DHCP on CentOS via GUI.

2. Before you exit out of the Network Manager, make sure to enable automatic connection for the network interface.

Enable automatic connection for network interface.

3. Select OK to save the changes.

4. Then, exit out of the Network Manages by selecting Back and then Quit.

5. To enable the new configuration, you need to restart the service network by typing the following command in the terminal:

service network restart

Set a System Hostname

You can also change your hostname using the Network Manager by selecting the Set system hostname option in the main menu.

Set a system hostname in the Network Manager.

Type in the new hostname and select OK.

Change hostname using Network Manager.

Note: For more information on how to change or set hostname on CentOS, please refer to our tutorials for CentOS 7 and CentOS 8.

Validating Your Network Settings

Verify your network is now working with the new settings with the command:

ip a show [network_device_name]

The output will display interface information based on which you can verify if the changes are live.

Validate you network settings on CentOS 7.

Conclusion

After reading this article, you should have successfully configured the network settings on your CentOS system. If one method seems too difficult, try another method explained in this article.

Was this article helpful?
YesNo
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
Nmap Commands - 17 Basic Commands for Linux Network
May 14, 2019

Nmap stands for Network Mapper. It is an open source tool for network exploration and security auditing. With...
Read more
Iptables Tutorial: Ultimate Guide to Linux Firewall
January 28, 2020

Learn how to use iptables commands and see how iptables works. By following the instructions listed in this...
Read more
How to Install and Use Nmap Network Scanner on Linux
September 15, 2019

Learn how to install Nmap on a Linux based system and use it to retrieve valuable information from remote...
Read more
How to Install and Configure Nginx on CentOS 8
January 31, 2020

Nginx, a popular, open-source HTTP web server, is used for hosting many high-traffic websites. It is part of...
Read more