How to Set a Static IP Address on Ubuntu (Desktop and Server)

Configuration file with three address settings seating into a network interface through a keyed edge, above a rollback path

Ubuntu keeps a static IPv4 address in a YAML file under /etc/netplan, and a generator turns it into the configuration the system applies at boot.

So editing /etc/network/interfaces does nothing on a current release, and a netplan file with the wrong interface name applies cleanly and changes nothing. The file owns the address, and the interface name is the key to it.

What a Static IP Changes on Ubuntu

A dynamic lease is temporary by design. The router hands the machine an address from a pool, and it can hand the same one to another device tomorrow.

A static address is yours until you change it, which is what port forwards, SSH host keys, network shares and firewall rules assume.

A laptop is where the choice matters. Take one configured with a static address onto another network and it comes up holding an address that does not belong there, which is why the method switch matters as much as the address field.

SituationWhat to use
A server or appliance you reach by addressA static address in netplan
A laptop that moves between networksLeave DHCP on
A device the router can reserve for youA DHCP reservation, set in the router
A machine that must come up before the routerA static address in netplan

The file is read at boot, and the renderer key decides which backend receives it, so server images use systemd-networkd and desktops use NetworkManager.

Both backends understand the same file. I ran the whole sequence on Ubuntu 26.04.1 with netplan 1.2, and that release accepts the route syntax below without a warning.

What You Need Before You Edit Anything

A static address fails for boring reasons. A name that does not match the interface, an address the router is already handing to another machine, or a gateway copied from an article about an older release.

  • The interface name, printed by ip -brief address.
  • A free address, outside the range the router hands out.
  • The gateway address, printed by ip route show default.
  • DNS servers you trust, at least two of them.
  • Sudo access, since every netplan command here writes to /etc or /run.
  • A copy of any netplan file that already exists on the machine.

The interface name and the gateway both come from commands in that list, and both are covered in more depth by the ip command, so neither needs a tool you have to install.

I captured each command here on a test machine that sits on 192.168.56.0/24, so its numbers differ from the examples in the YAML file.

ip -brief address and ip route show default output listing the eth0 interface and the default gateway
The interface name and the gateway the configuration file has to match

Ignore lo, the loopback. The name before the at sign is the interface to configure, and the suffix after it only marks a virtual pair such as a container or VM link.

Names starting with en are Ethernet, and names starting with wl are Wi-Fi. The address the machine holds now is only a starting point, since the value you assign replaces it.

Copy the file that is already there before changing it, with sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak.

That file name is common on cloud images, and it is the first thing to check when an edit disappears after a reboot.

Set a Static IP from the Ubuntu Desktop

The desktop app writes NetworkManager configuration, and netplan reads it on the way in. Nothing in this section needs a terminal.

Open the network panel

Open Settings and pick the panel that matches your connection, Network for an Ethernet cable and Wi-Fi for a wireless one.

Click the gear icon beside the connection you are changing. The gear only appears once the row is selected, so it is worth scanning the row again if the panel looks empty.

Switch IPv4 to Manual

Open the IPv4 tab and change the method from Automatic (DHCP) to Manual, which is the only switch that has to move for a fixed address.

The address fields appear as soon as the method changes, and the values already filled in are the ones the machine is using right now. Keep them for reference before you overwrite them.

IPv4 tab set to Manual with an address, netmask and gateway entered
The IPv4 tab of the connection editor, with the method switched to Manual
FieldWhat goes in it
AddressThe address you picked, for example 192.168.1.50
Netmask255.255.255.0 for a /24 network
GatewayThe router address from ip route show default
DNSTwo resolver addresses, with the automatic switch turned off

Apply and confirm

Press Apply, then watch the panel for a moment, because the connection drops and returns with the new address.

Confirm from the terminal with ip -brief address. The panel reports what the profile asks for rather than what the interface ended up with.

Put the address back on DHCP

Set the method back to Automatic (DHCP) and press Apply, which lets the router hand out an address again on the next lease renewal. The profile keeps the DNS entries you typed.

Set a Static IP with Netplan

On a server there is no panel to click, so the file is edited directly. This is also the method to use when the address has to be in place before anyone logs in.

Create the file

Netplan reads every .yaml file in /etc/netplan in order and later file names win, so a name such as 99-static-ip.yaml overrides the 50-cloud-init.yaml that a cloud image ships. Edit it with nano or any editor you already use.

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      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]

Each key states one decision. The dhcp4 line turns the automatic lease off, addresses takes CIDR notation rather than an address and a netmask, and routes with a to: default entry is the current spelling of a default gateway.

The nameservers block is optional, and leaving it out means the address changes while the resolver does not.

Both lines sit under the interface name, which is the key the rest of the file hangs from.

A single interface can carry several addresses. List them under the same key and they all come up together, which is how a machine serves two subnets from one cable.

      addresses: [192.168.1.50/24, 192.168.1.51/24]

Validate before you apply

The generator parses the file and writes the backend configuration without touching the running interfaces, which makes it the cheap check. It reports file permissions as well.

sudo netplan generate
netplan generate warning that the configuration file permissions are too open
netplan generate warns when the configuration file is readable by other users

That warning is not fatal, and I hit it on a freshly written file. Run sudo chmod 600 /etc/netplan/99-static-ip.yaml and generate again.

A second run prints nothing at all, which is the result to wait for before applying anything.

Hold the change open with netplan try

netplan try keeps you out of a rescue console.

The new configuration is applied and left in place for 120 seconds, and the old one returns if nobody confirms it. Press Enter to keep it, or send SIGUSR1 from another session if the terminal is frozen.

sudo netplan try
sudo netplan try asking for confirmation before the change reverts
netplan try holds the new configuration for 120 seconds and reverts it unless you press Enter

