How to Configure Static IP with Netplan on Ubuntu

How to Configure Static IP with Netplan on Ubuntu

https://ift.tt/lHMiRUA

Still configuring Ubuntu networking the old way? Learn from our latest guide how to configure static IPs using Netplan on modern Ubuntu servers with clean YAML configs, validation tips, multi-interface setups, and troubleshooting examples.

Network configuration management of Ubuntu servers has significantly changed in the last few years. Have you ever found editing /etc/network/interfaces to be challenging or found yourself wondering why your old networking commands no longer worked once you upgraded to a newer release of Ubuntu? The answer can be found in Netplan, the current Ubuntu networking standard that has been the default since Ubuntu 17.10.

Netplan provides easier configuration of your network by using human-readable YAML files that can serve as a single source of truth about the network settings of your system. Regardless of whether you are configuring a cloud VPS, a bare-metal server, or a local development machine, the knowledge of how to configure a static IP using Netplan is one of the most required Linux networking skills you need to know in 2026.

This guide will take you step by step through the process, with real examples of configuration, expert descriptions, and troubleshooting hints used by professional system administrators and DevOps engineers.

What Is Netplan and Why Does Ubuntu Use It?

Netplan is a network configuration tool created by Canonical that manages network configuration files written in YAML to describe your desired network setup. Your configuration is defined in a declarative style rather than writing up low-level network scripts; your configuration is passed to an underlying network renderer, be it systemd-networkd or NetworkManager, which then manages the actual implementation.

Ubuntu uses Netplan as its default networking tool, beginning with Ubuntu 17.10 (Artful), to offer an experience of unified, consistent network configuration across desktop, server, and cloud environments. Before Netplan, Ubuntu had a server-friendly, desktop-friendly system of ifupdown and NetworkManager, respectively, which created inconsistency and complexity in their use in managing systems across available deployment environments. Netplan eradicates this fragmentation because it offers a single configuration layer, which is everywhere.

In Ubuntu 20.04, 22.04, 24.04, and 26.04 LTS, the most widely deployed versions of Ubuntu server in production today, Netplan with systemd-networkd as its backend is the typical way of configuring a static IP address on a server.

Understanding Netplan Configuration Files

All the Netplan configuration files are located in the /etc/netplan/ directory and are named with the file extension of .yaml. A default set of configuration files on a freshly installed Ubuntu server will typically consist of a single default configuration file, named something like 00-installer-config.yaml, 01-network-manager-all.yaml, or 01-netcfg.yaml, depending on how the system was provisioned.

The prefix in the name of the file defines the precedence sequence – those with lower numbers are treated first. This enables you to stack configurations across a number of files when required by more elaborate configurations.

To see the existing Netplan configuration files on your system, run:

ls /etc/netplan/

 

wp-image-34224

 

To display the contents of your existing configuration:

cat /etc/netplan/01-network-manager-all.yaml

 

wp-image-34225

 

Steps to Configure Static IPs Using Netplan

To configure a static IP, you edit the Netplan YAML file with your desired IP address, subnet, gateway, and nameservers, then run sudo netplan apply to activate the changes instantly.

The first step before making any changes to the current file is a very important one that many beginners overlook and is the main cause of accidental network outages on production servers.

Step 1: Identify Your Network Interface Name

The correct name of your network interface must be known before you write any Netplan configuration. Ubuntu uses non-legacy names (like ens33, eth0, enp0s3, or ens160) as the preferred names to replace the older generic names (ens33, eth0, enp0s3, or ens160).

The following command will be used to enumerate all the available network interfaces in your Ubuntu system:

ip link show

 

wp-image-34226

 

Or the more detailed one to view IP addresses and interface states:

ip addr show

 

wp-image-34227

 

Search the interface that now has a network connection or has the status UP. The name you are looking at here, say ens33, is the name that you will use in your Netplan YAML file. The most likely error in the process of configuring Ubuntu to use static IPs is the wrong interface name, so it is important to always verify before proceeding.

Step 2: Back Up the Existing Netplan Configuration

Whenever making any alteration to any network configuration file on a live server, always make a copy of the existing working configuration. One habit has rescued many system administrators who have been locked out of remote servers following a wrong configuration:

sudo cp /etc/netplan/01-network-manager-all.yaml etc/netplan/01-network-manager-all.yaml.bak

 

wp-image-34228

 

Should anything go amiss after implementing the new configuration, you can restore the backup and bring your network to its original state without having to physically access the machine.

Step 3: Configure the Static IP Configuration in Netplan YAML

The Netplan configuration file is now open, and a text editor should be used to open it. Beginners should use nano since it shows keyboard shortcuts at the bottom of the screen:

sudo nano /etc/netplan/01-network-manager-all.yaml

Replace the current content with the following static IP settings, with the values altered to suit your network setup:

network:

version: 2

renderer: NetworkManager

ethernets:

ens3:

dhcp4: false

addresses:

- 192.168.1.100/24

routes:

- to: default

via: 192.168.1.1

nameservers:

addresses:

- 8.8.8.8

- 1.1.1.1

 

wp-image-34230

 

