How to assign a static IP address in Linux: a complete guide by distro and tool

Last update: 16/10/2025
Author Isaac
  • En Linux There is no single universal command: persistence depends on interfaces, Netplan, ifcfg or NetworkManager.
  • Identifying the interface and backing it up before editing is key to avoiding connectivity loss.
  • Always check with IP address, routes, and ping; if the name fails, check your DNS settings.

Static IP in Linux

Setting up a static IP in Linux is not a single trick, but a set of techniques that depend on the distribution, version, and network stack you have enabled; There is no single universal command that solves it for all cases and in a persistent way.

Additionally, there are two distinct plans: the temporary setting (which disappears when the network or system is restarted) and the persistent setting (which is saved in files or profiles and survives reboots). In the Debian/Ubuntu families, you can tap / etc / network / interfaces or use Netplan; in Red Hat/Rocky/AlmaLinux NetworkManager and ifcfg are the rules; in Arch Linux you can use netctl or systemd-networkd, and in all of them nmcli/nmtui shines as a modern alternative.

What is a static IP and why you might care?

A static IP address is one that does not change with There nor does it depend on a DHCP server; is key for servers, port forwarding, tunnels, remote access (SSH, VPN), NAS and services with DDNS.

In domestic or laboratory environments it is usually sufficient Dynamic IP (DHCP), but when you want stability or to publish internal services, you fix the IP so that it doesn't change; This avoids “surprises” like that router assign another address and port forwarding will stop working.

Configure network in Linux

Before you touch anything: Identify the interface and make a backup

The first thing is to know which interface you are going to configure (cable: usually starts with e, like enp0s3/enp2s0/eth0; wifi: starts with w, like wlan0/wlp3s0); to list interfaces with colors you can use ip -c link show and to see the addresses, ip -c addr show. If you work in Virtual machines, check the Network types in VirtualBox and VMware to choose the appropriate settings.

If you prefer a classic exit, it is also valid. ifconfig -a (on modern distros you may need to install net-tools); check the target interface and confirm if it is currently under DHCP or already have a static IP.

Before editing system files, save a backup: for example, copy / etc / network / interfaces to your $HOME with a date so you have a “plan B” in case you make a mistake.

sudo cp /etc/network/interfaces ~/interfaces.$(date +%Y%m%d).bk

In many operations you will need administrative privileges; you can log in as root or put before sudo to each command, which is essential when modifying network configuration files.

Static Network in Linux

Debian and derivatives: classic method with /etc/network/interfaces

In Debian 11 and previous versions it is common to manage the network with the file / etc / network / interfaces; first locate the interface (for example, eth0 or enp2s0) and edit the file with your favorite editor.

sudo vim /etc/network/interfaces
# o
sudo nano /etc/network/interfaces

Find your interface blocks. If it was set to DHCP (e.g., allow-hotplug eth0 + iface eth0 inet dhcp), change it to static; the typical syntax includes car and an “inet static” block.

auto eth0
iface eth0 inet static
    address 192.168.1.25       # IP del equipo
    netmask 255.255.255.0      # Máscara (equivale a /24)
    gateway 192.168.1.1        # Puerta de enlace
    dns-nameservers 192.168.1.1 1.1.1.1 8.8.8.8

In some scenarios, you'll also see fields like network and broadcast (192.168.1.0 and 192.168.1.255 on /24); these aren't always required, but you can include them if your guide or template allows for them. the essentials It is address, netmask, gateway and DNS.

  The right way to Share Photographs in Google Photographs App

Save and restart the network service to apply; on standard Debian it works fine. systemctl restart networking.service and then validate with ip addr that the IP is the one you have set.

sudo systemctl restart networking.service
ip -c addr show eth0

On Ubuntu variants, you may find interface-specific ifup units (e.g., ifup@enp2s0); if you're unsure, fall back to the general pattern with networking.service; The idea is to recharge the network battery for the change to take effect.

Modern Ubuntu Server: Step-by-Step Netplan

