fuck systemd-networkd-wait-online.service: "start job is running for wait for network to be configured"

fuck systemd-networkd-wait-online.service: “start job is running for wait for network to be configured”

When using Ubuntu, I have encountered this kind of situation many times.

It looks like the image shown.

image

After booting into the system, you can see through systemd-analyze blame​ that the startup time of systemd-networkd-wait-online.service reaches several minutes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
r00t@f4keserver:~$ sudo systemctl status systemd-networkd-wait-online.service
● systemd-networkd-wait-online.service - Wait for Network to be Configured
Loaded: loaded (/lib/systemd/system/systemd-networkd-wait-online.service; enabled-runtime; vendor preset: disabled)
Active: active (exited) since Mon 2024-01-15 03:36:01 UTC; 12min ago
Docs: man:systemd-networkd-wait-online.service(8)
Main PID: 624 (code=exited, status=0/SUCCESS)
CPU: 4ms

Jan 15 03:35:56 f4keserver systemd[1]: Starting Wait for Network to be Configured...
Jan 15 03:36:01 f4keserver systemd-networkd-wait-online[624]: managing: ens33
Jan 15 03:36:01 f4keserver systemd[1]: Finished Wait for Network to be Configured.

r00t@f4keserver:~$ cat /lib/systemd/system/systemd-networkd-wait-online.service
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

[Unit]
Description=Wait for Network to be Configured
Documentation=man:systemd-networkd-wait-online.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
Requires=systemd-networkd.service
After=systemd-networkd.service
Before=network-online.target shutdown.target

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-networkd-wait-online
RemainAfterExit=yes

[Install]
WantedBy=network-online.target

You can see that there is a timeout​ parameter for /lib/systemd/systemd-networkd-wait-online​. This means you can add the argument --timeout=1​ in the corresponding systemd-networkd-wait-online service file, indicating a timeout of 1 second.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
r00t@f4keserver:~$ /lib/systemd/systemd-networkd-wait-online --help
systemd-networkd-wait-online [OPTIONS...]

Block until network is configured.

-h --help Show this help
--version Print version string
-q --quiet Do not show status information
-i --interface=INTERFACE[:MIN_OPERSTATE[:MAX_OPERSTATE]]
Block until at least these interfaces have appeared
--ignore=INTERFACE Don't take these interfaces into account
-o --operational-state=MIN_OPERSTATE[:MAX_OPERSTATE]
Required operational state
-4 --ipv4 Requires at least one IPv4 address
-6 --ipv6 Requires at least one IPv6 address
--any Wait until at least one of the interfaces is online
--timeout=SECS Maximum time to wait for network connectivity

See the systemd-networkd-wait-online.service(8) man page for details.

look like this

/lib/systemd/system/systemd-networkd-wait-online.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=Wait for Network to be Configured
Documentation=man:systemd-networkd-wait-online.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
Requires=systemd-networkd.service
After=systemd-networkd.service
Before=network-online.target shutdown.target

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-networkd-wait-online --timeout=1
RemainAfterExit=yes

[Install]
WantedBy=network-online.target