How to Recreate Missing ifcfg-eth0 Network Configuration File in CentOS


5 views

When working with CentOS servers, you might accidentally delete or lose your network interface configuration files (typically located in /etc/sysconfig/network-scripts/). The ifcfg-eth0 file contains crucial networking parameters for your primary Ethernet interface.

First, verify your network interface name and status:

# Check available interfaces
ip link show

# Verify current temporary IP configuration
ip addr show eth0

The simplest way to recreate your configuration is using the text-based network manager tool:

sudo nmtui

Navigate through the menus to:

  1. Select "Edit a connection"
  2. Choose "Add"
  3. Select "Ethernet" type
  4. Configure with your network settings

If you prefer manual creation, here's a template for /etc/sysconfig/network-scripts/ifcfg-eth0:

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
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

For systems with NetworkManager, use this command sequence:

sudo nmcli con add type ethernet con-name eth0 ifname eth0
sudo nmcli con mod eth0 ipv4.addresses 192.168.1.100/24
sudo nmcli con mod eth0 ipv4.gateway 192.168.1.1
sudo nmcli con mod eth0 ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con mod eth0 ipv4.method manual
sudo nmcli con up eth0

After recreating your config file, always:

# Restart network service
sudo systemctl restart network

# Verify configuration
ip addr show eth0
ping -c 4 8.8.8.8

# Check routes
ip route show

For DHCP configuration, your ifcfg-eth0 would look like:

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

When working with CentOS network configurations, the ifcfg-eth0 file is the backbone of your Ethernet interface setup. Unlike temporary ifconfig commands, these configuration files persist across reboots and handle complex networking scenarios.

Simply creating a new file in /etc/sysconfig/network-scripts/ often doesn't work because:

  • Missing HWADDR binding
  • Incorrect driver module parameters
  • NetworkManager conflicts

Use nmtui (NetworkManager Text User Interface) for reliable recreation:

# Launch the interactive tool
sudo nmtui

# Navigate to "Edit a connection"
# Select "Add" → "Ethernet"
# Configure with these essential parameters:
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=dhcp  # or 'static' with manual IP

For servers without GUI access:

# First, identify your connection details
nmcli connection show

# Then recreate with minimal config
sudo nmcli connection add type ethernet \
    con-name eth0 \
    ifname eth0 \
    ip4 192.168.1.100/24 \
    gw4 192.168.1.1

After recreation, validate with:

# Check interface status
ip addr show eth0

# Verify routing
ip route show

# Test connectivity
ping -c4 8.8.8.8

# Check config file permissions
ls -l /etc/sysconfig/network-scripts/ifcfg-eth0

For static IP configurations, your ifcfg-eth0 should include:

DEVICE=eth0
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
  • Run systemctl restart network after changes
  • Check logs with journalctl -xe
  • For legacy systems, try service network restart