Summary of Network Card Configuration Methods for Mainstream Linux Operating Systems – A Must-Bookmark!

A single misoperation caused the server to lose network connectivity for 3 hours, simply due to a lack of understanding of the differences in network card configuration across different Linux versions.

In the field of Linux operations, incorrect network card configuration is the primary cause of server network failures. According to the 2024 Operations Failure Report, over 35% of server downtime incidents stem from improper network configuration. This article will delve into the network card configuration methods for mainstream distributions such as CentOS/RHEL and Ubuntu/Debian, helping you avoid configuration pitfalls.

1. Comprehensive Configuration Analysis for CentOS/RHEL Series

1. CentOS 6/RHEL 6: Traditional ifcfg Configuration

Configuration file path: <span>/etc/sysconfig/network-scripts/ifcfg-eth0</span>

Key Parameter Analysis:

DEVICE=eth0                # Physical network card name (must match the filename)\nBOOTPROTO=static           # IP allocation method: static/dhcp\nONBOOT=yes                 # Automatically activate on boot (the most easily overlooked key parameter!)\nIPADDR=10.0.0.100          # Static IP address\nNETMASK=255.255.255.0      # Subnet mask (or PREFIX=24)\nGATEWAY=10.0.0.2           # Default gateway\nDNS1=8.8.8.8               # Primary DNS\nDNS2=114.114.114.114       # Secondary DNS

Restart Service:

service network restart   # Command to apply configuration\nifconfig eth0             # Verify configuration

Pitfall Reminder: If <span>ONBOOT=no</span>, the network card will not automatically enable after a reboot, and the server will lose connectivity!

2. CentOS 7/RHEL 7: Transitional Dual Configuration Mode

Changes: Network card naming has changed to ens33, enp0s3, and other predictable naming formats

Configuration file path: <span>/etc/sysconfig/network-scripts/ifcfg-ens33</span>

Configuration Example:

TYPE=Ethernet\nNAME=ens33                # Connection name (customizable)\nDEVICE=ens33              # Device name (must match actual)\nPREFIX=24                 # CIDR notation replacing NETMASK\nIPV6_AUTOCONF=no          # Disable IPv6 auto-configuration

New Tools:

  • <span>nmcli</span>: Command-line configuration tool
    nmcli con add con-name static-ens33 ifname ens33 type ethernet \
    ipv4.addresses 10.0.0.100/24 ipv4.gateway 10.0.0.2 \
    ipv4.dns "8.8.8.8 114.114.114.114" ipv4.method manual
  • <span>nmtui</span>: Text-based graphical tool (suitable for beginners)

3. CentOS 8/RHEL 8+: Unified Management with NetworkManager

Revolutionary Change: The traditional ifcfg file is no longer generated by default, fully transitioning to <span>nmcli</span>

Three-Step Configuration Method:

# 1. Create connection configuration\nnmcli con add con-name prod-ens33 ifname ens33 type ethernet\n\n# 2. Set static IP parameters\nnmcli con mod prod-ens33 ipv4.addresses '192.168.1.100/24'\nnmcli con mod prod-ens33 ipv4.gateway '192.168.1.1'\nnmcli con mod prod-ens33 ipv4.dns '8.8.8.8,1.1.1.1'\nnmcli con mod prod-ens33 ipv4.method manual  # Set to static\n\n# 3. Activate configuration\nnmcli con up prod-ens33

Emergency Recovery Tip: If a misoperation causes a network outage, you can directly connect to the server and execute:

nmcli con add type ethernet ifname ens33 ipv4.method auto

Temporarily enable DHCP to automatically obtain an IP and restore network connectivity

2. Configuration Guide for Debian/Ubuntu Series

1. Ubuntu 16.04/Debian 9 and Earlier: interfaces File

Configuration file path: <span>/etc/network/interfaces</span>

Classic Configuration:

auto eth0                   # Automatically activate on boot\niface eth0 inet static      # Static IP configuration (dhcp for dynamic)\n    address 192.168.1.100\n    netmask 255.255.255.0\n    gateway 192.168.1.1\n    dns-nameservers 8.8.8.8 114.114.114.114  # Space-separated multiple DNS

Restart Service:

sudo systemctl restart networking

2. Ubuntu 18.04+/Debian 10+: netplan Revolution

