Systemd/networkd: Difference between revisions
imported>Mweinelt mNo edit summary |
imported>RaitoBezarius add DHCP example |
||
Line 29: | Line 29: | ||
Examples should be concise and give proper hints on how to achieve a reliably 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>. | ||
=== DHCP === | |||
Assuming your *wired* interface that should run DHCP is called <code>enp1s0</code>, this configuration will enable DHCP. | |||
<syntaxhighlight lang="nix"> | |||
systemd.network.networks."10-dhcp-wan" = { | |||
matchConfig.Name = "enp1s0"; | |||
linkConfig.RequiredForOnline = true; # Necessary if you want to make network-online.target dependent on this interface being online. | |||
DHCP = "yes"; | |||
}; | |||
</syntaxhighlight> | |||
=== Bonding === | === Bonding === |
Revision as of 16:14, 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.
systemd.network.links
reconfigures existing network devices- https://www.freedesktop.org/software/systemd/man/systemd.link.html
- actually implemented by udev on boot, not networkd
systemd.network.netdevs
creates virtual network devicessystemd.network.networks
configures network devices
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
.
DHCP
Assuming your *wired* interface that should run DHCP is called enp1s0
, this configuration will enable DHCP.
systemd.network.networks."10-dhcp-wan" = {
matchConfig.Name = "enp1s0";
linkConfig.RequiredForOnline = true; # Necessary if you want to make network-online.target dependent on this interface being online.
DHCP = "yes";
};
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";
};
};