3
November
2023
15:25

netplan as a replacement for /etc/network/interfaces

3 November 2023 15:25

How to configure a network using the interfaces file outdated.

Home

The netplan utility is used for network configuration. It converts a YAML (Structured Text File) format configuration file into settings for the SystemD network service, the systemd-networkd service.
Netplan was introduced in Ubuntu 18.04 "Bionic Beaver" in 2017, then it gradually came into use: it is present in OS 20.04 "Focal Fossa". Ubuntu 22.04 "Jammy Jallyfish" and Linux Mint 21.2 "Victoria" have netplan enabled by default. Moreover, the /etc/network/interfaces file is missing if you did not upgrade the version using sudo do-release-upgrade(from the package update-manager-core) or sudo mintupgrade(from the package of the same name).

КонThe Netplan configuration may not always be used on desktop operating systems, but is always used on server versions of the Ubuntu OS starting from 22.04. The fact is that disabling netplan requires intervention in the kernel parameters (there is information on the Internet about ways to disable netplan).

On desktop PCs, by default, netplan delegates network management to NetworkManager (see "Default natplan configuration" below).

For netplan to work, you need OS version 18.04 and higher. In versions 18.04 and 20.04, to work with a configuration different from the standard one, you need to force the systemd-networkd network service to start. (In 22.04 it starts after the default installation).

sudo systemctl start systemd-networkd
sudo systemctl enable systemd-networkd

Running the systemd-networkd service for netplan to work is required to work with configurations for dynamic distribution of DHCP and static IP addresses, and other options described in *config.yaml.

1. Netplan default configuration

When using systemd-networkd, the /etc/network/interfaces configuration is no longer accepted and this file may not be present in the system.

The configuration in the form of a yaml file is located in the folder /etc/netplan.

On a clean installation of a system, such as Linux Green, netplan is configured to transfer control of settings graphical component NetworkManager(configured using an applet in the system tray on the taskbar).

Netplan default configuration:

File /etc/netplan/1-network-manager-all.yaml:

#Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager

Applying the configuration using the command:

sudo netplan apply

2. Netplan configuration for DHCP

To configure the configuration using netplan files rather than the NetworkManager GUI, you need to in the directory /etc/netplan/ in the YAML file the line "renderer" from "NetworkManager" to "networked". In this case, the "NetworkManager" applet in the system tray loses the ability to manage the network and shows the "broken connection" icon, regardless of whether there is a network or not.

If the network uses dynamic IP addresses, the DHCP service is configured on the router, and the following netplan configuration is used on the client:

File /etc/netplan/00-installer-config.yamlfor DHCP

network:
renderer: networkd
ethernets:
    enp1s10:
      dhcp4: true
version: 2

where the name of the network card is enp1s10 in my case (external network card), and for built-in ones it can be enp1s0 and enp2s0.
If the router can also distribute IP addresses using the IPv6 protocol, below dhcp4: true пишем dhcp6: true with the same indentation (tab characters or spaces are important)!

Application configuration:

sudo netplan apply

3. Netplan configuration for static IP address

Indentation in a file matters a lot. Below is an example of a correct netplan configuration file for a static IP address.

File /etc/netplan/000-installer-config.yaml for static IP address:

network:
renderer: networkd
ethernets:
    enp1s10:
      dhcp4: false
      dhcp6: false
      optional: false
      addresses: [192.168.1.2/24]
      nameservers:
        addresses: [192.168.1.1,8.8.8.8]
      routes:
        - to: default
          via: 192.168.1.1
          metric: 100
version: 2

Where:

  • optional = false the device is not needed to boot

  • optional = true the device is required to boot.
    If a device is marked as optional, the networkd service will not wait for it.
    The default value is false.

  • addresses - may include multiple IP addresses, for example, [192.168.14.2/24, "2001:1::2/64"]

The gateway4 and gateway6 configuration parameters are deprecated; instead, "Default routes" of the following form are used:

      routes:
        - to: default
          via: 192.168.1.1
          metric: 100

Don't forget to apply the configuration:

sudo netplan apply

To check the network configuration to decide whether it is correct, you need to use try instead of apply. The user is given 120 seconds to check the network operation. If you press Ctrl+C or the timeout expires, the configuration will be cancelled. To apply the configuration, press Enter.

4. Installing netplan on Debian

(Addendum dated November 4, 2023):

su -
apt update
apt install netplan

5. How can I programmatically find out which network management mechanism is being used?

You can determine the use of netplan with the commands:

systemctl status systemd-networkd
(Checking the status of the systemd-networkd service).

cat /run/network/ifstate

(For netplan it will be lo=lo).

Setting up a network using NetworkManager

If the file /etc/netplan/*.yaml points to the graphical utility NetworkManager, then the current network settings need to look at the configuration file:
/etc/NetworkManager/NetworkManager.conf

If the device is not managed by NetworkManager:

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false

[device]
match-device=interface-name:*

To manage a device using NetworkManager (from the status bar next to the taskbar):

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=true

[device]
match-device=interface-name:*

Don't forget to restart the NetworkManager service:

sudo systemctl restart NetworkManager

For a managed device (managed = true) additional menu items appear "Disable", "ifupdown" and the settings section becomes available "Connection settings":

  1. in the system tray, click on the Network Manager icon and select the name of the network card
  2. bottom menu item "Connection settings..." is for changing settings (MTU, Wake-on-Lan, link negotiation, speed, proxy, IPv4 parameters - DHCP or manual, additional static addresses, DNS servers (for static IP address), additional DNS servers (for dynamic IP address), search domains, IPv6 parameters).

Addition: from 03/01/2025: you also need to “raise” the connection using the NetworkManager applet or command line utility nmcli

nmcli connection show
nmcli connection up "Проводное подключение 1"

Update dated July 30, 2024. After setting up netplan, you should rename the /etc/network/interfaces file, restart network services and check the IP address (it should change to the one specified in the connection settings in Network Manager or in the YAML configuration file /etc/netplan/*.yaml).

sudo mv /etc/network/interfaces /etc/network/interfaces.old
sudo systemctl restart networking
systemctl status systemd-networkd
ip addr

Conclusion

This article, like many others, contains examples of configuring netplan for both DHCP and simple static IP. The interfaces file is out of date. Use netplan. Netplan uses YAML for configuration. The /etc/network/interfaces file should be removed to avoid confusion.


Sources:
ubuntu-bionic-netplan
man netplan
*netplan.io



Related publications