Marcio Cunha

How to Configure a Static IP Address on Ubuntu Server Using Netplan

Learn the step-by-step process to configure a static IP address on Ubuntu Server using Netplan, ensuring your server always maintains the same local network location without surprises.

Marcio Cunha12 min
Also available in:EspañolPortuguês
Summary
  • Static IP addresses prevent servers from changing local network numbers and breaking pending connections
  • Netplan uses YAML configuration files to centralize and simplify network management in Ubuntu
  • Correctly identifying the network interface name prevents critical connectivity errors during application
  • YAML indentation errors are the most common cause of failures when applying network rules
  • Validating the configuration with the test command prevents accidental remote administrator lockout

Why your server needs a fixed IP address

When you connect a computer or smartphone to a Wi-Fi network, your home or office router automatically distributes a temporary identification number called a dynamic IP address. This process is managed by a protocol called DHCP, which acts like a hotel receptionist handing out keys as rooms become vacant. For personal computers, this is excellent because it prevents conflicts and simplifies connection. However, when turning a machine into an Ubuntu server, this dynamic behavior becomes a critical operational problem.

In practice, this means that if your server reboots tomorrow, the router might assign it a completely new number. Any service hosted on that machine, such as a database, a local website, or a shared file system, will become inaccessible because the address changed without prior warning. Configuring a static, or fixed, IP address ensures the machine always keeps the same digital coordinate on the network. This consistency is the foundation upon which we build any stable infrastructure, allowing other devices to reliably find the server at any time.

Understanding the Netplan network tool in modern Ubuntu

Historically, configuring networks in Linux was a decentralized and often confusing task, requiring changes to complex files like /etc/network/interfaces. In recent versions of Ubuntu Server, Canonical introduced Netplan, which is not a network service itself, but rather a unified control panel. It works like an intelligent translator: you write your network preferences in a human-readable configuration file and Netplan converts it into the format that the low-level manager — usually networkd — can execute.

In practice, Netplan uses the YAML format to structure data. YAML is a markup language focused on readability, where whitespace indentation defines information hierarchy, much like an organizational chart. This approach drastically simplifies systems administration by centralizing definitions of addresses, subnet masks, gateways, and DNS servers into a single clean, organized place. Understanding this logic is essential to avoid the most common error in the ecosystem: syntax failures caused by incorrect tabulations.

Discovering the exact name of your network interface

Before modifying any configuration file, we need to discover the technical name of the physical or virtual network interface we are going to modify. In the past, network cards received simple standardized names like eth0 or wlan0. Nowadays, Ubuntu uses a predictable naming scheme based on hardware bus topology, resulting in slightly longer names such as enp3s0 or ens18. Discovering this correct information is the first mandatory step to avoid applying rules in the wrong place.

To list all available network interfaces on your Ubuntu server, open the terminal and run the command ip a or ip link show. In practice, this will display a detailed list of all adapters connected to the motherboard. Look for the line starting with a number followed by the adapter name and check which one is active, usually indicated by the UP state. Note this name carefully, as it will be the anchor point for our Netplan configuration file.

Locating and interpreting the Netplan configuration file

Netplan configuration files are stored inside the /etc/netplan/ directory. If you navigate to this folder using the command cd /etc/netplan and list its contents with ls, you will find a file with a .yaml extension — the exact name may vary, such as 00-installer-config.yaml or 50-cloud-init.yaml depending on how your server was installed. It is inside this file that we will make the necessary modifications to fix the IP address.

In practice, opening this file with a text editor like sudo nano /etc/netplan/00-installer-config.yaml will reveal your current network structure. By default, you will see that the dhcp4 parameter is set to true, indicating that the server obtains its address automatically. Our technical goal will be to disable this automatic behavior and replace the dynamic guidelines with consistent manual parameters, specifying the desired IP address, default gateway, and DNS servers.

Writing static IP rules in YAML format

Now that you understand the structure, it is time to modify the Netplan configuration file with careful attention to detail. YAML file indentation is extremely strict: always use whitespace to align lines and never use the Tab key, as this corrupts the syntax and makes Netplan reject changes. Let's structure the code so that the operating system knows exactly which card to configure and which network parameters to adopt.

Below is a functional example of a YAML file configured for a typical local network. Replace enp3s0 with the actual name of your card, 192.168.1.100/24 with the desired IP and mask, 192.168.1.1 with your router's IP (gateway), and Google or Cloudflare addresses as DNS servers.

network:  version: 2  renderer: networkd  ethernets:    enp3s0:      dhcp4: no      addresses:        - 192.168.1.100/24      routes:        - to: default          via: 192.168.1.1      nameservers:        addresses:          - 8.8.8.8          - 1.1.1.1

In practice, each line of this block has a clear operational meaning. The addresses field defines the server IP followed by a slash and the number 24, which represents the subnet mask corresponding to 255.255.255.0. The routes field points to the default gateway, which is the exit route to the internet. Finally, nameservers translate website names into IP addresses understandable by machines.

Applying and testing the new network configuration safely

After saving the file in the text editor, the next step is to apply the changes to the operating system. However, modifying networks remotely via SSH requires extra caution: if there is a syntax error or the chosen IP is wrong, you will lose connection to the server instantly. To mitigate this risk, Netplan offers an intelligent application command that includes an integrated safety mechanism against permanent lockouts.

In practice, run the command sudo netplan try instead of applying directly. This command applies settings temporarily and waits for your confirmation by pressing the Enter key. If the network drops or connectivity fails, Netplan automatically reverts the changes after a few seconds, restoring previous access. If everything goes well and the connection remains active, confirm the change. If you prefer to apply directly without testing, use the command sudo netplan apply.

Validating connectivity and troubleshooting common failures

With the static IP address successfully applied, the configuration cycle requires rigorous validation to ensure the server not only has the correct number but can also talk to the rest of the world. The first practical procedure is to run the ip a command again to confirm whether the network interface displays the new configured IP address without apparent conflicts with other local network devices.

Next, test connectivity with the external network by sending test packets to the gateway and the internet using the command ping -c 4 192.168.1.1 and ping -c 4 8.8.8.8. If the ping responds correctly, it means both the local layer and outgoing routing are working. If failures occur, check if the subnet mask is correct and if the network cable is firmly connected, as minor typos in the YAML file are the root cause of almost all network problems on Ubuntu Server.

Final considerations on stability and network management

Maintaining predictable IT infrastructure starts at the most basic operating system layer, and using static IP addresses on Ubuntu Server is an indispensable pillar for such stability. By mastering Netplan, you eliminate reliance on volatile dynamic allocations and ensure critical services remain consistently accessible at the same addresses, facilitating firewall rules, storage mappings, and secure remote connections.

The consistent practice of documenting assigned IPs for each server and avoiding conflicts within your router's DHCP range saves hours of future troubleshooting. With the concepts and examples covered in this article, you now have complete technical autonomy to configure, validate, and maintain corporate or home networks on Ubuntu with total safety and operational precision.