An unanswered try closes itself. A countdown runs in the prompt, and the configuration reverts the moment it reaches zero.

netplan try reverting an unconfirmed configuration after five seconds
An unanswered netplan try puts the old configuration back on its own

I let a short countdown expire to confirm the rollback lands where it should. Add –timeout with a smaller number when you want to rehearse that on your own machine.

Apply and verify the address

Once the file passes the generator and survives a try, apply it.

sudo netplan apply
ip -brief address show eth0
ip route show default
ping -c 2 192.168.1.1
netplan apply followed by the new static address, the default route and a successful ping to the gateway
The new address, the default route and a ping to the gateway after netplan apply

The address line shows what the interface holds, the route line shows where traffic leaves, and the ping shows the gateway answering on that route. I ran all three checks after applying the file above, and the capture beside them is that run.

A route marked proto static comes from netplan. If a route survives without that mark, it came from somewhere else, usually a DHCP lease that has not expired yet.

Confirm the DNS and the route

An address can be static while DNS still arrives from the old lease. The resolver reports the servers it is actually using, per interface, which is the only answer that matters.

resolvectl status eth0
resolvectl status eth0 listing the DNS servers configured on the interface
resolvectl confirms which DNS servers the interface actually uses

If the old servers are still listed, the configuration did not apply or the cache is holding the previous answers, and clearing the DNS cache rules out the second case.

Set the address without an editor

Netplan can write its own file from the command line, which suits a provisioning script or a machine where the editor is not installed. The result lands in /etc/netplan/70-netplan-set.yaml, and simple values survive that route while the route list does not.

sudo netplan set ethernets.eth0.dhcp4=false
sudo netplan set ethernets.eth0.addresses=[192.168.1.50/24]

Setting a default route this way failed with a YAML parse error when I tried it. Keep the editor for the route and DNS lines, and use netplan set only for the address.

When the Static Address Does Not Stick

Every failure here prints something you can search for, apart from the silent one.

The interface name does not exist

Netplan applies the file to the interfaces it finds, and an interface it cannot find is not an error. A file keyed to enp0s3 on a machine with ens33 generates without complaint, applies without complaint, and changes nothing at all.

Compare the name in the file against ip -brief address before looking anywhere else. That comparison is worth doing even when the address looks correct in the panel.

The YAML does not parse

A single line out of step stops the file from loading, and the error names the line and the column. Netplan uses the same spaces-only indentation rules as every other YAML reader.

sudo netplan generate
netplan generate reporting invalid YAML with inconsistent indentation
A single misaligned line stops the whole file from loading

I reproduced that error by moving one line one space out of step. Tabs are the usual cause, because they look like spaces in an editor and never parse, so line the block up in multiples of two spaces and generate again.

gateway4 still loads, with a warning

Netplan 1.2 still reads the gateway4 key that older tutorials use for the default route. Copied files work today and print a deprecation warning every time.

sudo netplan generate
netplan generate warning that gateway4 has been deprecated in favour of default routes
gateway4 still loads in netplan 1.2 but the generator marks it deprecated

A file I wrote with gateway4 printed exactly that warning. The replacement is the routes block above, which also supports more than one default route and per-route metrics, so plan that change now rather than during an upgrade.

The failures that report nothing at all

The remaining causes are a short list, and each has one fix worth trying before you reboot the machine.

SymptomCauseFix
Address returns after a rebootcloud-init regenerated its own netplan fileDisable cloud-init network config, then reapply
DNS still answers from the old serversResolver cache or a stale leaseCheck with resolvectl, then clearing the DNS cache
Permissions warning on generateThe file is readable by other userssudo chmod 600 on the file
Networking is down after a bad applyThe applied file has no reachable routeWait for netplan try to revert, or restore the .bak copy from a console

A remote machine deserves one extra precaution.

Keep a second session open while you apply a network change. Prefer a try over an apply when the change touches the interface SSH uses, so a mistake ends with the old configuration rather than a rescue console.

A Fixed Address Is Only Half the Decision

An address the machine claims for itself can still be handed to another device, because the router does not know the machine has taken it. A conflict like that shows up later as an intermittent failure that is hard to attribute.

Reserve the address in the router when you control it, or set the pool to exclude that range.

The same reasoning runs through Ubuntu network configuration, and restarting networking on Ubuntu is worth knowing if a service keeps an old address after the change.

Read the file back once the work is done. It is the same view netplan will use at the next boot, and it takes one command.

sudo netplan get all

If you only need the address for one session, setting a temporary IP address is faster and undoes itself at the next reboot.

Frequently Asked Questions

The questions below come up on every machine that gets a fixed address, and each answer points back at the commands above rather than repeating them.

How do I set a static IP address in Ubuntu 24.04 or 26.04?

Create a file under /etc/netplan with dhcp4 set to false, the address in CIDR form, a routes entry with to: default and via, and your nameservers. Run sudo netplan generate to validate it, then sudo netplan apply. Both releases use the same form.

Does /etc/network/interfaces still work?

No. Netplan owns network configuration from 18.04 onward, and the ifupdown package that reads that file is not installed by default. Add the same settings to a netplan file instead.

Should I set the address on the device or reserve it in the router?

Reserve it in the router when you control the router, because a reservation leaves one file to audit. Set it on the device when the router is not yours, or when the machine has to be reachable before the router finishes booting.

Why does netplan apply change nothing on a cloud server?

Cloud images regenerate their network configuration during boot, and a conflicting file can be overwritten before netplan reads it. Edit the file cloud-init generates, or turn its network configuration off so your file is the only one left.

How do I undo a static IP address?

Set dhcp4 back to true and apply, or restore the .bak copy of the file and apply that. On a remote machine, run sudo netplan try first so an unworkable change reverts without you.