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

In most network configurations, the IP address is assigned dynamically by the router’s 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, nmcli from the command line, and GNOME Settings on Ubuntu Desktop. The 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 |
| Show the default gateway | ip route |
| List Netplan files | ls /etc/netplan/ |
| Test Netplan changes safely | sudo netplan try |
| Apply Netplan changes | sudo netplan apply |
| List NetworkManager connections | nmcli connection show |
| Show one interface | ip addr show dev ens3 |
Reserving an IP Address on the Router
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 ifupdown with the /etc/network/interfaces file. The legacy ifconfig
command is part of the net-tools package, which is not installed by default on current Ubuntu releases; the ip command replaces it.
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. For a broader look at Netplan, including DHCP, Wi-Fi, and bridges, see our guide on configuring networking with Netplan on Ubuntu .
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:ffIf you only need to see which address the system has right now, see our guide on finding your IP address in Linux .
Netplan 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.
Before editing the file, check the current IPv4 addresses and default gateway:
ip -4 addr show
ip route show defaultThe address after inet shows the current subnet and prefix length, while the default via line shows the gateway. Replace ens3, 192.168.121.221/24, and 192.168.121.1 in the examples below with values from your network. Choose an unused address outside the router’s DHCP pool, or reserve the address for this machine in the router settings, to avoid conflicts.
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. On newer installations, the renderer line may be missing, in which case Netplan uses networkd by default.
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.
Save the file and restrict its permissions so only root can read it. Current Netplan versions print a warning when a configuration file is readable by other users:
sudo chmod 600 /etc/netplan/01-netcfg.yamlIf 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 within 120 seconds, Netplan rolls back to the previous configuration.
When you confirm the configuration, netplan try makes it permanent, so you do not need to run netplan apply. If you are working on the machine directly and did not use netplan try, apply the changes with:
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 foreverThe inet line shows the new address with the /24 prefix. With this Netplan configuration, valid_lft forever means the address has no expiration time.
To confirm that traffic leaves through the right gateway, check the routing table:
ip routedefault via 192.168.121.1 dev ens3 proto static
192.168.121.0/24 dev ens3 proto kernel scope link src 192.168.121.221The default via line should point to the gateway you set in the routes block. You have assigned a static IP to your Ubuntu server.
Configuring a Static IP Address with nmcli
Ubuntu Desktop manages the network through NetworkManager, so you can also set a static IP address from the command line with nmcli
. This is useful when you are working in a terminal or connected to a desktop machine over SSH. Ubuntu Server does not include NetworkManager by default, so use Netplan on servers.
First, list the connection profiles to find the name of the one you want to change:
nmcli connection showNAME UUID TYPE DEVICE
Wired connection 1 8d6c2f1e-4a5b-3c7d-9e0f-1a2b3c4d5e6f ethernet enp1s0
lo 0f5c6e2a-1b3d-4e8f-a7c9-2d4e6f8a0b1c loopback loIn this example, the profile is named Wired connection 1. Set the address, gateway, and DNS servers, and switch the method from DHCP to manual:
sudo nmcli connection modify "Wired connection 1" \
ipv4.method manual \
ipv4.addresses 192.168.121.130/24 \
ipv4.gateway 192.168.121.1 \
ipv4.dns "8.8.8.8 1.1.1.1"The new settings are saved to the profile but do not take effect until you reactivate the connection:
sudo nmcli connection up "Wired connection 1"If you are connected over SSH, double-check the values before running this command. A wrong address or gateway will drop the session.
To switch the profile back to DHCP and remove the manual IPv4 settings, run:
sudo nmcli connection modify "Wired connection 1" \
ipv4.method auto \
ipv4.addresses "" \
ipv4.gateway "" \
ipv4.dns ""
sudo nmcli connection up "Wired connection 1"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. To use your own DNS servers, turn off the “Automatic” switch next to DNS. Once done, click on the “Apply” button.

GNOME Settings and nmcli edit the same NetworkManager profile. On Ubuntu 23.10 and later, NetworkManager stores that profile as a Netplan file named /etc/netplan/90-NM-<uuid>.yaml, so you may see a new file in /etc/netplan after you change the settings.
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 noprefixrouteChanging the IP Address Temporarily
Sometimes you need a different address only for a quick test, for example to reach a device that ships with a fixed default IP. The ip command can add an address to an interface on the fly:
sudo ip addr add 192.168.121.222/24 dev ens3The interface now has both the old and the new address. To remove the temporary address, run:
sudo ip addr del 192.168.121.222/24 dev ens3Changes made with ip are not saved anywhere. They are lost after a reboot or when the network service reapplies its configuration. For a permanent address, use one of the methods above.
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.
Netplan warns that permissions are too open
The warning looks like Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others. Run sudo chmod 600 on the file to make it readable only by root.
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. Run resolvectl status to see which DNS servers the interface is using.
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, with nmcli from the terminal, 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 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page