Master Linux Network Configuration Across Distributions: netplan, nmcli, systemd‑networkd, and ifupdown
This step‑by‑step guide shows how to configure networking on Ubuntu/Debian with netplan, CentOS/RHEL with nmcli, Arch Linux with systemd‑networkd, and Alpine with ifupdown, plus common debugging commands and a systematic troubleshooting workflow.
1. Ubuntu/Debian: netplan (YAML)
Since Ubuntu 18.04, Canonical delegates network configuration to netplan, which translates YAML files into backend configurations for systemd‑networkd or NetworkManager. Configuration files reside in /etc/netplan/ and typically use names like 01-netcfg.yaml or 50-cloud-init.yaml.
Static IP example:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.100/24]
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]Key pitfalls: YAML is indentation‑sensitive (spaces only), dhcp4: no must be explicit, and the newer routes syntax replaces the deprecated gateway4. Test changes with sudo netplan try (auto‑rollback on failure) before applying with sudo netplan apply. For a quick DHCP setup, use a three‑line YAML with dhcp4: yes.
2. CentOS/RHEL: NetworkManager + nmcli
From CentOS 7 onward, NetworkManager is the primary manager. The nmcli CLI lets you configure networking without editing files directly.
Show current status:
$ nmcli device status
DEVICE TYPE STATE CONNECTION
ens33 ethernet connected ens33
lo loopback unmanaged --Configure a static IP:
$ nmcli con mod ens33 ipv4.addresses 10.0.0.50/24
$ nmcli con mod ens33 ipv4.gateway 10.0.0.1
$ nmcli con mod ens33 ipv4.dns 8.8.8.8
$ nmcli con mod ens33 ipv4.method manualReload and activate the connection with nmcli con reload and nmcli con up ens33. Verify the settings using nmcli device show ens33 | grep IP. Configuration files live under /etc/NetworkManager/system-connections/, but direct file edits are rarely needed. CentOS 8/RHEL 8 also provide nmstate, a declarative tool similar to netplan, though nmcli remains the most reliable.
3. Arch Linux: systemd‑networkd
Arch follows the KISS principle; systemd‑networkd is the lightweight network manager within the systemd ecosystem.
Configuration files are placed in /etc/systemd/network/ with a .network suffix. Files are processed in lexical order, allowing numeric prefixes to control priority.
DHCP configuration:
[Match]
Name=enp0s3
[Network]
DHCP=yes
[DHCP]
RouteMetric=100Static IP configuration:
[Match]
Name=enp0s3
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=1.1.1.1After editing, restart the service with sudo systemctl restart systemd-networkd and enable systemd-resolved for DNS handling: sudo systemctl enable --now systemd-resolved.
4. Alpine Linux: ifupdown
Alpine uses the classic ifupdown implementation from busybox. The main file is /etc/network/interfaces, mirroring Debian’s older style.
DHCP example:
auto eth0
iface eth0 inet dhcpStatic IP example:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1DNS servers are defined in /etc/resolv.conf (e.g., nameserver 8.8.8.8, nameserver 1.1.1.1). Apply changes with /etc/init.d/networking restart or by restarting the network service.
5. Common verification commands
After applying configurations, run the following to confirm connectivity:
ip addr – shows assigned IPs.
ip route – displays the routing table and default gateway.
ping – tests reachability of the gateway and external DNS.
ss – checks listening sockets (e.g., ss -tulpn | grep :80).
resolvectl – inspects DNS resolver status on systemd‑based systems.
6. Systematic troubleshooting flow
When connectivity fails, follow these steps (covers ~90% of cases):
Physical layer : ip link show; if the interface is DOWN, bring it up with ip link set eth0 up. Verify VM bridge settings if applicable.
IP configuration : ip addr; ensure an address is present. In DHCP mode, a missing address may indicate a dead DHCP server or MAC filtering.
Routing : ip route; confirm a default via … entry exists.
DNS : If IP ping works but hostnames do not, check /etc/resolv.conf or resolvectl status. Remember that some distros manage resolv.conf automatically.
Firewall : Temporarily disable iptables or firewalld to see if rules are blocking traffic. In production, adjust rules rather than leaving the firewall off.
SELinux (CentOS/RHEL) : Query status with getenforce. If Enforcing interferes, set permissive mode with setenforce 0 for testing, but apply proper policies for long‑term use.
Following this logical flow lets you quickly locate and fix most network issues across any Linux distribution.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
AI Agent Super App
AI agent applications, installation, large-model testing, computer fundamentals, IT operations and maintenance exchange, network technology exchange, Linux learning
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
