Configuring Network Interfaces
Networking Basics covers reading a machine's current network state with the ip command - this covers actually changing it persistently, which depends on which of three different configuration systems a distribution uses.
Networking Basics covers ip addr add and ip route add for inspecting and changing network state live.
The catch: changes made directly with ip don't survive a reboot, and
in practice are usually overwritten immediately anyway by whichever
service manages the interface. Setting a static address that actually
sticks means configuring that service directly.
Three systems, by distribution family
| Tool | Typical on | Config style |
|---|---|---|
NetworkManager (nmcli) |
Most desktop distros, and increasingly servers | Commands, or /etc/NetworkManager/system-connections/ |
| Netplan | Ubuntu (server and desktop) | YAML in /etc/netplan/ |
| systemd-networkd | Minimal/server installs, Arch | .network files in /etc/systemd/network/ |
Check which one is actually active before editing anything - editing
Netplan's YAML has no effect if systemd-networkd is the service
actually managing the interface, and vice versa:
systemctl status NetworkManager
systemctl status systemd-networkd
NetworkManager: nmcli
nmcli con show # list configured connections
nmcli con show "Wired connection 1" # full detail on one
nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.50/24
nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1
nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 1.1.1.1"
nmcli con mod "Wired connection 1" ipv4.method manual
nmcli con up "Wired connection 1" # apply the changes
Each nmcli con mod edits one setting on a saved connection profile;
nothing takes effect until con up re-activates it.
Netplan (Ubuntu)
# /etc/netplan/01-static.yaml
network:
version: 2
ethernets:
enp3s0:
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
sudo netplan try # apply with automatic rollback if it breaks connectivity
sudo netplan apply # apply permanently
netplan try is worth using over apply directly for remote machines -
it reverts automatically after a short countdown unless you confirm,
so a config mistake that cuts off SSH access doesn't lock you out.
Netplan is a YAML front-end; depending on the renderer setting it
configures either NetworkManager or systemd-networkd underneath, rather
than being a third independent mechanism.
systemd-networkd
# /etc/systemd/network/20-wired.network
[Match]
Name=enp3s0
[Network]
Address=192.168.1.50/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=1.1.1.1
sudo systemctl restart systemd-networkd
The [Match] section targets which interface(s) the file applies to;
[Network] holds the actual configuration. This is the lowest-level of
the three - no daemon-specific commands, just a config file and a
restart.
Legacy: /etc/network/interfaces
Older Debian-based systems (and Ubuntu before Netplan) used a single
/etc/network/interfaces file with ifupdown managing it. Rare on
current installations, but still occasionally encountered on
long-lived servers:
auto enp3s0
iface enp3s0 inet static
address 192.168.1.50
netmask 255.255.255.0
gateway 192.168.1.1
After changing anything
Confirm with the same commands used to inspect state in Networking Basics:
ip addr show
ip route show
If the new configuration doesn't seem to have taken effect at all, double back to confirming which of the three systems above is actually active on this machine - the single most common reason a config file edit appears to do nothing.
See VPN Basics with WireGuard for configuring a virtual interface that tunnels traffic to another network entirely, rather than just addressing a physical one.