Skip to content

Configuring Network Interfaces on Linux

This guide shows concrete commands and configuration examples for common Linux network setups. It focuses on modern tools: NetworkManager, systemd-networkd, and Ubuntu’s netplan frontend. Keep in mind distributions differ in defaults; adapt file paths accordingly.

Check interfaces and addresses:

Terminal window
ip addr show
ip route show
ss -tuln

Check kernel messages and network service logs for device and driver issues:

Terminal window
sudo journalctl -k | tail -n 200
sudo journalctl -u NetworkManager -n 200
sudo dmesg | grep -i ethernet

Bring an interface up and request DHCP:

Terminal window
sudo nmcli device status
sudo nmcli device connect eth0
sudo nmcli device show eth0

Create a static IPv4 connection using nmcli:

Terminal window
sudo nmcli connection add type ethernet ifname eth0 con-name static-eth0 ipv4.method manual ipv4.addresses 192.0.2.10/24 ipv4.gateway 192.0.2.1 ipv4.dns "8.8.8.8 1.1.1.1"
sudo nmcli connection up static-eth0

Use nmtui for an interactive TUI on systems with NetworkManager:

Terminal window
sudo nmtui

Drop a .network file in /etc/systemd/network/ for DHCP:

[Match]
Name=eth0
[Network]
DHCP=ipv4

For a static address:

[Match]
Name=eth0
[Network]
Address=192.0.2.20/24
Gateway=192.0.2.1
DNS=8.8.8.8

Then restart the service:

Terminal window
sudo systemctl restart systemd-networkd
sudo networkctl status eth0

Netplan YAML lives in /etc/netplan/ and translates to NetworkManager or systemd-networkd backends. Example static config:

network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses: [192.0.2.30/24]
gateway4: 192.0.2.1
nameservers:
addresses: [8.8.8.8,1.1.1.1]

Apply with:

Terminal window
sudo netplan apply

On systems using systemd-resolved, check status with:

Terminal window
systemd-resolve --status
resolvectl status

Temporary DNS test:

Terminal window
dig @8.8.8.8 example.com +short
ping -c2 8.8.8.8

Troubleshooting steps (practical checklist)

Section titled “Troubleshooting steps (practical checklist)”
  1. Verify link: cat /sys/class/net/eth0/operstate and ethtool eth0.
  2. Check driver/kernel messages: dmesg | grep -i eth0 and sudo journalctl -k.
  3. Confirm IP and routes: ip addr, ip route.
  4. Test connectivity: ping, traceroute, and curl --interface eth0 https://ifconfig.co.
  5. Capture packets for analysis: sudo tcpdump -i eth0 -n -s 0 -w /tmp/cap.pcap.
  6. Check for NetworkManager interfering when using systemd-networkd (or vice versa) — ensure only one manager controls the interface.
  • If an interface does not come up after a configuration change, run sudo ip link set dev eth0 down then sudo ip link set dev eth0 up, and sudo systemctl restart NetworkManager or systemctl restart systemd-networkd as relevant.
  • For flaky DHCP, clear leases (/var/lib/NetworkManager/ or DHCP client state) and request a fresh lease.

This guide is intentionally concrete — tell me which distribution(s) you want exact commands for (Debian/Ubuntu, Fedora, Arch) and我会补齐更精确的步骤与示例。