Introduction
Networking is at the core of any Linux server’s operation. Whether you’re setting up a web server, file share, or simply enabling internet access, configuring the network interface correctly is crucial. This guide provides a comprehensive comparison and walkthrough for setting up networking on two major Linux families:
- Red Hat-based (RHEL, CentOS, Rocky, AlmaLinux)
- Debian-based (Ubuntu, Debian)
We’ll cover both manual (CLI) and persistent (configuration file) methods, using modern tools like nmcli and netplan, with examples, flow, and common use cases.
Table of Contents
- Understanding Linux Network Interfaces
- Checking Network Status
- Configuring Networking in Red Hat-Based Systems
- Configuring Networking in Debian-Based Systems
- Use Cases (Static IP, DHCP, Bridging, DNS)
- Troubleshooting Tips
- Conclusion
1. Understanding Linux Network Interfaces
In Linux, every network device is treated as a file and usually appears as:
- eth0, ens33, or enp0s3 for Ethernet
- wlan0 or wlp2s0 for wireless
- lo for loopback
Modern distributions often use Predictable Network Interface Names like enp0s3
.
You can view all interfaces using:
ip a
or
nmcli device status
2. Checking Network Status
Before making changes, always verify your current setup:
ip addr show
ip route show
nmcli connection show
For DNS resolution testing:
ping google.com
cat /etc/resolv.conf
3. Configuring Networking in Red Hat-Based Linux
➤ Option 1: Using nmcli
(NetworkManager CLI)
Set a static IP:
nmcli con add con-name static-eth0 ifname eth0 type ethernet ip4 192.168.1.100/24 gw4 192.168.1.1
nmcli con mod static-eth0 ipv4.dns "8.8.8.8 1.1.1.1"
nmcli con up static-eth0
Enable DHCP:
nmcli con add type ethernet con-name dhcp-eth0 ifname eth0
nmcli con up dhcp-eth0
➤ Option 2: Manual Configuration (Legacy method)
Edit the network script:
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
Example static IP config:
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
ONBOOT=yes
Then restart networking:
sudo systemctl restart network
4. Configuring Networking in Debian-Based Linux
➤ Option 1: Using netplan (Ubuntu 18.04+ and Debian 11+)
Netplan is the default network configuration tool in modern Ubuntu/Debian.
Edit or create config:
sudo vi /etc/netplan/01-netcfg.yaml
Static IP example:
network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
Apply changes:
sudo netplan apply
➤ Option 2: Legacy /etc/network/interfaces
(Debian 10 or older)
Edit:
sudo vi /etc/network/interfaces
Example static IP:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 1.1.1.1
Restart networking:
sudo systemctl restart networking
5. Use Cases
Scenario | Recommended Method | Notes |
---|---|---|
Static IP for servers | Netplan (Debian) / nmcli (RedHat) | Easier to manage persistently |
Dynamic IP for laptops | DHCP via nmcli or Netplan | Simpler setup |
Bridged networking | nmcli con add type bridge | For virtualization setups |
Custom DNS setup | resolv.conf, or YAML (Netplan) | For local DNS or filtering |
6. Troubleshooting Tips
- Interface not coming up? ip link set eth0 up
- DNS not working? systemd-resolve –status cat /etc/resolv.conf
- NetworkManager errors? nmcli general logging level DEBUG journalctl -u NetworkManager
- Applying Netplan fails? netplan try
7. Conclusion
Whether you’re on Red Hat or Debian-based Linux, networking setup boils down to two key steps: configuring the interface and ensuring persistence. While the tools vary (nmcli, Netplan
, legacy files), the goals remain the same: connectivity, reliability, and control.
Mastering these configuration methods is essential for:
- Virtual machines & cloud instances (AWS, GCP, Proxmox, etc.)
- Hosting web applications
- Managing servers