Don’t use network-online.target either, though, since that will force boot to be delayed until a network connection is established.
Combined with multi-user.target or default.target, this results in laptops waiting 60 seconds to start your login manager any time they’re not in range of a known wifi. Even when they are in range this comes at a hefty startup delay.
The systemd manual used to recommend depending on network.target, I’m pretty sure, since this guaranteed being able to bind on an IP address (even if this did not guarantee that anything would be able to reach that address). Wonder if this is my imagination or if something changed.
I don’t think network.target ever promised a working IP address, right? It just meant order this service after all the various services which manage the network. They could be NetworkManager, iwd, a custom script, pppd, whatever you want. Depending on the Type= specified in the service file, the various network management services may only have forked and not signalled readiness when network.target is reached. For an IP address, any IP address, you need to have reached network-online.target.
In any case, I personally do not use network.target. I rarely deal with network-dependent services where shutting down gracefully is important.
I thought it promised that at least loopback addresses can be bound to. Tbh given the documentation for systemd.special, it seems like it might, given that virtual devices are guaranteed to be available, and the loopback device is such a device.
And yeah, no matter what the pretty systemd page says, network.target does actually guarantee that virtual devices are up.
Strangely, it does not however seem to guarantee that their IP setup is finished, so I think you aren’t guaranteed to be able to bind a 127 address, or even 0.0.0.0. I don’t understand why it should not wait for that, seems like a useful synchronization primitive (and in practice, it is used like that, probably works most of the time too).
network-online.target OTOH used to be explicitly recommended against by the systemd docs, precisely because it covers more than just “loopback IP addresses are bindable”, and I’m fairly certain of that, too. I think something big changed within the last year or so.
If you look at the networkd code, you’ll find that nothing actually guarantees virtual devices being allocated by the time network.target is reached. They say “should be allocated” because in practice virtual devices are created/allocated so fast that anything ordered after network.target will almost definitely see them present.
Loopback is a special case because it’s set by pid1. So even if you have no network manager of any sort, loopback is always bindable.
And I don’t think the network-online.target advice has changed. The man page still says (and has always said as far as I remember) daemons that only serve other hosts generally shouldn’t pull it in. For servers, the robust option is neither target: bind the wildcard, or use IP_FREEBIND if you need a specific address.
Sounds like LLM output, I hope you’re engaging in good faith and not using one.
Or use netlink as god intended to dynamically respond to the conditions on the box.
Yeah, I’m sorry, but that’s literally what I said; 0.0.0.0 is the wildcard, and I was under the assumption that network.target guarantees it can be bound, but the systemd.special docs say it doesn’t.
I haven’t read the networkd code because it’s irrelevant here; what matters is the systemd.special documentation, because it’s a contract for distros to fulfill, not a guide to using networkd. Those targets existed long before networkd, and other network managers exist (in fact, most of my machines do not use networkd).
If the documentation says that virtual devices should be up by the time network.target starts, that is a contract; if the contract is fulfilled by “well that happens super quick!”, that is a potential race condition, and I’d argue a bug in the systemd docs.
What you’re saying now also directly contradicts what you said earlier:
Kinda hard to trust you as a reliable source on any of this if you’re contradicting yourself and don’t seem to understand what I’m saying, nor really the point of the target units in the first place.
That’s fair, and I spoke loosely. My bad. Wildcard and loopback can be bound at any time, that’s true. What I meant was a specific address which is configured by a network manager and network.target does not guarantee that.
On the race condition, I agree. networkd signals readiness before it has even sent the requests to create the netdevs afaict. Idk if it’s a bug in networkd or the docs, but I think it’s worth reporting upstream in either case.
Great, we got another claude bot…
this is clearly llm text designed to waste our time responding, the sycophantic phrases are bog-standard stuff.