Linux Labs

Networking / Stage 3 of 14

Persistent networking with Netplan

Not running Starting usually ~20 s
Leave the lesson

Step 4 of 9 · theory · 4 min

Every file in the directory is one configuration

/etc/netplan may hold several files, and Netplan merges them into one configuration — an old copy too.

Netplan reads every /etc/netplan/*.yaml file in name order and merges them. Lists add up: if two files set addresses for lab0, the interface gets the addresses from both. sudo netplan get prints the merged result:

text
$ sudo netplan get ethernets.lab0
renderer: networkd
addresses:
- "192.0.2.10/24"
- "192.0.3.10/24"
dhcp4: false

That is why a copy of an old file is kept outside /etc/netplan, for example in /root. A copy with another extension, 50-lab.yaml.bak, is not read by Netplan, while any *.yaml in the directory becomes part of the configuration.

Warning

On a server you reached over the network, a mistake in the configuration cuts off your access. There, sudo netplan try is used instead of apply: it applies the configuration and rolls it back unless you press Enter within 120 seconds.

Check yourself 1 question

/etc/netplan holds two files for lab0: 50-lab.yaml with 192.0.2.10/24 and 70-lab-old.yaml with 192.0.3.10/24. What will lab0 have after sudo netplan apply?

  • The last file does not cancel the previous one: the addresses from both go into one list. sudo netplan get ethernets.lab0 prints it.

  • There is no conflict: two addresses on one interface are allowed, and apply sets both silently.

  • The files do not replace each other: the addresses lists add up. sudo netplan get ethernets.lab0 shows the result.

Netplan merges every *.yaml in the directory, and the address lists add up. That is why a copy of the old configuration is kept outside /etc/netplan.

Key points

  • Netplan merges every /etc/netplan/*.yaml, and address lists from different files add up.
  • sudo netplan get prints the merged result.
  • Keep a copy of an old configuration outside /etc/netplan.
Ubuntu 24.04
Loading…