Setting a static IP address on Ubuntu and Debian (Netplan, interfaces, nmcli)

Servers, printers or a Raspberry Pi should always be reachable at the same address. How to set a static IP address depends on which tool manages the network: Netplan (Ubuntu Server), ifupdown with /etc/network/interfaces (Debian without a desktop) or NetworkManager (desktops and Raspberry Pi OS).

A tip up front: it is often easier to assign the fixed address on the router with a DHCP reservation (on a Fritz!Box under Home Network → Network → edit device → “Always assign this network device the same IPv4 address”). Then nothing has to be changed on the device itself.

Name of the network interface

ip -br addr

These days the interface is no longer called eth0 but, for example, ens18, enp3s0 or eno1.

Ubuntu Server: Netplan

The configuration is a YAML file in /etc/netplan/, e.g. 50-cloud-init.yaml or 01-netcfg.yaml. Example for a static address:

network:
  version: 2
  ethernets:
    ens18:
      dhcp4: false
      addresses:
        - 192.168.178.50/24
      routes:
        - to: default
          via: 192.168.178.1
      nameservers:
        addresses: [192.168.178.1, 9.9.9.9]
        search: [fritz.box]

In YAML the indentation counts – always spaces, never tabs. The file should be readable by root only (sudo chmod 600 /etc/netplan/*.yaml). Older guides still use gateway4: – that is deprecated and has been replaced by the routes block.

Apply safely:

sudo netplan try

netplan try activates the new configuration and reverts it automatically after 120 seconds unless you confirm with Enter. So if you lock yourself out over SSH, the server is reachable again shortly afterwards. Then run sudo netplan apply.

On cloud and VM images, cloud-init may overwrite the file on the next boot. You can prevent that with:

echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

Debian: /etc/network/interfaces

auto ens18
iface ens18 inet static
    address 192.168.178.50/24
    gateway 192.168.178.1
    dns-nameservers 192.168.178.1 9.9.9.9

The dns-nameservers line only takes effect if the resolvconf package is installed. Otherwise enter the DNS servers directly in /etc/resolv.conf. Apply with sudo systemctl restart networking – when connected via SSH, it is better to plan for a reboot of the machine.

NetworkManager (desktop, Raspberry Pi OS)

nmcli connection show                       # find the name of the connection

sudo nmcli connection modify "Wired connection 1" \
  ipv4.method manual \
  ipv4.addresses 192.168.178.50/24 \
  ipv4.gateway 192.168.178.1 \
  ipv4.dns "192.168.178.1 9.9.9.9"

sudo nmcli connection up "Wired connection 1"

To go back to DHCP, use ipv4.method auto and empty values for address, gateway and DNS.

Verify

ip -br addr
ip route
resolvectl status       # DNS (with systemd-resolved)
ping -c 3 linux-survival-blog.de

Originally published in 2012, completely revised in November 2026.