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
- Understanding Network Interfaces in CentOS
- Identifying Available Network Interfaces
- Configuring a Static IP Address
- Configuring DHCP (Dynamic IP Addressing)
- Restarting the Network Service
- Verifying Your Network Configuration
- Troubleshooting Common Networking Issues
- 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 Name | Description |
|---|---|
eth0 | Traditional Ethernet interface naming |
ens33 | Predictable network interface name (VMware/virtual) |
ens3 | Common in KVM-based virtual machines |
enp0s3 | PCI-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-ipStep 2: List All Network Interfaces
Run the following command to display all available network interfaces along with their IP addresses and statuses:
ip addrExample 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 ens33Alternatively, you can use the older ifconfig command (requires the net-tools package):
ifconfig -aOr list only interface names with:
ip link showMake 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-ens33Step 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.4Parameter breakdown:
| Parameter | Description |
|---|---|
DEVICE | The name of the network interface |
TYPE | Interface type (typically Ethernet) |
BOOTPROTO | Set to none for static IP assignment |
ONBOOT | Set to yes to activate the interface at boot |
IPADDR | Your desired static IP address |
NETMASK | Subnet mask for your network |
GATEWAY | Default gateway (your router's IP address) |
DNS1 | Primary DNS server (Google: 8.8.8.8) |
DNS2 | Secondary 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=24This is equivalent to NETMASK=255.255.255.0.
Step 3: Save and Exit
If using nano, save the file by pressing:
CTRL + X β Y β EnterIf using vi or vim:
:wq β Enter4. 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-ens33Step 2: Set DHCP Parameters
Replace the existing content with the following minimal DHCP configuration:
DEVICE=ens33
TYPE=Ethernet
BOOTPROTO=dhcp
ONBOOT=yesStep 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 networkMethod 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 ens33Method 3: Using NetworkManager (CentOS 7/8)
If NetworkManager is active on your system, use nmcli:
sudo nmcli connection reload
sudo nmcli connection up ens33Method 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 ens33The 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 ens33Verify the Default Gateway
ip route showYou should see a line similar to:
default via 192.168.1.1 dev ens33Check DNS Resolution
cat /etc/resolv.confConfirm that your DNS servers are listed:
nameserver 8.8.8.8
nameserver 8.8.4.4Test Internet Connectivity
Ping an external host to confirm end-to-end connectivity:
ping -c 4 google.comExpected 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 lossIf all four packets are received with 0% packet loss, your network configuration is working correctly.
Test DNS Resolution Separately
nslookup google.comor
dig google.com7. 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=yesThen restart the network service:
sudo systemctl restart networkIssue 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
GATEWAYmatches your router or network gateway IP. - DNS misconfiguration: Ensure
DNS1andDNS2are set to valid DNS servers. - Routing issue: Check the routing table with
ip route showand 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-allAllow a specific service permanently:
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reloadAllow a specific port:
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reloadCheck if firewalld is running:
sudo systemctl status firewalldIssue 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=noAlternatively, 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 NetworkManagerOr 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:
- Identify your network interfaces using
ip addr - Edit the appropriate
ifcfg-<interface>configuration file - Set
BOOTPROTO=nonefor static IPs orBOOTPROTO=dhcpfor dynamic addressing - Restart the network service using
systemctlornmcli - Verify connectivity using
ip addr,ip route, andping - 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.
