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.
Netplan reads YAML files from /etc/netplan/. It supports two renderers — the back end that actually manages the network:
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.
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
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:
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 settingsgateway4 deprecation warning: replace the gateway4 line with a routes: block using to: default and via: <gateway_ip>/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the content network: {config: disabled}, then rebootNetplan 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.