Migrate to RunxBuild and earn up to $50 in hosting credit on your first deposit.

Calculate your savings
unxBuild

Ubuntu Set Static IP Address: Netplan YAML with the Right Options

Sean

Platform Writer

Jul 06, 2026
5 min read

Set a static IP on Ubuntu by writing a Netplan YAML file in /etc/netplan/, with dhcp4: no and an addresses: block, then running sudo netplan apply. The right file is 00-installer-config.yaml for a fresh install. The right verification is ip a show to see the new IP. The team that has the right YAML has a static IP that survives a reboot.

Ubuntu Set Static IP Address: Netplan YAML with the Right Options

Table of contents

The right YAML

The right Netplan YAML for a static IP:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8

Replace enp0s3 with the actual interface name. Replace 192.168.1.100/24 with the static IP and CIDR. Replace 192.168.1.1 with the gateway. Replace the nameservers with whatever you want to use.

Finding the interface name

The right command to find the interface name:

ip a

The output shows all interfaces with their names, IPs, and states. The right answer is to use the interface name that is state UP and has a link. The wrong answer is to use eth0 — modern systemd names interfaces based on the hardware (enp0s3, ens192, etc.).

Applying the config safely

The right command to apply the config:

sudo netplan apply

The right command for a remote box where the wrong config would lock you out:

sudo netplan try

netplan try reverts automatically after 120 seconds if the new config breaks connectivity. The right answer is to use try on remote boxes, apply on local boxes.

Common mistakes

The most common mistake is wrong indentation. Netplan YAML is whitespace-sensitive, and a single misplaced space causes netplan apply to fail. The right answer is two spaces per level, no tabs.

The second mistake is leaving dhcp4: yes while also specifying addresses:. The right answer is dhcp4: no for a static config.

The third mistake is a wrong CIDR. The right answer is to use the actual subnet’s CIDR. The wrong answer is to copy /24 from a tutorial and assume it works on every network.

Verifying the change

The right verification is three commands:

ip a show enp0s3
ip route
resolvectl status

ip a shows the new IP. ip route shows the default route through the right gateway. resolvectl status shows the DNS servers.

FAQ

What if I lose connection after netplan apply?

Wait 120 seconds if you used netplan try — the old config comes back. If you used netplan apply and lost connection, the right answer is to use a cloud provider’s console or IPMI to access the box and revert the YAML.

Can I have multiple static IPs?

Yes. Add them to the addresses: list. The right answer is to ensure each is in the right subnet or with the right routing.

What about IPv6?

Replace dhcp4 with dhcp6 and add the IPv6 prefix to addresses:. The right answer is to set dhcp6: yes and use SLAAC for workstations; the right answer is to set dhcp6: no and specify the address for servers.

Why does my static IP not work after a reboot?

The most common cause is cloud-init overwriting the config. The right answer is to set network: {config: disabled} in /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg.

What is the difference between networkd and NetworkManager?

networkd is systemd’s network daemon, the right answer for servers. NetworkManager is the right answer for desktops. Netplan generates configs for whichever one is active.

Can I keep the file in a different name?

Yes, as long as it ends with .yaml. The files are applied in lexical order, so 00- files come before 99- files. The right answer is to use a higher number to override an earlier file.

If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.

Useful related references:

#ubuntu#guide#dev-infra#tutorial