Since Ubuntu 17.10, and especially in 20.04 LTS and later, Netplan manages network configuration by reading YAML files in /etc/netplan/*.yaml; the syntax is sensitive to indentation and spaces.

Check the current file (e.g., 00-installer-config.yaml or 50-cloud-init.yaml) and confirm the current state; by default, you should see something like this: dhcp4: true, which means that the IP is obtained by DHCP.

cat /etc/netplan/00-installer-config.yaml
# Ejemplo típico por defecto:
# network:
#   ethernets:
#     enp0s3:
#       dhcp4: true
#   version: 2

Edit the YAML and disable DHCP by changing dhcp4: true to dhcp4: no (or false), adding addresses (with mask in CIDR notation), gateway4 and nameservers; respects the indentations, because one less space can break the parsing.

sudo nano /etc/netplan/00-installer-config.yaml

network:
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: 
      gateway4: 192.168.1.1
      nameservers:
        addresses: 
  version: 2

If the directory contains no files (rare, but it can happen), you can regenerate the basic ones with sudo netplan generate and then apply; under normal conditions it will be enough to launch apply and check.

sudo netplan apply
ip addr

If the changes fail, Netplan will notify you and won't leave the network "broken." Check the YAML syntax and run apply again when you're done. the “ip a” command is your ally to verify the status after each adjustment.

Red Hat, Rocky and AlmaLinux: ifcfg and NetworkManager (nmcli/nmtui)

On RPM-based systems, ifcfg files still coexist in / Etc / sysconfig / network-scripts / with NetworkManager as the management layer; you can do it the old-fashioned way by editing your interface's ifcfg.

sudo nvim /etc/sysconfig/network-scripts/ifcfg-enp0s2

TYPE="Ethernet"
BOOTPROTO="none"
NAME="enp0s2"
ONBOOT="yes"
HWADDR="08:00:27:80:63:19"
IPADDR0="192.168.225.150"
PREFIX0="24"
GATEWAY0="192.168.225.1"
DNS1="8.8.8.8"

Make sure to set BOOTPROTO="none" to indicate you're not using DHCP, and ONBOOT="yes" to bring up the interface; save and restart the network service, and check with ip addr that it's reflected; so it remains persistent. If you need more context about the MAC address and network mask, check that reference.

sudo systemctl restart network
ip a s enp0s2

With NetworkManager, you can prefer nmcli, which is convenient and declarative; modify the connection profile (it doesn't always match the interface name) by specifying ip4, gw4, and DNS, and then activate the profile.

nmcli connection show
sudo nmcli connection modify "eth0" ip4 192.168.1.20/24 gw4 192.168.1.101 ipv4.dns 8.8.8.8
sudo nmcli connection up "eth0"

If you want a semi-graphic mode in terminal, install the NetworkManager TUI and use its wizard; it's handy for making sure you don't miss any fields; then restart NetworkManager if you see it necessary.

sudo dnf install NetworkManager-tui
nmtui
sudo systemctl restart NetworkManager

Arch Linux: netctl or systemd-networkd

In Arch you have two widely used paths: netctl (profiles inspired by systemd) or going “naked” with systemd-networkd; both are valid and the choice depends on your environment.

  Designing Word documents with a UX focus: practical guide and examples

Using netctl, copy the example profile ethernet-static to /etc/netctl/ with the name of your interface, edit address, mask (in CIDR), gateway and DNS; then enable and launch the profile.

sudo cp /etc/netctl/examples/ethernet-static /etc/netctl/enp2s0
sudo nvim /etc/netctl/enp2s0

Description='A basic static ethernet connection'
Interface=enp2s0
Connection=ethernet
IP=static
Address=('192.168.1.102/24')
Gateway=('192.168.1.1')
DNS=('8.8.8.8' '8.8.4.4')

sudo netctl enable enp2s0
sudo netctl start enp2s0

If you had a DHCP client running (such as dhcpcd), stop and disable its units so they don't overwrite your static settings; Avoiding conflicts here is essential.

sudo systemctl stop dhcpcd
sudo systemctl disable dhcpcd

With systemd-networkd you create a .network file that matches your interface in /etc/systemd/network/, specify the IP, gateway, and DNS, and enable the service; after rebooting, check with IP addr.

sudo nvim /etc/systemd/network/enp2s0.network


Name=enp2s0


Address=192.168.1.102/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=8.8.4.4

sudo systemctl disable netctl@enp2s0.service  # si venías de netctl
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd

Before closing it, check again that there are no remaining competing profiles or services; systemctl list-unit-files helps you detect residual netctl units or DHCP clients.

GUI and alternatives on Linux desktops

If you are in an environment with a graphical interface (GNOME, KDE, etc.), you can open the “Network Connections” and in the wired or wireless connection choose the “Manual” method (IPv4), filling in Address, Mask and Gateway; You can also define DNS on that same screen.

This approach is convenient for user computers and works with NetworkManager underneath; however, it is useful to know the console methods for servers and remote administrations, where the GUI is not always available or recommended.

Apply changes: Service and system restarts

After editing, it is usually enough to restart the network daemon: on classic Debian/Ubuntu, systemctl restart networking.service; in Netplan, netplan apply; in NetworkManager, systemctl restart NetworkManager or disable/enable the profile with nmcli.

# Debian/Ubuntu tradicional
sudo systemctl restart networking.service

# Netplan
sudo netplan apply

# NetworkManager
sudo systemctl restart NetworkManager

On distros with old-style ifcfg, use systemctl restart network; on Arch with netctl, netctl restart or stop/start; if the reboot service is unavailable, you can reboot the computer with systemctl reboot or shut down with systemctl poweroff.

sudo systemctl restart network
sudo netctl restart enp2s0
# Alternativas de control del sistema
sudo systemctl reboot
sudo systemctl poweroff

Connectivity verification and testing

Check that the address is applied with ip -c addr show and that the default route points to the gateway you defined; if everything checks out, move on to testing connectivity.

  What to do if the mouse pointer doesn't appear in Windows 11: Complete guide with all the solutions

Start by pinging the gateway (e.g., 192.168.1.1) and then a domain (google.com) to also check DNS resolution; if ping by IP works but by name doesn't, check your DNS servers.

ip -c addr show enp0s3
ping -c 4 192.168.1.1
ping -c 4 google.com

In case of problems, go back to the source: check the file you touched (/etc/network/interfaces or Netplan's YAML), confirm that there are no active DHCP clients overwriting it, and repeat the cycle. apply and verify.

Is there a single “magic command” to fix IP in Linux?

No, and here's the crux of the matter: in Linux there are several ways to leave a fixed IP, and they depend on the network manager and the distro; what does exist is a generic command to assign an IP temporarily, for example with ip addr add.

# Asignación temporal (no persiste tras reiniciar red/sistema)
sudo ip addr add 192.168.1.50/24 dev enp0s3
sudo ip route add default via 192.168.1.1

This configuration is not persistent; to make it survive reboots you must edit files (interfaces, ifcfg, Netplan) or use profiling tools like nmcli/nmtui; that's why teachers They usually ask for your distro’s method, not a “single command.”

Useful notes and nuances to remember

In the RPM world, BOOTPROTO=»none» Specify Manual IP and BOOTPROTO=”dhcp” enables automatic acquisition; the IPADDR0/PREFIX0/GATEWAY0/DNS1 fields allow multiple entries with suffixes 0, 1, or 2 if needed.

In classic Debian, the key is to use “inet static” and not forget gateway and dns-nameservers; in Netplan, watch the indentation and remember that the masks are in CIDR format. addresses (for example, /24 for 255.255.255.0).

If you work with exotic devices or vintage labs, you may have not-so-recent versions (such as Debian 11 on a Pine A64 SBC) and the classic interface method will solve your problem; adapts the method to what actually runs stable on your computer.

Finally, if something stops responding remotely after applying network changes, wait for the service to reload and check routes from the local console; Backup from the original file saves you the hassle of reverting quickly.

With all the above you already have a complete map by families and tools: classic method in Debian/Ubuntu, YAML with Netplan for modern servers, ifcfg and NetworkManager in Red Hat/Rocky/Alma and netctl or systemd-networkd profiles in Arch; choose the route that fits your distro and context, remember to check with IP addr and ping, and don't forget DNS if you run out of names.

How to configure a static IP on Debian, Arch, Ubuntu, openSUSE, and Fedora
Related article:
How to configure a static IP address on Debian, Arch, Ubuntu, openSUSE, and Fedora