Table of Contents
Understanding How Linux Stores Network Configuration
Linux distributions use different mechanisms and file locations for network configuration, but they all solve the same problems:
- Assigning IP addresses
- Setting gateways and routes
- Configuring DNS
- Choosing which interfaces are up or down at boot
You should always know what networking stack your distro uses before editing anything:
- Classic scripts (e.g.,
ifconfig,ifupdown,/etc/network/interfaces) - NetworkManager
systemd-networkd- Distro‑specific tools (e.g.,
netplanon Ubuntu,wickedon openSUSE,ifcfgon RHEL/CentOS/Fedora)
The safest workflow:
- Identify the active networking system.
- Locate the correct configuration file(s).
- Edit with root privileges.
- Validate syntax if a tool is available.
- Apply/reload the configuration in a controlled way.
The sections below focus on editing configuration files for the most common setups.
Identifying Which System Manages Networking
Use these checks (you can run more than one):
- Check running services:
systemctl is-active NetworkManager
systemctl is-active systemd-networkd- Look for distro indicators:
- Ubuntu 18.04+ desktop/server: usually netplan + NetworkManager or
systemd-networkd - RHEL/CentOS/Fedora: historically
ifcfg-*+networkservice, more recently NetworkManager - Debian/older Ubuntu:
/etc/network/interfaces - openSUSE:
wicked - Check files:
/etc/netplan/present ⇒ netplan in use/etc/sysconfig/network-scripts/ifcfg-*⇒ RHEL‑style scripts/etc/systemd/network/*.network⇒systemd-networkd
Only edit the system that is actually active; mixing them often leads to confusion.
Editing `/etc/network/interfaces` (Debian-Style)
Used by: classic ifupdown on Debian/old Ubuntu.
Main file: /etc/network/interfaces
Additional per‑interface snippets may live in /etc/network/interfaces.d/.
Basic Structure
Sections begin with a auto or allow-hotplug line, followed by an iface stanza:
# Bring up at boot
auto enp0s3
# Interface configuration
iface enp0s3 inet static
address 192.168.1.50/24
gateway 192.168.1.1
dns-nameservers 1.1.1.1 8.8.8.8Key parts:
auto enp0s3– bring interface up at boot withifup -aiface enp0s3 inet static– IPv4 (inet) with static addressingaddress,gateway– obviousdns-nameservers– integrates with resolvconf//etc/resolv.confon many systems
For DHCP:
auto enp0s3
iface enp0s3 inet dhcpCommon Options
Inside an iface block:
address 192.168.1.50/24or separatenetmask:
address 192.168.1.50
netmask 255.255.255.0gateway 192.168.1.1dns-nameservers 1.1.1.1 8.8.4.4dns-search example.com
Applying Changes
After editing:
sudo ifdown enp0s3 && sudo ifup enp0s3
# or reboot if you’re unsureBe careful when doing this over SSH: misconfiguration can lock you out.
Editing Netplan Configuration (Ubuntu 18.04+)
Used by: Ubuntu server/desktop.
Netplan converts YAML in /etc/netplan/ into backend configs (NetworkManager or systemd-networkd).
Main files:
/etc/netplan/*.yaml(usually01-netcfg.yamlor similar)
YAML Basics for Netplan
- Indentation is spaces only, consistent (usually 2 spaces).
- Key order doesn’t matter, indentation does.
- Inline comments start with
#.
Example: Static IP on Ethernet
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses:
- 192.168.1.50/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
search:
- example.comCommon Fields
renderer: usuallynetworkd(servers) orNetworkManager(desktops)- Under
ethernetsorwifis: dhcp4: yes|noaddresses: [ "IP/CIDR", ... ]gateway4: IPnameservers: addresses: [list]optional: trueto avoid boot waits
For DHCP:
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s3:
dhcp4: yesValidating and Applying
After editing:
sudo netplan try- Temporarily applies config and offers a rollback timer; safer over SSH.
If satisfied:
sudo netplan apply
If you get YAML errors, netplan will show line/column hints; double‑check indentation and colons.
Editing `systemd-networkd` Files
Used by: some servers (Debian, Ubuntu, Arch, etc.), containers, minimalist systems.
You configure networkd directly if there is no netplan/NetworkManager or if you choose to.
Key directories:
/etc/systemd/network/– admin configs (preferred)/lib/systemd/network/or/usr/lib/systemd/network/– packaged defaults (don’t edit directly)
`.network` File Structure
A .network file describes how systemd-networkd should manage an interface.
Example static IP:
# /etc/systemd/network/10-enp0s3.network
[Match]
Name=enp0s3
[Network]
Address=192.168.1.50/24
Gateway=192.168.1.1
DNS=1.1.1.1 8.8.8.8
Domains=example.comFor DHCP:
[Match]
Name=enp0s3
[Network]
DHCP=yesCommon Sections
[Match]Name=enp0s3or wildcard likeName=enp*[Network]DHCP=yesorDHCP=ipv4Address=IP/CIDRGateway=IPDNS=IP1 IP2 ...Domains=example.com
Enabling and Applying
Ensure services are enabled:
sudo systemctl enable --now systemd-networkd systemd-resolved
After changing .network files:
sudo systemctl restart systemd-networkd
In some setups you also link /etc/resolv.conf to systemd-resolved’s stub, but that belongs in DNS configuration specifics.
Editing RHEL/Fedora `ifcfg-*` Files
Used by: traditional RHEL/CentOS/Fedora networking (still supported, sometimes behind NetworkManager).
Location: /etc/sysconfig/network-scripts/ifcfg-<interface>
Example static IPv4:
# /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.1.50
PREFIX=24
GATEWAY=192.168.1.1
DNS1=1.1.1.1
DNS2=8.8.8.8For DHCP:
TYPE=Ethernet
BOOTPROTO=dhcp
NAME=ens33
DEVICE=ens33
ONBOOT=yesKey fields:
BOOTPROTO=none|dhcpONBOOT=yes|no– bring interface up at bootIPADDR,PREFIX(instead of netmask),GATEWAYDNS1,DNS2– populate resolver configs
Apply changes with:
sudo nmcli connection reload # if NetworkManager manages them
# or legacy:
sudo systemctl restart network
Beware: modern RHEL/Fedora relies primarily on NetworkManager; editing ifcfg-* is often reflected via NetworkManager rather than the old network service.
Editing DNS Configuration Files
DNS may be managed by different components; two common file approaches:
`/etc/resolv.conf`
Traditional file used by the resolver library.
Typical content:
nameserver 1.1.1.1
nameserver 8.8.8.8
search example.comHowever, on modern systems this file is often auto‑generated by:
- NetworkManager
systemd-resolved- DHCP clients
You can check with:
ls -l /etc/resolv.conf
If it is a symlink to something like /run/systemd/resolve/stub-resolv.conf, editing it will not persist across reboots. In that case, configure DNS in:
- netplan or
.networkfiles (as shown earlier), or - NetworkManager (usually not by editing files directly, but via
nmclior GUI).
`/etc/hosts`
Local static hostname resolution. Manual entries here override DNS:
127.0.0.1 localhost
192.168.1.10 app-server.local app-serverTypical use:
- Permanent custom names for your local machines
- Simple testing of hostnames before DNS is available
No service restart is required; changes take effect immediately.
openSUSE `wicked` and `ifcfg` Files (Brief)
openSUSE traditionally uses wicked with ifcfg-* files under /etc/sysconfig/network/:
/etc/sysconfig/network/ifcfg-<interface>- General settings:
/etc/sysconfig/network/config
Structure is similar in spirit to RHEL ifcfg-*, but keys differ (e.g., BOOTPROTO, STARTMODE, etc.). When in doubt, use distro documentation or yast / wicked CLI tools and inspect the generated files.
Safe Editing Practices
When editing any network configuration file:
- Use root privileges safely
sudo nano /path/to/file- Or
sudoedit /path/to/fileto reduce mistakes. - Make a backup first
sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak- Validate syntax when possible
netplan trysystemd-analyze verify /etc/systemd/network/*.network(for advancedsystemd-networkdusage)- YAML linting tools for netplan files.
- Avoid locking yourself out over SSH
- Keep an open root console (physical, serial, or virtual machine console).
- Use tools like
netplan trywhich auto‑revert on failure. - Make incremental changes instead of large rewrites.
- Document your changes
- Add brief comments in files (
# why this IP, what service, date). - Keep a simple change log, especially on servers.
By understanding how to safely edit your distribution’s network configuration files, you gain precise, scriptable control over IP addressing, routing, and DNS, which is essential for reliable Linux system administration.