Chapter 39. Systemd network targets and services
RHEL uses the network
and network-online
targets and the NetworkManager-wait-online
service while applying network settings. Configure systemd
services to start after the network is fully available if those services cannot react dynamically to a change in the network state.
39.1. Differences between the network and network-online systemd target Copy linkLink copied to clipboard!
The network
target indicates that the network management stack has been started, and the network-online
target is to actively wait until the network is up and a usable network connection is available.
Systemd maintains the network
and network-online
target units. The special units such as NetworkManager-wait-online.service
, have WantedBy=network-online.target
and Before=network-online.target
parameters. If enabled, these units get started with network-online.target
and delay the target to be reached until some form of network connectivity is established. They delay the network-online
target until the network is connected.
The network-online
target starts a service, which adds substantial delays to further execution. Systemd automatically adds dependencies with Wants
and After
parameters for this target unit to all the System V (SysV) init
script service units with a Linux Standard Base (LSB) header referring to the $network
facility. The LSB header is metadata for init
scripts. You can use it to specify dependencies. This is similar to the systemd
target.
The network
target does not significantly delay the execution of the boot process. Reaching the network
target means that the service that is responsible for setting up the network has started. However, it does not mean that a network device was configured. This target is important during the shutdown of the system. For example, if you have a service that was ordered after the network
target during bootup, then this dependency is reversed during the shutdown. The network does not get disconnected until your service has been stopped. All mount units for remote network file systems automatically start the network-online
target unit and order themselves after it.
The network-online
target unit is only useful during the system startup. After the system has completed booting up, this target does not track the online state of the network. Therefore, you cannot use network-online
to monitor the network connection. This target provides a one-time system startup concept.
39.2. Overview of NetworkManager-wait-online Copy linkLink copied to clipboard!
The NetworkManager-wait-online
service delays reaching the network-online
target until NetworkManager reports that the startup is complete.
During boot, NetworkManager activates all profiles with the connection.autoconnect
parameter set to yes
. However, the activation of profiles is not complete as long as NetworkManager profiles are in an activating state. If activation fails, NetworkManager retries the activation depending on the value of the connection.autoconnect-retries
.
When a device reaches the activated state depends on its configuration. For example, if a profiles contains both IPv4 and IPv6 configuration, by default, NetworkManager considers the device as fully activated when only one of the Address families is ready. The ipv4.may-fail
and ipv6.may-fail
parameters in a connection profile control this behavior.
For Ethernet devices, NetworkManager waits for the carrier with a timeout. Consequently, if the Ethernet cable is not connected, this can further delay NetworkManager-wait-online.service
.
When the startup completes, either all profiles are in a disconnected state or are successfully activated. You can configure profiles to auto-connect. The following are a few examples of parameters that set timeouts or define when the connection is considered active:
-
connection.wait-device-timeout
: Sets the timeout for the driver to detect the device. -
ipv4.may-fail
andipv6.may-fail
: Sets activation with one IP address family ready, or whether a particular address family must have completed configuration. -
ipv4.gateway-ping-timeout
: Delays network activation until NetworkManager receives a ping response from the IPv4 gateway. The system waits up to the specified number of seconds before proceeding. -
ip-ping-timeout
andip-ping-addresses
: Delays network activation until NetworkManager receives a ping response from the hosts defined inip-ping-addresses
. The system waits up to the specified number of seconds before proceeding.
For further details, see the nm-settings(5)
, systemd.special(7)
, NetworkManager-wait-online.service(8)
man pages on your system.
39.3. Configuring a systemd service to start after the network has been started Copy linkLink copied to clipboard!
RHEL installs systemd
service files in the /usr/lib/systemd/system/
directory. You can create a drop-in snippet in /etc/systemd/system/<service_name>.service.d/
to start a service after the network is online.
This snippet’s settings override any conflicting settings in the original service file.
Procedure
Open a service file in the editor:
systemctl edit <service_name>
# systemctl edit <service_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the following, and save the changes:
[Unit] After=network-online.target
[Unit] After=network-online.target
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the
systemd
service.systemctl daemon-reload
# systemctl daemon-reload
Copy to Clipboard Copied! Toggle word wrap Toggle overflow