Systemd/networkd: Difference between revisions

imported>Mweinelt
imported>Mweinelt
network-online.target
Line 25: Line 25:
can write your complete network setup in native networkd configuration, you should
can write your complete network setup in native networkd configuration, you should
stay away from that option.
stay away from that option.
=== network-online.target ===
While <code>network.target</code> only requires the network management stack
to be up, which means it does not care about network interfaces being configured,
the <code>network-online.target</code> waits until a defined set of network
interfaces are in a state, that by its configuration is considered online.
When networkd is enabled, the <code>network-online.target</code> is implemented
through the <code>systemd-networkd-wait-online.service</code>, which makes
sure interfaces configured through networkd are in their expected operational state.
The current operational state of network interfaces can be learned from <code>networkctl</code>.
<syntaxhighlight lang="bash">
❯ networkctl
IDX LINK          TYPE    OPERATIONAL SETUP   
  1 lo            loopback carrier    unmanaged
  2 enp10s0      ether    routable    unmanaged
  3 wlp9s0        wlan    no-carrier  unmanaged
</syntaxhighlight>
For most network interfaces that will mean that they have <code>routable</code>
network connectivity, but in more complex setups some links may be content with more
simple states like <code>carrier</code> or <code>enslaved</code>. Interfaces that
are managed by networkd, but not always in use, shouldn't be required for
<code>network-online.target</code>
<syntaxhighlight lang="nix">
systemd.network."50-enp3s0" = {
  matchConfig.Name = "enp3s0";
  # acquire a DHCP lease, when connected
  networkConfig.DHCP = "yes";
  # this port is not always connected and not required to be online
  linkConfig.RequiredForOnline = "no";
};
</syntaxhighlight>
Note that the default value for <code>linkConfig.RequiredForOnline</code> is unexpectedly
<code>"yes"</code>, which often leads to a failing <code>network-online.target</code>.
Setting individual interfaces to <code>"no"</code> is a perfectly valid choice
and should be considered, before disabling the <code>systemd-networkd-wait-online.service</code>
entirely, because a working <code>network-online.target</code> is required for some
services to properly start without race conditions.
Further details in the upstream documentation:
* [https://www.freedesktop.org/software/systemd/man/systemd.network.html#RequiredForOnline= RequiredForOnline=]
* [https://www.freedesktop.org/software/systemd/man/networkctl.html#%0A%20%20%20%20%20%20%20%20%20%20list%0A%20%20%20%20%20%20%20%20%20%20PATTERN%E2%80%A6%0A%20%20%20%20%20%20%20%20 List of operational interface states]


== Examples ==
== Examples ==