How to Configure Static IP Address on Ubuntu

In most network configurations, the IP address is assigned dynamically by the router DHCP server. Setting a static IP address may be required in different situations, such as configuring port forwarding, running a media server , or managing a server over SSH.
This guide shows how to configure a static IP address using Netplan on Ubuntu Server and GNOME Settings on Ubuntu Desktop. The Netplan steps apply to current supported Ubuntu releases, including Ubuntu 24.04 and Ubuntu 26.04.
Quick Reference
| Task | Command |
|---|---|
| Show network interfaces | ip link |
| Show current IP addresses | ip addr |
| List Netplan files | ls /etc/netplan/ |
| Test Netplan changes safely | sudo netplan try |
| Apply Netplan changes | sudo netplan apply |
| Show one interface | ip addr show dev ens3 |
Configuring a Static IP Address Using DHCP
Before changing the configuration on the device itself, consider setting a static DHCP lease on your router. The device still receives its address from DHCP, but the router always hands out the same IP, which is enough for most use cases such as port forwarding or local services. Static DHCP, also called DHCP reservation, is a feature found on most routers, and it works by mapping the IP address to the device MAC address.
The steps for configuring a DHCP reservation vary from router to router. Consult the vendor’s documentation for more information.
Netplan
Ubuntu 17.10 and later uses Netplan
as the default network configuration tool. Older Ubuntu versions used ifconfig
and the /etc/network/interfaces file.
Netplan configuration files are written in YAML syntax with a .yaml file extension. To configure a network interface with Netplan, you need to create a YAML
description for the interface, and Netplan will generate the required configuration files for the chosen renderer tool.
Netplan supports two renderers, NetworkManager and systemd-networkd. NetworkManager is mostly used on desktop systems, while systemd-networkd is common on servers without a GUI.
Configuring a Static IP Address on Ubuntu Server
Ubuntu identifies network interfaces using predictable network interface names. The exact name depends on the hardware, virtual machine, or cloud provider.
The first step toward setting up a static IP address is identifying the name of the ethernet interface you want to configure. To do so, use the ip link
command, as shown below:
ip linkThe command prints a list of all the available network interfaces. In this example, the name of the interface is ens3:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ffNetplan configuration files are stored in the /etc/netplan directory. You may find one or more YAML files in this directory. The name of the file differs between installations. Common names include 00-installer-config.yaml, 01-netcfg.yaml, and 50-cloud-init.yaml.
To assign a static IP address on the network interface, open the YAML configuration file with your text editor :
sudo nano /etc/netplan/01-netcfg.yamlnetwork:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: yesBefore changing the configuration, here is what the file does.
Each Netplan YAML file starts with the network key. The first required element is the version of the network configuration format, and the second one is the device type. The device type can be ethernets, bonds, bridges, or vlans.
The configuration above also has a line that shows the renderer type. Out of the box, if you installed Ubuntu in server mode, the renderer is configured to use networkd as the back end.
Under the device’s type (ethernets), you can specify one or more network interfaces. In this example, we have only one interface ens3 that is configured to obtain IP addressing from a DHCP server dhcp4: yes.
To assign a static IP address to the ens3 interface, edit the file as follows:
- Set DHCP to
dhcp4: false. - Specify the static IP address. Under
addresses:you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface. - Specify the default gateway under
routes:. - Under
nameservers, set the IP addresses of the nameservers.
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: false
addresses:
- 192.168.121.221/24
routes:
- to: default
via: 192.168.121.1
nameservers:
addresses:
- 8.8.8.8
- 1.1.1.1When editing YAML files, make sure you follow the YAML indentation rules. If the syntax is not correct, the changes will not be applied.
If you are connected over SSH, test the configuration before applying it permanently:
sudo netplan tryNetplan will apply the configuration temporarily and ask you to confirm it. If the connection breaks and you do not confirm the change, Netplan rolls back to the previous configuration.
Once done, save the file and apply the changes:
sudo netplan applyVerify the changes by typing:
ip addr show dev ens32: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff
inet 192.168.121.221/24 brd 192.168.121.255 scope global ens3
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:feb0:f500/64 scope link
valid_lft forever preferred_lft foreverYou have assigned a static IP to your Ubuntu server.
Configuring a Static IP Address on Ubuntu Desktop
Setting up a static IP address on Ubuntu Desktop computers requires no technical knowledge.
In the Activities screen, search for “settings” and click on the icon. This will open the GNOME settings window. Depending on the interface you want to modify, click either on the Network or Wi-Fi tab. To open the interface settings, click on the cog icon next to the interface name.
In the “IPv4” tab, select “Manual” and enter your static IP address, netmask, gateway, and DNS servers. Once done, click on the “Apply” button.

To verify the changes, open your terminal either by using the Ctrl+Alt+T keyboard shortcut or by clicking on the terminal icon, and run:
ip addrThe output will show the interface IP address:
...
2: wlp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 50:5b:c2:d8:59:7d brd ff:ff:ff:ff:ff:ff
inet 192.168.121.130/24 brd 192.168.121.255 scope global noprefixroute wlp1s0
valid_lft forever preferred_lft forever
inet6 fe80::45e3:7bc:a029:664/64 scope link noprefixroute Troubleshooting
Netplan reports a YAML error
Check the indentation in the YAML file. YAML uses spaces, not tabs, and nested values must line up exactly.
The interface name is wrong
Run ip link again and replace ens3 in the example with the interface name on your system.
Netplan warns that gateway4 is deprecated
Replace gateway4 with a routes block that uses to: default and via: gateway_ip.
DNS works before the change but not after it
Check the nameservers block and make sure the DNS server addresses are indented under the correct interface.
The setting reverts on a cloud instance
Some cloud images use cloud-init to generate Netplan files. If you manage networking manually, create /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following content:
network: {config: disabled}Reboot the instance or regenerate the Netplan configuration after making this change.
Conclusion
You can configure a static IP address on Ubuntu by editing the Netplan file on servers or by using GNOME Settings on desktop systems. When working over SSH, use sudo netplan try first so the system can roll back if the new network configuration is not reachable.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page