Systemd/networkd: Difference between revisions

From NixOS Wiki
imported>Mweinelt
imported>Mweinelt
mNo edit summary
Line 5: Line 5:
* <code>systemd.network.links</code> reconfigures existing network devices
* <code>systemd.network.links</code> reconfigures existing network devices
** https://www.freedesktop.org/software/systemd/man/systemd.link.html
** https://www.freedesktop.org/software/systemd/man/systemd.link.html
** actually implemented by udev, not networkd
** actually implemented by udev on boot, not networkd
* <code>systemd.network.netdevs</code> creates virtual network devices
* <code>systemd.network.netdevs</code> creates virtual network devices
** https://www.freedesktop.org/software/systemd/man/systemd.netdev.html
** https://www.freedesktop.org/software/systemd/man/systemd.netdev.html

Revision as of 16:11, 26 March 2023

Networkd is the network configuration component of the systemd software suite. It is well integrated into NixOS below systemd.network and should be preferred over networking.interfaces options for most use cases, since it receives far superior maintenance.

Configuration for networkd is split into three sections.

In most simple scenarios configuring existing network devices is what you want to do.

Enabling

To be able to use networkd configuration it needs to be enabled first.

systemd.network.enable = true;

Some guides will mention the networking.useNetworkd option, which offers translation of some networking.* options into networkd. If you can write your complete network setup in native networkd configuration, you should stay away from that option.

Examples

Examples should be concise and give proper hints on how to achieve a reliably working network-online.target.

Bonding

Given two hardlinks enp2s0 and enp3s0 create a virtual bond0 interface using Dynamic LACP (802.3ad), hashing outgoing packets using a packet's Layer3/4 (OSI Layer) information.

  systemd.network = {
    netdevs = {
      "10-bond0" = {
        netdevConfig = {
          Kind = "bond";
          Name = "bond0";
        };
        bondConfig = {
          Mode = "802.3ad";
          TransmitHashPolicy = "layer3+4";
        };
      };
    };
    networks = {
      "30-enp2s0" = {
        matchConfig.Name = "enp2s0";
        networkConfig.Bond = "bond0";
      };
      "30-enp3s0" = {
        matchConfig.Name = "enp3s0";
        networkConfig.Bond = "bond0";
      };
      "40-bond0" = {
        matchConfig.Name = "bond0";
        linkConfig = {
          RequiredForOnline = "carrier";
        };
        networkConfig.LinkLocalAddressing = "no";
      };
  };