The following is a description of each of the configuration fields in a way that you can see what it is you are adjusting:

  • version: 2 — This is the Netplan configuration schema version and must always be set to 2 for current Ubuntu releases.
  • renderer: NetworkManager— This tells Netplan to use systemd-NetworkManager as the backend, which is the correct choice for Ubuntu servers without a graphical desktop.
  • ethernets: — This section sets the configuration of Ethernet interfaces.
  • ens33: — The name of your particular network interface that was identified in Step 1.
  • dhcp4: false — Making this false will disable DHCP and allow you to manually assign a static IP address.
  • addresses: — This is where you are specifying your static IP address in CIDR notation. The /24 suffix means your subnet mask is 255.255.255.0.
  • routes: — The default route sends all outgoing traffic to your gateway IP (via: 192.168.1.1), which is normally your router IP address.
  • nameservers: — Here you configure your DNS servers. They use Google DNS (8.8.8.8) and Cloudflare DNS (1.1.1.1) as trusted public resolvers.

The indentation of YAML is of the utmost importance. There is a two-space indentation in netplan configuration files, and any tab characters or irregular spacing will result in a silent failure of the configuration or an error in parsing.

Step 4: Validate the Netplan Configuration

Netplan has a built-in check command that will verify your YAML file has no syntax errors before it actually makes any changes to any network settings:

sudo netplan generate

 

wp-image-34231

 

When no output is returned, then your configuration file has no syntax errors. In case of error messages, it is important to revise the line numbers in the error message and fix the indentation or value errors before proceeding.

Step 5: Apply the Static IP Configuration

After you have checked out your configuration, use the following command to apply it:

sudo netplan apply


wp-image-34232

 

This command will cause Netplan to push the new configuration to the systemd-networkd backend and execute the changes in real-time. On the majority of systems, it will take one to two seconds to reconfigure the network interface, and at that point, your server will start using the new static IP address immediately.

Step 6: Verify the Static IP Configuration

To ensure that the application of the static IP was successful, execute:

ip addr show ens33

 

wp-image-34233

 

Your static IP address should be displayed under the interface. To ensure that routing and DNS are functioning as desired, test connectivity to:

ping -c 4 google.com

 

wp-image-34234

 

A ping response is a successful ping response that will confirm that your default gateway, DNS servers, and your static IP are all correctly configured.

Step 7: Configure a Static IP for Multiple Interfaces

When your Ubuntu server has more than one network interface (such as one to the outside world and one to a private internal network), you can configure both of them in the same Netplan YAML file:

network:

version: 2

renderer: NetworkManager

ethernets:

ens33:

dhcp4: false

addresses:

- 192.168.1.100/24

routes:

- to: default

via: 192.168.1.1

nameservers:

addresses:

- 8.8.8.8

ens4:

dhcp4: false

addresses:

- 10.0.0.5/24

 

wp-image-34235

 

In this example, ens33 is the main front-end interface with a default gateway, and ens4 is a secondary back-end interface with no default gateway assigned, which is the appropriate configuration in the case of internal-only network communication.

Troubleshooting Common Netplan Static IP Issues

Even seasoned administrators have problems with the installation of networks. The following are the most frequent issues and how to solve them:

  • “netplan apply” has no effect: This normally indicates that the YAML file has a syntax error that has not been identified by netplan generate. To view verbose output that shows precisely where the failure is, run sudo netplan –debug apply.
  • Lost SSH connection after applying: When configuring a remote server, you might lose connection with the server after running netplan apply. To fix the configuration, you will require console access (through cloud provider dashboard or physical access) to do so.
  • DNS not resolving after setting static IP: When ping google.com fails but ping 8.8.8.8 works, it is a problem with your DNS settings. Ensure that the nameservers section has been properly indented and ensure that the addresses are legitimate.
  • Interface name not found: When Netplan informs you that the interface does not exist, re-check the interface name using ip link show and update your YAML file to include it.

Best Practices for Netplan Static IP Configuration on Ubuntu

These professional best practices will make certain that your Netplan settings are stable, readable, and maintainable throughout your entire infrastructure:

  • Never make any changes to a live server or, more specifically, one that you can access remotely via SSH.
  • Always check the netplan generated before applying it to avoid syntax errors before they can affect connectivity.
  • Add comments to your YAML file using the character # to record what each interface is used to do, which helps future administrators to understand the network design.
  • Always use CIDR notation for all IP addresses and subnet masks to prevent ambiguity and to ensure compatibility with the YAML parser in Netplan.

Conclusion

Configuring a static IP using Netplan is the modern, recommended approach for Ubuntu network configuration in 2026. To configure a static IP in Ubuntu using Netplan, edit the YAML configuration file in /etc/netplan/ (e.g., 01-netcfg.yaml), set dhcp4: false, and define addresses, gateway4, and nameservers. Apply changes using sudo netplan apply after verifying formatting.

By replacing the outdated ifupdown system with a clean YAML-based workflow, Netplan makes it straightforward to define, validate, and apply network settings on Ubuntu 20.04, 22.04, and 24.04 LTS servers with full confidence.

The process covered in this guide, identifying your interface, writing the YAML configuration, validating it, and applying it, gives you a repeatable, professional workflow that scales from a single VPS to hundreds of servers in an enterprise environment.

storage

via StarWind Blog https://ift.tt/67pcGjX

May 26, 2026 at 05:25PM
Karim Buzdar