Linux systemd and Network Status

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

systemd-based boot scripts rely on the $network boot facility to express their dependency on the network status (note that '$' is the conventional way to refer to a boot facility and it does not imply variable substitution). According to the Linux specifications, $network can be used to signal that basic network support is available. This definition is rather vague.

In systemd, three target units take the role of $network:

  • network.target, if reached, indicates that the network management stack is up. This carries little meaning during startup: whether any network interface is already configured is undefined. The primary purpose is to be used during shutdown. Shutdown ordering of units in systemd is in reverse of the startup ordering, any unit that declares After=network.target can be sure it is stopped before the network is shut down. This allows services to cleanly terminate connections. Those services should place an After=network.target dependency and avoid Wants=network.target or even Requires=network.target. network.target is a passive unit: it cannot be started directly, it is not pulled by any service that wants to make use of the network, but by the network management service (NetworkManager) itself.
  • network-online.target is a target that actively waits until the network is "up". The definition of "up" depends on the network management software (not necessarily NetworkManager, the target is reached even if NetworkManager is absent). network-online.target usually indicates a configured, routable IP address of some kind. The primary purpose is to delay activation of services until the network is up. network-online.target is an active target, meaning that it may be pulled by services requiring the network to be up, but it is not pulled by the network management service itself (NetworkManager). By default, all remote mounts declared in /etc/fstab pull this service in.