Disruptive Change: Uses YAML format configuration files, located at <span>/etc/netplan/*.yaml</span>

Standard Configuration:

network:\n  version:2                # Fixed version number\nrenderer:networkd        # Background service: networkd or NetworkManager\nethernets:\n    ens33:                  # Device name\n      dhcp4:no             # Disable DHCPv4\n      addresses:\n        -192.168.1.100/24# IP/mask (CIDR format)\n      gateway4:192.168.1.1# IPv4 gateway\n      nameservers:\n        addresses:\n          -8.8.8.8         # DNS list\n          -223.5.5.5

Apply Configuration:

sudo netplan apply          # Apply configuration (no service interruption)\nsudo netplan --debug apply  # Debug mode (recommended for first use)

YAML Format Pitfalls:

  • • Indentation must use spaces (Tab key is prohibited)
  • • There must be a space after the colon A company experienced a network outage for 200 servers due to indentation errors; be sure to use <span>netplan try</span> to validate syntax!

3. Universal Techniques Across Versions

1. Temporary Configuration (Essential for Emergencies)

# Set IP/mask\nsudo ip addr add 192.168.1.100/24 dev ens33\n\n# Enable network card\nsudo ip link set ens33 up\n\n# Add default gateway\nsudo ip route add default via 192.168.1.1\n\n# Temporary DNS (will not persist after reboot)\necho "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

2. Multiple IP Binding (Multiple Addresses on a Single Network Card)

CentOS Method:

# Create configuration file ifcfg-ens33:1\nDEVICE=ens33:1\nIPADDR=192.168.1.101\nNETMASK=255.255.255.0

Ubuntu Method:

# netplan configuration\naddresses:\n  -192.168.1.100/24\n  -192.168.1.101/24  # Directly append IP

3. Golden Commands for Network Connectivity Diagnosis

ping 8.8.8.8 -c 4          # Basic connectivity test\nip route show               # Check routing table (look for missing gateway)\nnslookup www.baidu.com      # DNS resolution verification\nnetstat -tuln               # Listening port detection\ntraceroute 114.114.114.114  # Route tracing (check for network blockage)

4. Enterprise-Level Fault Diagnosis Process

When server network anomalies occur, quickly locate the issue by following these steps:

  1. 1. Physical Layer Check:
    ip link show ens33 | grep state  # Check physical status of the network card

    If it shows <span>DOWN</span>, execute <span>ip link set ens33 up</span> to activate

  2. 2. IP Layer Diagnosis:
    ip addr show dev ens33   # Confirm if IP configuration is correctly loaded
  3. 3. Routing Check:
    ip route get 8.8.8.8     # Test routing path to target IP
  4. 4. Service Verification:
    systemctl status NetworkManager  # Check network service status
  5. 5. Firewall Interception:
    sudo iptables -L -v -n    # View firewall rules

5. Quick Reference Table for Configuration Across Distributions

Distribution Configuration File Path Restart Command Key Parameters
CentOS 6/RHEL 6 /etc/sysconfig/network-scripts/ifcfg-eth0 service network restart BOOTPROTO, ONBOOT
CentOS 7/RHEL 7 /etc/sysconfig/network-scripts/ifcfg-ens33 systemctl restart network PREFIX replacing NETMASK
CentOS 8/RHEL 8+ nmcli command configuration (no default file) nmcli con reload ipv4.method manual
Ubuntu 16.04- /etc/network/interfaces systemctl restart networking iface eth0 inet static
Ubuntu 18.04+ /etc/netplan/*.yaml netplan apply renderer: networkd

A financial company experienced a 6-hour core business interruption when upgrading from CentOS 7 to 8 due to a lack of knowledge about the nmcli command. The technical lead admitted, “I thought the configuration file was still in the old location, unaware that the underlying architecture had changed drastically.”

Best Practice Summary

  1. 1. Must-Do in Production Environment:
  • • Backup original files before modifying configurations: <span>cp ifcfg-ens33 ifcfg-ens33.bak</span>
  • • Use <span>ip a</span> command instead of the deprecated <span>ifconfig</span>
  • • Test configurations: first <span>netplan try</span> (Ubuntu) or <span>nmcli con reload</span> (RHEL)
  • 2. Security Hardening Recommendations:
    [connection]\nipv4.dns-search=example.com  # Add DNS search domain\nipv4.ignore-auto-dns=true    # Prevent DHCP from overriding DNS
  • 3. High Availability Solutions:
    • • Network card bonding
    • • Bridged network configuration (essential for KVM virtualization)

    Mastering the configuration differences across various distributions is the core competitiveness of advanced Linux engineers.

    Since you’ve read this far, if you find it useful, please give it a thumbs up, share, and forward. If you want to receive updates immediately, you can also give me a star.⭐ Thank you for reading my article, and see you next time.

    Leave a Comment