ubuntu, updated

Netplan and the current config

How Ubuntu configures the network, where the files are, and how to see the current IP, gateway and interfaces.

How it works

Ubuntu Server describes the network in Netplan YAML files in /etc/netplan/. Netplan itself doesn’t run anything. It translates your YAML into config for the real network service (the renderer):

flowchart LR
    Y["/etc/netplan/*.yaml"] -->|netplan apply| N["systemd-networkd
(server)"] Y -.->|or| NM["NetworkManager
(desktop)"] N --> I["interfaces
IP, routes, DNS"]

So: change the YAML, then netplan apply. Don’t edit /etc/network/interfaces, that is the old system and is ignored.

See the current config

WhatCommand
Interfaces, IPs, routes, DNS in one viewsudo netplan status (24.04+)
IP addresses (short)ip -br a
IP addresses (full)ip a
Default gateway and routesip r
Link state (up/down) and MACip -br link
DNS servers in useresolvectl status
What Netplan will applysudo netplan get
The files themselvesls /etc/netplan/ and sudo cat /etc/netplan/*.yaml

ip replaces the old ifconfig and route, which are not installed by default.

The files

Files are read in alphabetical order; later files override earlier ones.

Typical fileCreated by
50-cloud-init.yamlcloud-init: cloud images, VM templates, and the 24.04 installer
00-installer-config.yamlThe Ubuntu Server 22.04 installer

A minimal file with DHCP looks like this:

network:
  version: 2
  ethernets:
    ens18:
      dhcp4: true

Interface names like ens18, eth0 or enp3s0 come from ip -br link.

cloud-init overwrites my changes

If your file says it was generated by cloud-init, your edits may be replaced on the next boot. Tell cloud-init to leave the network alone:

echo "network: {config: disabled}" | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

Then edit the Netplan file (or create your own, e.g. 60-static.yaml).

Netplan commands

CommandDoes
sudo netplan generateCheck the YAML and generate backend config, without applying
sudo netplan tryApply, and roll back after 120 s unless you press Enter. Use this over SSH!
sudo netplan applyApply for real
sudo netplan getShow the merged config
sudo netplan set ethernets.ens18.dhcp4=falseChange one value from the command line

Next: Change IP, gateway and routes.

§ home
~/knubertus/home/
1,1 Top