How to Configure a Static IP on Linux
Configure a static IP on Linux using Netplan, NetworkManager (nmcli), or systemd-networkd across Ubuntu, Fedora, Debian, and Arch with verified steps.
Before you start
- ▸Root or sudo access on the target machine
- ▸Console or out-of-band access recommended when working on a remote server
- ▸Known values for static IP, subnet prefix, gateway, and DNS servers
A static IP address keeps your machine reachable at a predictable address — essential for servers, home lab nodes, and any device you SSH into regularly. Modern Linux distributions handle network configuration through one of two stacks: Netplan (Ubuntu and derivatives) or NetworkManager (Fedora, RHEL, Arch, Debian, and most desktop systems). This guide covers both, with concrete commands for each distro family.
Identify Your Interface and Current Settings
Before changing anything, know your interface name and current addressing. The old eth0/wlan0 naming is largely gone; predictable names like enp3s0 or eno1 are standard.
ip addr show
Note the interface name, current IP, and the gateway. Also confirm your DNS servers:
resolvectl status
Pick values for your static configuration before proceeding. You will need: a static IP (e.g. 192.168.1.50/24), the gateway (e.g. 192.168.1.1), and at least one DNS server.
Method 1 — Netplan (Ubuntu 18.04+ and Derivatives)
Ubuntu uses Netplan as a front-end that writes to either NetworkManager or systemd-networkd. Configuration lives in /etc/netplan/ as YAML files. Indentation matters; use spaces, never tabs.
Step 1: Back Up and Edit the Netplan File
Netplan files are usually named 00-installer-config.yaml or similar. List them first:
ls /etc/netplan/
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
sudo nano /etc/netplan/00-installer-config.yaml
Step 2: Write the Static Configuration
Replace the existing content with a static block. Adjust the interface name, addresses, and gateway to match your network:
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 1.1.1.1
- 9.9.9.9
If your machine uses NetworkManager as the renderer (common on Ubuntu Desktop), change renderer: networkd to renderer: NetworkManager.
Step 3: Test and Apply
Netplan has a built-in dry-run that reverts automatically after 120 seconds if you do not confirm — a useful safety net on remote machines:
sudo netplan try
If the network comes up correctly, press Enter to confirm. To apply immediately without the timeout:
sudo netplan apply
Method 2 — NetworkManager with nmcli
NetworkManager is the default on Fedora, RHEL, Rocky Linux, Debian (desktop installs), Arch, and Ubuntu Desktop (where it runs alongside Netplan). The nmcli command-line tool is the modern, scriptable way to manage it — no need to hand-edit connection files.
Step 1: Find the Connection Name
NetworkManager tracks connections by name, not just interface name. List active connections:
nmcli connection show
The output lists NAME, UUID, TYPE, and DEVICE. Note the NAME column for your wired connection — often something like Wired connection 1 or the interface name itself.
Step 2: Set a Static IPv4 Address
Replace "Wired connection 1" and the address/gateway with your own values. The /24 CIDR notation is required:
nmcli connection modify "Wired connection 1" \
ipv4.method manual \
ipv4.addresses 192.168.1.50/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "1.1.1.1 9.9.9.9"
Step 3: Bring the Connection Down and Up
Changes take effect only after cycling the connection. Do this in a single chained command to minimise the window where you lose connectivity — critical when working over SSH:
nmcli connection down "Wired connection 1" && nmcli connection up "Wired connection 1"
If you lose your SSH session anyway, wait 10–15 seconds and reconnect to the new static IP.
Distro-Specific Package Notes
NetworkManager is installed by default on most desktop and server spins, but if it is missing:
- Debian/Ubuntu:
sudo apt install network-manager - Fedora/RHEL/Rocky:
sudo dnf install NetworkManager - Arch:
sudo pacman -S networkmanager && sudo systemctl enable --now NetworkManager
Method 3 — systemd-networkd (Servers and Minimal Installs)
On minimal Ubuntu Server installs, Alpine, or any system where NetworkManager is not running, systemd-networkd handles networking directly via Netplan (Ubuntu) or its own .network files.
For non-Ubuntu systems using systemd-networkd directly, create a network file:
sudo nano /etc/systemd/network/10-static.network
[Match]
Name=enp3s0
[Network]
Address=192.168.1.50/24
Gateway=192.168.1.1
DNS=1.1.1.1
DNS=9.9.9.9
sudo systemctl restart systemd-networkd
Verify the Configuration
After applying any method, confirm the address is assigned and the gateway is reachable:
ip addr show enp3s0
ip route show
You should see your static IP listed and a default route via your gateway. Then test external connectivity and DNS:
ping -c 4 192.168.1.1
ping -c 4 one.one.one.one
If both succeed, the static IP, routing, and DNS are all functioning.
Troubleshooting
nmcli: "Error: unknown connection"
The connection name contains special characters or spaces — quote it exactly as shown in nmcli connection show. You can also use the UUID from that output instead of the name.
Netplan apply breaks connectivity
If you lose network access after netplan apply, boot into recovery or use the console to restore your backup:
sudo cp /etc/netplan/00-installer-config.yaml.bak /etc/netplan/00-installer-config.yaml
sudo netplan apply
IP is assigned but no internet access
Check the gateway is correct with ip route show. A missing or wrong default route is the most common cause. Also verify the DNS servers are reachable: dig @1.1.1.1 example.com.
Address reverts to DHCP after reboot
With NetworkManager, check that the connection file was actually saved:
nmcli connection show "Wired connection 1" | grep ipv4
If ipv4.method still shows auto, re-run the modify command and ensure you are modifying the connection that is actually active on that interface.
Two tools fighting over the same interface
Running both Netplan (with renderer: networkd) and NetworkManager on the same interface causes conflicts. On Ubuntu Desktop, stick to renderer: NetworkManager in Netplan, or manage everything through nmcli and let Netplan delegate to it.
Frequently asked questions
- Will the static IP persist after a reboot?
- Yes — both Netplan and NetworkManager write persistent configuration. Verify with 'nmcli connection show <name> | grep ipv4.method' or by reviewing your Netplan YAML to confirm dhcp4 is false.
- Can I set a static IP on a Wi-Fi connection the same way?
- Yes. With nmcli, use the Wi-Fi connection name from 'nmcli connection show' and follow the same 'connection modify' steps. Netplan supports wireless too, but you also need to supply the SSID and credentials in the YAML.
- What subnet mask should I use?
- Use the same prefix length as your network. Home and small office networks are almost always /24 (255.255.255.0). Your router's DHCP range or existing devices on the network will confirm this.
- How do I pick a static IP that won't conflict with DHCP leases?
- Configure your router's DHCP pool to exclude the address range you use for static assignments. For example, set DHCP to hand out 192.168.1.100–200 and use 192.168.1.1–99 for static devices.
- Does this work the same way for IPv6?
- The process is nearly identical. In Netplan use 'dhcp6: false' and 'addresses' with a /64 prefix. With nmcli, modify 'ipv6.method' and 'ipv6.addresses' instead of their ipv4 counterparts.
Related guides
Build a Mesh VPN with Nebula
Build a fully self-hosted mesh VPN with Nebula: create a CA, sign node certs, configure lighthouses, enforce group-based firewall rules, and run as a systemd service.
Common Linux Network Ports Reference
Learn Linux port ranges, read /etc/services, find what's listening with ss and nmap, and apply solid firewall rules to expose or block the right ports.
Expose a Service with Cloudflare Tunnel
Expose local services to the internet without port-forwarding using Cloudflare Tunnel. Install cloudflared, create a named tunnel, configure ingress rules, and run as a systemd service.
firewalld Zones and Rich Rules in Practice
Assign interfaces to firewalld zones, open services, write rich rules for source-based and rate-limited policies, and manage runtime vs permanent config.