Linux Labs

Networking / Stage 3 of 14

Persistent networking with Netplan

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 9 · theory · 5 min

Where the network configuration lives

After a restart the address comes from a Netplan file — a short description of the interfaces in YAML.

Netplan keeps Ubuntu's network configuration in the files /etc/netplan/*.yaml. It configures the interfaces from them at boot and on the netplan apply command. The file can only be read with sudo: it has -rw------- permissions and belongs to root, since network settings may contain passwords.

Here is /etc/netplan/50-lab.yaml from the first exercise, as sudo cat prints it:

yaml
network:
  version: 2
  ethernets:
    lab0:
      renderer: networkd
      dhcp4: false
      addresses:
        - 192.0.3.10/24

The file is written in YAML: indentation with spaces sets the nesting, and a line starting with - is a list item.

Key What it sets
ethernets: → lab0: the settings of the lab0 interface
renderer: networkd who applies the configuration
dhcp4: false do not get an address automatically
addresses: a list of addresses with prefixes

The renderer is the service that receives the ready configuration from Netplan and sets it on the interface. Here it is systemd-networkd.

Check yourself 1 question

After a restart lab0 must have 192.0.2.10/24. What do you change?

  • The renderer chooses who applies the configuration; the address itself is written under addresses.

  • The first exercise showed that an address set with ip lasts only until the next netplan apply.

  • DHCP hands out addresses automatically, but it will not pick the 192.0.2.10/24 you need. The interface's address is set by the addresses list.

After a restart the address comes from the addresses list of the Netplan file. That is what you fix, and then you apply the file.

Key points

  • Ubuntu's persistent network configuration is the files /etc/netplan/*.yaml, readable only with sudo.
  • Indentation sets the nesting in YAML, and the interface's addresses are the addresses list with prefixes.
  • The renderer sets the configuration on the interface; here it is the systemd-networkd service.
Ubuntu 24.04
Loading…