How To

Configure Netplan on Ubuntu: DHCP, Static IP, Wi-Fi, and Bridges

Since Ubuntu 17.10, networking is configured with Netplan rather than the older /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 guide shows how to configure Netplan on Ubuntu for DHCP, a static IP address, Wi-Fi, and a network bridge, and how to apply changes safely without locking yourself out of a remote server.

Configure Netplan on Ubuntu: Files, Renderers, and Interface Names

Netplan reads YAML files from /etc/netplan/. It supports two renderers — the back end that actually manages the network:

  • systemd-networkd – the default on Ubuntu Server. It runs without a graphical environment and suits headless machines
  • NetworkManager – the default on Ubuntu Desktop. It handles Wi-Fi, VPN connections, and integrates with the GNOME settings panel

Files are read in alphanumeric order, and later files override earlier ones. A file named 99-custom.yaml takes precedence over 50-cloud-init.yaml. Create your config file:

bashsudo nano /etc/netplan/99-custom.yaml

Set strict permissions before applying. Netplan warns and may refuse to process files that are too open — and YAML files can contain Wi-Fi passwords:

bashsudo chmod 600 /etc/netplan/*.yaml

Find the correct interface names with ip link. YAML requires spaces for indentation — never tabs. A single misaligned line is the most common reason a configuration fails to apply.

Set Up DHCP, Static IP, Wi-Fi, and Network Bridges

DHCP for IPv4 and IPv6:

yamlnetwork:  version: 2  renderer: networkd  ethernets:    ens3:      dhcp4: true      dhcp6: true

Static IP address. Addresses use CIDR notation — /24 is equivalent to the 255.255.255.0 netmask. The routes: block replaces the deprecated gateway4 key. Use to: default for the default route:

yamlnetwork:  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.1

Wi-Fi. Desktop systems use the NetworkManager renderer. The password is stored in plain text inside the YAML file — keep permissions at chmod 600 and never commit Netplan files to version control:

yamlnetwork:  version: 2  renderer: NetworkManager  wifis:    wlp2s0:      dhcp4: true      access-points:        "MyNetwork":          password: "your-wifi-password"

Network bridge. A bridge joins physical interfaces into one logical network, which is needed when VMs or containers require direct access to the physical network. The physical interface gets dhcp4: false because the bridge owns the IP address — enabling DHCP on both would create duplicate addresses on the same network segment:

yamlnetwork:  version: 2  renderer: networkd  ethernets:    ens3:      dhcp4: false  bridges:    br0:      interfaces:        - ens3      dhcp4: true

Apply Netplan Changes Safely and Troubleshoot Common Issues

Check for syntax errors before touching the live network. The generate command builds the back-end configuration files and reports any YAML problems without applying anything to the active network:

bashsudo netplan generate

When working over SSH, use netplan try instead of netplan apply. netplan try applies the configuration temporarily and rolls back automatically if you do not confirm it within the timeout. A broken config cannot permanently lock you out:

bashsudo netplan try

Confirm the prompt if the connection holds and the configuration is correct. You do not need to run netplan apply afterward.

To apply directly at a local console:

bashsudo netplan apply

Review the current network state — addresses, routes, and DNS — with:

bashsudo netplan status

To check which settings survive the file-ordering override:

bashsudo netplan get

Common issues:

  • Changes do not take effect: run sudo netplan generate to check for YAML errors, confirm the interface name matches ip link, and run sudo netplan get to see whether a later file overrides your settings
  • gateway4 deprecation warning: replace the gateway4 line with a routes: block using to: default and via: <gateway_ip>
  • Static address reverts after reboot on a cloud instance: cloud-init regenerates Netplan files on each boot. Disable it by creating /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the content network: {config: disabled}, then reboot

Netplan centralizes Ubuntu networking in readable YAML files, systemd-networkd drives servers and NetworkManager drives desktops. When editing over SSH, always reach for sudo netplan try so a mistake rolls back on its own. Leave a comment below if you have any questions.

Cyber Defence

Recent Posts

Install Docker on Ubuntu 24.04: Repository, Compose, and Non-Root

Docker is an open-source containerization platform that packages an application and everything it depends on…

7 minutes ago

update-alternatives on Ubuntu: Manage Default Program Links

When two or more installed programs provide the same command name, the system needs a…

6 hours ago

Install Docker on Ubuntu 26.04: Official Repository Setup Guide

Install Docker on Ubuntu 26.04: Official Repository Setup GuideDocker is an open-source container platform that…

2 days ago

Install Asterisk on Ubuntu 18.04: Source Build and Secure Config

Asterisk is the most widely deployed open-source PBX (Private Branch Exchange) platform in the world. It…

3 days ago

Install Ghost on Ubuntu 18.04: Node.js, MySQL, and Nginx SSL

Ghost is an open-source publishing platform built on Node.js. It is designed for bloggers, journalists, and…

3 days ago

Install Mattermost on Ubuntu 18.04: Nginx SSL Reverse Proxy Setup

Mattermost is an open-source, self-hosted team messaging platform and a direct alternative to Slack. It is…

3 days ago