How to Set a Static IP Address on Ubuntu Server and Desktop
Learn how to set a static ip address on ubuntu 24.04 and 22.04 with Netplan YAML configuration, NetworkManager GUI, and DNS routing setup.

6 min read
Learn how to set a static ip address on ubuntu 24.04 and 22.04 with Netplan YAML configuration, NetworkManager GUI, and DNS routing setup.
- Prerequisites and Supported Releases
- Step 1: Identifying Active Network Interface Names
- Step 2: Locating Existing Netplan Configuration Files
When an Ubuntu computer connects to a local network, a Dynamic Host Configuration Protocol (DHCP) server usually assigns it a temporary dynamic IP address.
While DHCP is ideal for laptops and workstations, production servers, database nodes, hypervisors, and network appliances require unchanging static IP addresses.
A predictable IP address ensures that DNS records, SSH bookmarks, firewall rules, and API endpoints remain permanently reachable across reboots.
Ubuntu utilizes Netplan as its default network configuration abstraction utility, parsing YAML files to configure backend renderers like systemd-networkd or NetworkManager.
In this guide, we demonstrate how to set a static ip address on ubuntu both on headless servers via Netplan and on Desktop installations via graphical controls.
Complete administrator guide on configuring a persistent static IP address on Ubuntu 24.04 LTS (Noble Numbat) and 22.04 LTS. Covers identifying active network interface names, authoring YAML Netplan configuration files for systemd-networkd, applying settings safely with netplan try, and configuring static IPs on Ubuntu Desktop via NetworkManager GUI.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A server or desktop computer running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- A non-root user account with
sudoadministrative privileges. - Network parameters ready: target Static IP, Subnet Mask (CIDR notation), Gateway IP, and DNS Nameservers.
- Console or physical terminal access in case network connectivity drops during reconfiguration.
Step 1: Identifying Active Network Interface Names
Before configuring a static address, identify the logical name of your physical or virtual network interface.
Modern Linux kernels assign predictable interface names (such as eth0, ens3, ens33, or enp3s0) based on hardware bus topology:
Run the ip link or ip addr command to list all network interfaces:
# List active network interfaces:
ip -br link
# Example output:
# lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
# eth0 UP 52:54:00:12:34:56 <BROADCAST,MULTICAST,UP,LOWER_UP>
# Identify current dynamic IP and default gateway:
ip route show default
# Example output: default via 192.168.1.1 dev eth0 proto dhcp src 192.168.1.150 metric 100
Step 2: Locating Existing Netplan Configuration Files
Netplan stores network configuration files in YAML format inside /etc/netplan/.
File names typically end in .yaml (such as 50-cloud-init.yaml, 01-netcfg.yaml, or 00-installer-config.yaml):
Inspect the contents of /etc/netplan/ to identify your active configuration:
# List files in the Netplan directory:
ls -la /etc/netplan/
# Output: 00-installer-config.yaml
# Create a backup before making modifications:
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
Step 3: Configuring Static IP via Netplan YAML (Server)
Open your Netplan configuration file in a text editor like nano.
YAML syntax is strictly indentation-sensitive; use spaces (not tabs) with 2-space indentation levels.
Configure your network interface with a static IP address, subnet CIDR prefix (such as /24), default gateway route, and DNS nameservers:
Save the following configuration structure into /etc/netplan/00-installer-config.yaml:
# /etc/netplan/00-installer-config.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
dhcp6: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
search:
- localdomain
Netplan Routing Syntax Evolution: gateway4 vs routes
In older Ubuntu versions (like 18.04 and early 20.04), Netplan accepted gateway4: 192.168.1.1.
Canonical has fully deprecated gateway4 in favor of the standardized routes list shown above.
Using gateway4 on Ubuntu 24.04 triggers deprecation warnings during validation.
Step 4: Testing and Applying Netplan Configuration Safely
Applying invalid YAML indentation or typographical errors over SSH can sever your remote connection permanently.
Netplan provides a safety mechanism called netplan try.
This command applies the new configuration temporarily and waits for user confirmation; if you do not press Enter within 120 seconds, Netplan automatically rolls back to the previous working configuration:
Execute the safe test and apply your changes:
# Test configuration with automatic 120-second rollback safety:
sudo netplan try
# Output:
# Do you want to keep these settings?
# Press ENTER before the timeout to accept the new configuration
# Changes will revert in 120 seconds
# Press Enter to confirm.
# Alternatively, apply settings directly:
sudo netplan apply
Step 5: Verifying Network Connectivity and DNS Resolution
Confirm that the network interface adopted the new static IP address and that gateway routing and DNS resolution function correctly:
Run diagnostic commands to verify your network state:
# Verify IP address on eth0:
ip addr show dev eth0
# Output confirms: inet 192.168.1.50/24 brd 192.168.1.255 scope global eth0
# Verify default gateway routing:
ip route
# Output confirms: default via 192.168.1.1 dev eth0 proto static
# Test DNS resolution and external internet reachability:
ping -c 3 1.1.1.1
ping -c 3 ubuntu.com
Step 6: Setting Static IP on Ubuntu Desktop via NetworkManager GUI
If you run Ubuntu Desktop, managing network configuration graphically through NetworkManager is faster and avoids editing system configuration files manually:
Follow these graphical steps to assign a static IP address:
| Step Number | Action in Ubuntu Desktop GUI | Details to Enter |
|---|---|---|
| Step 1 | Open Settings | Navigate to Network (for Ethernet) or Wi-Fi |
| Step 2 | Click the Gear Icon | Opens properties for your active connection profile |
| Step 3 | Select the IPv4 Tab | Change IPv4 Method from Automatic (DHCP) to Manual |
| Step 4 | Enter Addresses | Address: 192.168.1.50, Netmask: 255.255.255.0, Gateway: 192.168.1.1 |
| Step 5 | Configure DNS | Disable Automatic DNS toggle, enter 1.1.1.1, 8.8.8.8 |
| Step 6 | Click Apply & Reconnect | Toggle the network switch off and on to initialize the static IP |
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
Invalid YAML: mapping values are not allowed in this context
Cause: Indentation error or tab characters used instead of spaces in Netplan YAML file.
Resolution: Replace all tab characters with two spaces and verify indentation alignment.
sudo netplan generate
WARNING: gateway4 has been deprecated, use default routes instead
Cause: Using deprecated gateway4 directive in modern Netplan on Ubuntu 24.04.
Resolution: Replace gateway4: 192.168.1.1 with routes: [{to: default, via: 192.168.1.1}].
sudo netplan apply
Network unreachable after applying Netplan configuration
Cause: Incorrect gateway IP or invalid subnet mask prefix specified.
Resolution: Revert to the backup file created in Step 2: sudo cp /etc/netplan/00-installer-config.yaml.bak /etc/netplan/00-installer-config.yaml && sudo netplan apply.
sudo netplan apply
Security Best Practices and Hardening
Ensure your chosen static IP address does not fall inside the active DHCP dynamic lease pool range of your router to prevent duplicate IP collisions.
Protect Netplan configuration files with 600 root-only permissions to prevent unauthorized users from viewing network topology.
Always maintain secondary console access (e.g., IPMI, VNC console) when reconfiguring network interfaces on remote cloud hosts.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Configure Networking with Netplan on Ubuntu — Deep-dive into Netplan syntax, bonding, bridges, and VLAN configurations.
- How to Set Up a Firewall with UFW on Ubuntu 24.04 — Secure your newly assigned static IP address with UFW firewall rules.
- Initial Server Setup on Ubuntu 24.04 LTS — Base operating system hardening and administrative configuration.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/etc/network/interfaces has been replaced by Netplan in modern Ubuntu releases to provide a unified declarative YAML schema that configures both systemd-networkd (servers) and NetworkManager (desktops) consistently./24 corresponds to the standard subnet mask 255.255.255.0, allowing up to 254 usable host addresses on a class C network.dhcp4: true, remove the addresses, routes, and nameservers sections, and execute sudo netplan apply.netplan apply reconfigures the running backend network daemon (systemd-networkd) dynamically without rebooting the operating system.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides


Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!