15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started
01.11.2024

How to Configure Networking in CentOS: A Complete Step-by-Step Guide

Configuring networking in CentOS is one of the most fundamental tasks for any systems administrator. Whether you're setting up a freshly deployed VPS Hosting environment or managing a bare-metal Dedicated Server, getting your network interfaces configured correctly is the critical first step toward a stable, connected, and production-ready server.

This comprehensive guide walks you through everything you need to know: identifying network interfaces, assigning static IP addresses, configuring DHCP, restarting network services, verifying connectivity, and resolving the most common networking issues encountered on CentOS systems.

Table of Contents

  1. Understanding Network Interfaces in CentOS
  2. Identifying Available Network Interfaces
  3. Configuring a Static IP Address
  4. Configuring DHCP (Dynamic IP Addressing)
  5. Restarting the Network Service
  6. Verifying Your Network Configuration
  7. Troubleshooting Common Networking Issues
  8. Conclusion

1. Understanding Network Interfaces in CentOS {#understanding-network-interfaces}

In CentOS (versions 7 and 8), network interfaces are managed through configuration files stored in the following directory:

/etc/sysconfig/network-scripts/

Each network interface has a dedicated configuration file named using the following convention:

ifcfg-<interface_name>

Where <interface_name> is the identifier assigned to the interface by the operating system. Common examples include:

Interface NameDescription
eth0Traditional Ethernet interface naming
ens33Predictable network interface name (VMware/virtual)
ens3Common in KVM-based virtual machines
enp0s3PCI-based Ethernet (VirtualBox, bare metal)

> Note: CentOS 7 and later use "predictable network interface names" by default (e.g., ens33, enp3s0) instead of the legacy eth0 naming convention. This improves consistency across reboots and hardware changes.

Understanding this structure is essential before making any configuration changes. Editing the wrong file or using incorrect parameters can result in loss of network connectivity β€” a particularly critical concern when managing remote servers.

2. Identifying Available Network Interfaces {#identifying-network-interfaces}

Before modifying any configuration, you must first identify which network interfaces exist on your system and what their current state is.

Step 1: Access the Terminal

Connect to your server via SSH or access the terminal directly if you have physical or console access:

ssh user@your-server-ip

Step 2: List All Network Interfaces

Run the following command to display all available network interfaces along with their IP addresses and statuses:

ip addr

Example output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
    link/ether 00:0c:29:ab:cd:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.105/24 brd 192.168.1.255 scope global dynamic ens33

Alternatively, you can use the older ifconfig command (requires the net-tools package):

ifconfig -a

Or list only interface names with:

ip link show

Make a note of the interface name you want to configure (e.g., ens33) before proceeding to the next section.

3. Configuring a Static IP Address {#configuring-static-ip}

Assigning a static IP address is the recommended approach for servers, as it ensures the IP address never changes unexpectedly β€” which is critical for DNS records, firewall rules, and remote access stability.

Step 1: Open the Network Interface Configuration File

Use a text editor such as nano or vi to open the configuration file for your interface. Replace ens33 with your actual interface name:

sudo nano /etc/sysconfig/network-scripts/ifcfg-ens33

Step 2: Add or Modify the Configuration Parameters

The file may already contain some parameters. Update or add the following lines to configure a static IP address:

DEVICE=ens33
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4

Parameter breakdown:

ParameterDescription
DEVICEThe name of the network interface
TYPEInterface type (typically Ethernet)
BOOTPROTOSet to none for static IP assignment
ONBOOTSet to yes to activate the interface at boot
IPADDRYour desired static IP address
NETMASKSubnet mask for your network
GATEWAYDefault gateway (your router's IP address)
DNS1Primary DNS server (Google: 8.8.8.8)
DNS2Secondary DNS server (Google: 8.8.4.4) β€” optional

> Important: Replace the example values (192.168.1.100, 192.168.1.1, etc.) with the actual values provided by your network or hosting provider.

You can also use CIDR notation with the PREFIX parameter instead of NETMASK:

PREFIX=24

This is equivalent to NETMASK=255.255.255.0.

Step 3: Save and Exit

If using nano, save the file by pressing:

CTRL + X β†’ Y β†’ Enter

If using vi or vim:

:wq β†’ Enter

4. Configuring DHCP (Dynamic IP Addressing) {#configuring-dhcp}

If your environment uses a DHCP server to automatically assign IP addresses (common in development environments, cloud platforms, or internal networks), configure the interface as follows:

Step 1: Open the Configuration File

sudo nano /etc/sysconfig/network-scripts/ifcfg-ens33

Step 2: Set DHCP Parameters

Replace the existing content with the following minimal DHCP configuration:

DEVICE=ens33
TYPE=Ethernet
BOOTPROTO=dhcp
ONBOOT=yes

Step 3: Save and Exit

Save the file using the same method described in the previous section.

> When to use DHCP vs. Static IP: Use DHCP for workstations, development VMs, or temporary environments. Use static IPs for production servers, web servers, database servers, and any system that requires a consistent, predictable address. If you're hosting websites or applications on a Shared Web Hosting plan or a VPS, a static IP is strongly recommended.

5. Restarting the Network Service {#restarting-network-service}

After saving your configuration changes, you must restart the network service to apply them. There are several methods depending on your CentOS version.

Method 1: Restart the Entire Network Service (CentOS 7)

sudo systemctl restart network

Method 2: Bring the Interface Down and Back Up

This method restarts only the specific interface, minimizing disruption to other interfaces:

sudo ifdown ens33 && sudo ifup ens33

Method 3: Using NetworkManager (CentOS 7/8)

If NetworkManager is active on your system, use nmcli:

sudo nmcli connection reload
sudo nmcli connection up ens33

Method 4: Restart NetworkManager Service

sudo systemctl restart NetworkManager

> Warning: If you are connected via SSH, restarting the network service will temporarily drop your connection. Ensure you have an alternative way to access the server (such as a console or KVM) in case the new configuration contains an error.

6. Verifying Your Network Configuration {#verifying-network-configuration}

Once the network service has restarted, verify that your configuration has been applied correctly.

Check the Assigned IP Address

ip addr show ens33

The output should display the IP address you configured under the inet line:

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
    inet 192.168.1.100/24 brd 192.168.1.255 scope global ens33

Verify the Default Gateway

ip route show

You should see a line similar to:

default via 192.168.1.1 dev ens33

Check DNS Resolution

cat /etc/resolv.conf

Confirm that your DNS servers are listed:

nameserver 8.8.8.8
nameserver 8.8.4.4

Test Internet Connectivity

Ping an external host to confirm end-to-end connectivity:

ping -c 4 google.com

Expected output:

PING google.com (142.250.185.46) 56(84) bytes of data.
64 bytes from lga34s32-in-f14.1e100.net: icmp_seq=1 ttl=117 time=12.4 ms
64 bytes from lga34s32-in-f14.1e100.net: icmp_seq=2 ttl=117 time=11.9 ms
...
4 packets transmitted, 4 received, 0% packet loss

If all four packets are received with 0% packet loss, your network configuration is working correctly.

Test DNS Resolution Separately

nslookup google.com

or

dig google.com

7. Troubleshooting Common Networking Issues {#troubleshooting}

Even experienced administrators encounter networking problems. Here are the most common issues and how to resolve them on CentOS.

Issue 1: Network Interface Does Not Start on Boot

Symptom: The server loses network connectivity after a reboot.

Cause: The ONBOOT parameter is set to no or is missing from the configuration file.

Fix: Open the interface configuration file and ensure the following line is present and set correctly:

ONBOOT=yes

Then restart the network service:

sudo systemctl restart network

Issue 2: No Internet Connectivity After Configuration

Symptom: The interface has an IP address, but you cannot reach external hosts.

Possible causes and fixes:

  • Incorrect gateway: Verify that GATEWAY matches your router or network gateway IP.
  • DNS misconfiguration: Ensure DNS1 and DNS2 are set to valid DNS servers.
  • Routing issue: Check the routing table with ip route show and confirm the default route is present.
  • Physical connectivity: If using a physical server, verify the network cable is properly connected.

Issue 3: IP Address Conflict

Symptom: Network connectivity is intermittent or another device on the network reports an IP conflict.

Fix: Choose a static IP address that is outside the DHCP pool range of your router, or coordinate with your network administrator to reserve the IP.

Issue 4: Firewall Blocking Traffic

Symptom: The server has connectivity, but specific services (HTTP, HTTPS, SSH, etc.) are not accessible from external hosts.

Check current firewall rules:

sudo firewall-cmd --list-all

Allow a specific service permanently:

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload

Allow a specific port:

sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

Check if firewalld is running:

sudo systemctl status firewalld

Issue 5: NetworkManager Conflicts with Static Configuration

Symptom: Static IP settings are ignored or overwritten after a reboot.

Fix: If you are managing interfaces manually via configuration files and not using NetworkManager, you can either disable NetworkManager or configure it to ignore the specific interface by adding the following line to the ifcfg file:

NM_CONTROLLED=no

Alternatively, manage the interface through NetworkManager's nmcli tool for a more integrated approach.

Issue 6: systemctl restart network Fails on CentOS 8

Symptom: The network service does not exist or fails to restart on CentOS 8.

Explanation: CentOS 8 deprecated the legacy network service in favor of NetworkManager. Use the following instead:

sudo systemctl restart NetworkManager

Or manage connections with nmcli:

nmcli connection show
nmcli connection up <connection-name>

Conclusion {#conclusion}

Configuring networking in CentOS is a foundational skill that every Linux systems administrator must master. Whether you're assigning a static IP for a production web server, configuring DHCP for a development environment, or troubleshooting connectivity issues on a remote machine, the steps outlined in this guide provide a solid, reliable framework.

To summarize the key steps:

  1. Identify your network interfaces using ip addr
  2. Edit the appropriate ifcfg-<interface> configuration file
  3. Set BOOTPROTO=none for static IPs or BOOTPROTO=dhcp for dynamic addressing
  4. Restart the network service using systemctl or nmcli
  5. Verify connectivity using ip addr, ip route, and ping
  6. Troubleshoot using firewall commands, routing checks, and DNS verification

Proper network configuration is especially important when managing cloud infrastructure. If you're looking for a reliable hosting environment with full root access and flexible networking options, explore AlexHost's VPS Hosting plans β€” ideal for CentOS deployments requiring stable, high-performance connectivity. For mission-critical workloads that demand dedicated resources, consider AlexHost's Dedicated Servers. And if your server is hosting web applications, don't forget to secure your domain with a trusted SSL Certificate to encrypt traffic and protect your users.

Regularly review your network configurations, monitor interface status, and keep your firewall rules up to date to maintain optimal server performance and security.

15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started