Systemd/networkd: Difference between revisions

From NixOS Wiki
imported>Mweinelt
mNo edit summary
imported>Mweinelt
Line 28: Line 28:
== Examples ==
== Examples ==


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


=== Bonding ===
=== Bonding ===

Revision as of 16:06, 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";
      };
  };