How to Configure Networking with Netplan on Ubuntu

Since Ubuntu 17.10, networking is configured with Netplan rather than the old /etc/network/interfaces file. You write a short YAML description of how each interface should behave, and Netplan translates it into configuration for the back end that actually manages the network. This keeps the configuration in one place and makes it easy to read, but the YAML syntax trips up people who are used to the older format.
This guide explains how Netplan works and how to configure DHCP, static addresses, DNS, Wi-Fi, and bridges, then how to apply the changes without locking yourself out of a remote server.
Quick Reference
| Task | Command |
|---|---|
| List Netplan files | ls /etc/netplan/ |
| Show interface names | ip link |
| Show the merged configuration | sudo netplan get |
| Check configuration for errors | sudo netplan generate |
| Apply changes with rollback | sudo netplan try |
| Apply changes directly | sudo netplan apply |
| Show current network state | sudo netplan status |
How Netplan Works
Administrators store Netplan YAML files in /etc/netplan. Netplan reads those files and generates configuration for one of two back ends, called renderers:
systemd-networkd- The usual renderer on Ubuntu Server. It runs without a graphical environment and suits headless machines.NetworkManager- The usual renderer on Ubuntu Desktop. It handles Wi-Fi, VPNs, and interface switching, and integrates with the GNOME settings panel.
When you run netplan apply, Netplan parses the YAML, writes back-end configuration, and tells the renderer to reload it. Syntax errors stop this process, but a valid configuration with the wrong address or route can still interrupt the connection.
List the files Netplan currently reads:
ls /etc/netplan/50-cloud-init.yamlThe exact name depends on how the system was installed. Common names include 00-installer-config.yaml, 01-netcfg.yaml, and 50-cloud-init.yaml. Files are read in alphanumeric order, and later files override earlier ones, so a 90-custom.yaml takes precedence over 50-cloud-init.yaml.
The examples below use /etc/netplan/99-custom.yaml, which loads after the common installer and cloud-init filenames. Create the file with a text editor, or edit an existing file instead if you already manage it directly:
sudo nano /etc/netplan/99-custom.yamlNetplan configuration files should be readable and writable only by root. After saving the file, set the required permissions before applying changes:
sudo chmod 600 /etc/netplan/*.yamlThe Structure of a Netplan File
Every Netplan file starts with a top-level network key. Under it, you can set the configuration version, choose a renderer, and list interfaces by type, such as ethernets, wifis, bridges, or vlans. Netplan defaults to version 2 and the networkd renderer when these keys are omitted, but keeping them explicit makes the file easier to understand:
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: trueVersion 2 is the only supported Netplan YAML format. The renderer chooses the back end, and the interface name (ens3 here) must match a real interface on the system. Find the interface names with the ip link
command:
ip linkYAML is sensitive to indentation, so use spaces, never tabs, and keep nested keys aligned. A single misaligned line is the most common reason a configuration does not apply.
Configuring DHCP
The example above already enables DHCP for IPv4 with dhcp4: true. To also enable DHCP for IPv6, add dhcp6:
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: true
dhcp6: trueThis is the default configuration on most fresh installs, where the router assigns the address automatically.
Configuring a Static IP Address
To assign a fixed address, disable DHCP and set the address, gateway, and nameservers manually:
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 1.1.1.1The address uses CIDR notation, so /24 is the equivalent of the 255.255.255.0 netmask. The routes block replaces the deprecated gateway4 key that older guides still use. You can assign more than one address to an interface by adding extra lines under addresses. For a focused walkthrough of static addressing on both Server and Desktop, see the dedicated guide on setting a static IP address on Ubuntu
.
Configuring Wi-Fi
On a desktop or laptop, Netplan can connect to a wireless network through the wifis section. Ubuntu Desktop usually uses the NetworkManager renderer:
network:
version: 2
renderer: NetworkManager
wifis:
wlp2s0:
dhcp4: true
access-points:
"MyNetwork":
password: "your-wifi-password"Replace wlp2s0 with your wireless interface name, MyNetwork with the network SSID, and the password with your own.
600, and never commit Netplan files containing credentials to version control.Creating a Network Bridge
A bridge joins several interfaces into one logical network, which is useful when you run virtual machines or containers that need direct access to the physical network. The example below creates a bridge named br0 that takes its address from DHCP and includes the physical interface ens3:
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: false
bridges:
br0:
interfaces:
- ens3
dhcp4: trueNotice that the physical interface has DHCP disabled, because the bridge now owns the address rather than the interface itself.
Applying the Configuration
After editing a file, you can check it for syntax errors before doing anything to the live network. The generate command builds the back-end configuration and reports any problems:
sudo netplan generateWhen you connect over SSH, never run netplan apply blindly, because a broken configuration can drop your connection. Use netplan try instead, which applies the configuration temporarily and rolls back automatically if you do not confirm it within the timeout:
sudo netplan tryIf the connection holds and the configuration is correct, confirm it at the prompt. Confirmation makes the tested configuration permanent, so you do not need to run netplan apply afterward.
When you are working from a local console and want to apply the configuration directly, run:
sudo netplan applyOn recent Ubuntu releases you can review the resulting state, including addresses, routes, and DNS, with the status command:
sudo netplan statusVerify the assigned address directly with ip addr
:
ip addr show dev ens3Troubleshooting
Changes do not take effect after netplan apply
Run sudo netplan generate and fix any YAML error it reports. If the file is valid, confirm that the interface name matches ip link, then run sudo netplan get to check whether a later file overrides your settings.
The configuration warns that gateway4 is deprecated
Replace the gateway4 line with a routes block that uses to: default and via: gateway_ip.
Wi-Fi does not connect
Make sure the renderer is set to NetworkManager, the SSID is quoted exactly, and the interface name matches the output of ip link.
The static address reverts after a reboot on a cloud instance
Cloud images often regenerate Netplan files with cloud-init. Disable that by creating /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the content network: {config: disabled}, then reboot.
Conclusion
Netplan centralizes Ubuntu networking in a few readable YAML files, with systemd-networkd driving servers and NetworkManager driving desktops. When you edit these files over SSH, reach for sudo netplan try first so a mistake rolls back on its own instead of cutting off your access.
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