Describe the bug
Unbound starts before the network interface gains carrier. On my system this caused the following errors:
Aug 21 13:55:55 arch unbound[453]: [453:0] error: failed to connect to redis server: Network is unreachable
Aug 21 13:55:55 arch unbound[453]: [453:0] error: redis_init: failed to init redis (for thread 0)
To reproduce
Steps to reproduce the behavior:
-
Use unbound.service from https://github.com/NLnetLabs/unbound/blob/master/contrib/unbound.service.in.
-
I am using systemd-networkd. However, I think this behavior can be reproduced with other network managers too. In my /etc/systemd/network/*.network file, I added the following lines:
[Link]
RequiredForOnline=routable
This ensures that the network is actually routable before the network is flagged as online.
-
Configure Redis in unbound.conf, so it uses an external database for cachedb. The following lines in my unbound.conf are related to Redis:
module-config: "respip validator cachedb iterator"
cachedb:
backend: "redis"
cachedb-check-when-serve-expired: yes
redis-server-host: 100.64.1.2
redis-server-port: 6458
redis-expire-records: no
redis-replica-server-port: 6621
redis-replica-server-path: "run/valkey/valkey.sock"
100.64.1.2 is a local ip-address of another computer.
-
Make sure there are no other applications with a (weak) requirement dependency on network-online.target. In other words, make sure that systemctl list-dependencies --reverse network-online.target doesn't list any dependencies or only lists dependencies that are not triggered on boot. On my system, systemctl list-dependencies --reverse network-online.target lists archlinux-keyring-wkd-sync.service as a dependency, but archlinux-keyring-wkd-sync.service is triggered by a timer and is not triggered on boot.
-
This means that network-online.target will not get started at all because the line After=network-online.target in unbound.service only defines an ordering dependency. It will not actually try to start network-online.target. This causes unbound to start too early. The following lines in the logs back my claim:
Aug 21 13:55:55 arch unbound[453]: [453:0] error: failed to connect to redis server: Network is unreachable
Aug 21 13:55:55 arch unbound[453]: [453:0] error: redis_init: failed to init redis (for thread 0)
Aug 21 13:55:56 arch systemd-networkd[397]: enp5s0: Gained carrier
Expected behavior
Unbound should always start after the network gains carrier.
You can easily achieve this by setting a weak requirement dependency on network-online.target for Unbound. Currently, it only relies on an ordering dependency (After=network-online.target). An ordering dependency doesn't actually trigger the dependency to start. This is where a (weak) requirement dependency comes in. In other words, please add Wants=network-online.target under [Unit] in unbound.service.
System:
- Unbound version: 1.23.1
- OS: Arch Linux
unbound -V output:
Version 1.23.1
Configure line: --prefix=/usr --sysconfdir=/etc --localstatedir=/var --sbindir=/usr/bin --disable-rpath --enable-dnscrypt --enable-dnstap --enable-pie --enable-relro-now --enable-subnet --enable-systemd --enable-tfo-client --enable-tfo-server --enable-cachedb --with-libhiredis --with-conf-file=/etc/unbound/unbound.conf --with-pidfile=/run/unbound.pid --with-rootkey-file=/etc/trusted-key.key --with-libevent --with-libnghttp2 --with-pyunbound
Linked libs: libevent 2.1.12-stable (it uses epoll), OpenSSL 3.5.2 5 Aug 2025
Linked modules: dns64 cachedb subnetcache respip validator iterator
DNSCrypt feature available
TCP Fastopen feature available
BSD licensed, see LICENSE in source package for details.
Report bugs to unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues
Additional information
One more remark related to systemd-networkd. I also needed to add the following lines to /etc/systemd/network/*.network:
[Link]
RequiredForOnline=routable
Without these lines, the network is flagged as online before the network is routable. This will cause the same error: error: failed to connect to redis server: Network is unreachable.
Describe the bug
Unbound starts before the network interface gains carrier. On my system this caused the following errors:
Aug 21 13:55:55 arch unbound[453]: [453:0] error: failed to connect to redis server: Network is unreachableAug 21 13:55:55 arch unbound[453]: [453:0] error: redis_init: failed to init redis (for thread 0)To reproduce
Steps to reproduce the behavior:
Use
unbound.servicefrom https://github.com/NLnetLabs/unbound/blob/master/contrib/unbound.service.in.I am using
systemd-networkd. However, I think this behavior can be reproduced with other network managers too. In my/etc/systemd/network/*.networkfile, I added the following lines:[Link]RequiredForOnline=routableThis ensures that the network is actually routable before the network is flagged as online.
Configure Redis in
unbound.conf, so it uses an external database forcachedb. The following lines in myunbound.confare related to Redis:module-config: "respip validator cachedb iterator"cachedb:backend: "redis"cachedb-check-when-serve-expired: yesredis-server-host: 100.64.1.2redis-server-port: 6458redis-expire-records: noredis-replica-server-port: 6621redis-replica-server-path: "run/valkey/valkey.sock"100.64.1.2 is a local ip-address of another computer.
Make sure there are no other applications with a (weak) requirement dependency on
network-online.target. In other words, make sure thatsystemctl list-dependencies --reverse network-online.targetdoesn't list any dependencies or only lists dependencies that are not triggered on boot. On my system,systemctl list-dependencies --reverse network-online.targetlistsarchlinux-keyring-wkd-sync.serviceas a dependency, butarchlinux-keyring-wkd-sync.serviceis triggered by a timer and is not triggered on boot.This means that
network-online.targetwill not get started at all because the lineAfter=network-online.targetinunbound.serviceonly defines an ordering dependency. It will not actually try to startnetwork-online.target. This causes unbound to start too early. The following lines in the logs back my claim:Aug 21 13:55:55 arch unbound[453]: [453:0] error: failed to connect to redis server: Network is unreachableAug 21 13:55:55 arch unbound[453]: [453:0] error: redis_init: failed to init redis (for thread 0)Aug 21 13:55:56 arch systemd-networkd[397]: enp5s0: Gained carrierExpected behavior
Unbound should always start after the network gains carrier.
You can easily achieve this by setting a weak requirement dependency on
network-online.targetfor Unbound. Currently, it only relies on an ordering dependency (After=network-online.target). An ordering dependency doesn't actually trigger the dependency to start. This is where a (weak) requirement dependency comes in. In other words, please addWants=network-online.targetunder[Unit]inunbound.service.System:
unbound -Voutput:Version 1.23.1Configure line: --prefix=/usr --sysconfdir=/etc --localstatedir=/var --sbindir=/usr/bin --disable-rpath --enable-dnscrypt --enable-dnstap --enable-pie --enable-relro-now --enable-subnet --enable-systemd --enable-tfo-client --enable-tfo-server --enable-cachedb --with-libhiredis --with-conf-file=/etc/unbound/unbound.conf --with-pidfile=/run/unbound.pid --with-rootkey-file=/etc/trusted-key.key --with-libevent --with-libnghttp2 --with-pyunboundLinked libs: libevent 2.1.12-stable (it uses epoll), OpenSSL 3.5.2 5 Aug 2025Linked modules: dns64 cachedb subnetcache respip validator iteratorDNSCrypt feature availableTCP Fastopen feature availableBSD licensed, see LICENSE in source package for details.Report bugs to unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issuesAdditional information
One more remark related to
systemd-networkd. I also needed to add the following lines to/etc/systemd/network/*.network:[Link]RequiredForOnline=routableWithout these lines, the network is flagged as online before the network is routable. This will cause the same error:
error: failed to connect to redis server: Network is unreachable.