[GH-ISSUE #2575] Ubuntu 24.04: DNS not configured on amn0 after connect (race condition with systemd-resolved restart) #1166

Open
opened 2026-10-14 03:35:34 +07:00 by bsakaguchi · 14 comments
Owner

Originally created by @akonovaloff on GitHub (May 6, 2026).
Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/2575

Environment

  • OS: Ubuntu 24.04.4 LTS
  • AmneziaVPN: 4.8.15.4
  • Protocol: AmneziaWG2

Problem
After connecting, the VPN tunnel is up but internet doesn't work.

  • ping 8.8.8.8 succeeds (tunnel is alive)
  • ping google.com hangs (DNS broken)
  • resolvectl status hangs with Connection timed out
  • resolvectl status amn0 shows Current Scopes: none instead of DNS

Happens on most connects, especially noticeable right after the first connection attempt.

Root cause
AmneziaVPN restarts systemd-resolved and immediately tries to configure DNS on amn0 via DBus. The service hasn't fully initialized its DBus interface yet, so the call fails silently and DNS is never set on amn0.

Visible in /var/log/AmneziaVPN/AmneziaVPN-service.log right after connect:

[DEBUG] Amnezia  : Restarting systemd-resolved.service
[DEBUG] Amnezia  : Flush dns completed
[ERROR] Amnezia DnsUtilsLinux : Error retrieving the DNS domains from the DBus service
[ERROR] Amnezia DnsUtilsLinux : Error received from the DBus service
[ERROR] Amnezia DnsUtilsLinux : Error received from the DBus service

Workaround
Note: systemctl restart systemd-resolved hangs when resolved is stuck — use kill + start instead.

Manual fix (run after connecting when DNS doesn't work):

sudo systemctl kill systemd-resolved
sudo systemctl start systemd-resolved

for i in $(seq 1 15); do
    busctl status org.freedesktop.resolve1 &>/dev/null && break
    sleep 1
done

sudo resolvectl dns amn0 8.8.8.8 1.0.0.1
sudo resolvectl domain amn0 "~."

Permanent automated fix — udev rule that triggers a systemd service on amn0 creation:

/etc/udev/rules.d/99-amnezia-dns.rules:

ACTION=="add", SUBSYSTEM=="net", KERNEL=="amn0", TAG+="systemd", ENV{SYSTEMD_WANTS}="amnezia-fix-dns.service"

/etc/systemd/system/amnezia-fix-dns.service:

[Unit]
Description=Fix AmneziaVPN DNS on amn0
After=systemd-resolved.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/amnezia-fix-dns.sh

/usr/local/bin/amnezia-fix-dns.sh:

#!/bin/bash
for i in $(seq 1 15); do
    busctl status org.freedesktop.resolve1 &>/dev/null && break
    sleep 1
done
resolvectl dns amn0 8.8.8.8 1.0.0.1
resolvectl domain amn0 "~."

Expected behavior
DNS should be correctly configured on amn0 immediately after connecting.

Originally created by @akonovaloff on GitHub (May 6, 2026). Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/2575 **Environment** - OS: Ubuntu 24.04.4 LTS - AmneziaVPN: 4.8.15.4 - Protocol: AmneziaWG2 **Problem** After connecting, the VPN tunnel is up but internet doesn't work. - `ping 8.8.8.8` succeeds (tunnel is alive) - `ping google.com` hangs (DNS broken) - `resolvectl status` hangs with `Connection timed out` - `resolvectl status amn0` shows `Current Scopes: none` instead of `DNS` Happens on most connects, especially noticeable right after the first connection attempt. **Root cause** AmneziaVPN restarts `systemd-resolved` and immediately tries to configure DNS on amn0 via DBus. The service hasn't fully initialized its DBus interface yet, so the call fails silently and DNS is never set on amn0. Visible in `/var/log/AmneziaVPN/AmneziaVPN-service.log` right after connect: ``` [DEBUG] Amnezia : Restarting systemd-resolved.service [DEBUG] Amnezia : Flush dns completed [ERROR] Amnezia DnsUtilsLinux : Error retrieving the DNS domains from the DBus service [ERROR] Amnezia DnsUtilsLinux : Error received from the DBus service [ERROR] Amnezia DnsUtilsLinux : Error received from the DBus service ``` **Workaround** Note: `systemctl restart systemd-resolved` hangs when resolved is stuck — use `kill` + `start` instead. Manual fix (run after connecting when DNS doesn't work): ```bash sudo systemctl kill systemd-resolved sudo systemctl start systemd-resolved for i in $(seq 1 15); do busctl status org.freedesktop.resolve1 &>/dev/null && break sleep 1 done sudo resolvectl dns amn0 8.8.8.8 1.0.0.1 sudo resolvectl domain amn0 "~." ``` Permanent automated fix — udev rule that triggers a systemd service on amn0 creation: `/etc/udev/rules.d/99-amnezia-dns.rules`: ``` ACTION=="add", SUBSYSTEM=="net", KERNEL=="amn0", TAG+="systemd", ENV{SYSTEMD_WANTS}="amnezia-fix-dns.service" ``` `/etc/systemd/system/amnezia-fix-dns.service`: ```ini [Unit] Description=Fix AmneziaVPN DNS on amn0 After=systemd-resolved.service [Service] Type=oneshot ExecStart=/usr/local/bin/amnezia-fix-dns.sh ``` `/usr/local/bin/amnezia-fix-dns.sh`: ```bash #!/bin/bash for i in $(seq 1 15); do busctl status org.freedesktop.resolve1 &>/dev/null && break sleep 1 done resolvectl dns amn0 8.8.8.8 1.0.0.1 resolvectl domain amn0 "~." ``` **Expected behavior** DNS should be correctly configured on amn0 immediately after connecting.
Author
Owner

@akonovaloff commented on GitHub (May 6, 2026):

For anyone hitting this issue, here's a step-by-step fix:

Quick manual fix

Run this after connecting when internet doesn't work:

#!/bin/bash
echo "Restarting systemd-resolved..."
sudo systemctl kill systemd-resolved
sudo systemctl start systemd-resolved

echo "Waiting for DBus..."
for i in $(seq 1 15); do
    busctl status org.freedesktop.resolve1 &>/dev/null && break
    sleep 1
done

echo "Setting DNS on amn0..."
sudo resolvectl dns amn0 8.8.8.8 1.0.0.1
sudo resolvectl domain amn0 "~."

echo "Done. Testing..."
ping -c 2 google.com

Permanent fix (runs automatically on every connect)

# 1. Create the fix script
sudo tee /usr/local/bin/amnezia-fix-dns.sh > /dev/null <<'SCRIPT'
#!/bin/bash
for i in $(seq 1 15); do
    busctl status org.freedesktop.resolve1 &>/dev/null && break
    sleep 1
done
resolvectl dns amn0 8.8.8.8 1.0.0.1
resolvectl domain amn0 "~."
SCRIPT
sudo chmod +x /usr/local/bin/amnezia-fix-dns.sh

# 2. Create systemd service
sudo tee /etc/systemd/system/amnezia-fix-dns.service > /dev/null <<'SERVICE'
[Unit]
Description=Fix AmneziaVPN DNS on amn0
After=systemd-resolved.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/amnezia-fix-dns.sh
SERVICE

# 3. Create udev rule
echo 'ACTION=="add", SUBSYSTEM=="net", KERNEL=="amn0", TAG+="systemd", ENV{SYSTEMD_WANTS}="amnezia-fix-dns.service"' \
    | sudo tee /etc/udev/rules.d/99-amnezia-dns.rules

# 4. Apply
sudo systemctl daemon-reload
sudo udevadm control --reload-rules

After this, DNS will be fixed automatically every time you connect.

<!-- gh-comment-id:4389093248 --> @akonovaloff commented on GitHub (May 6, 2026): For anyone hitting this issue, here's a step-by-step fix: ## Quick manual fix Run this after connecting when internet doesn't work: ```bash #!/bin/bash echo "Restarting systemd-resolved..." sudo systemctl kill systemd-resolved sudo systemctl start systemd-resolved echo "Waiting for DBus..." for i in $(seq 1 15); do busctl status org.freedesktop.resolve1 &>/dev/null && break sleep 1 done echo "Setting DNS on amn0..." sudo resolvectl dns amn0 8.8.8.8 1.0.0.1 sudo resolvectl domain amn0 "~." echo "Done. Testing..." ping -c 2 google.com ``` ## Permanent fix (runs automatically on every connect) ```bash # 1. Create the fix script sudo tee /usr/local/bin/amnezia-fix-dns.sh > /dev/null <<'SCRIPT' #!/bin/bash for i in $(seq 1 15); do busctl status org.freedesktop.resolve1 &>/dev/null && break sleep 1 done resolvectl dns amn0 8.8.8.8 1.0.0.1 resolvectl domain amn0 "~." SCRIPT sudo chmod +x /usr/local/bin/amnezia-fix-dns.sh # 2. Create systemd service sudo tee /etc/systemd/system/amnezia-fix-dns.service > /dev/null <<'SERVICE' [Unit] Description=Fix AmneziaVPN DNS on amn0 After=systemd-resolved.service [Service] Type=oneshot ExecStart=/usr/local/bin/amnezia-fix-dns.sh SERVICE # 3. Create udev rule echo 'ACTION=="add", SUBSYSTEM=="net", KERNEL=="amn0", TAG+="systemd", ENV{SYSTEMD_WANTS}="amnezia-fix-dns.service"' \ | sudo tee /etc/udev/rules.d/99-amnezia-dns.rules # 4. Apply sudo systemctl daemon-reload sudo udevadm control --reload-rules ``` After this, DNS will be fixed automatically every time you connect.
Author
Owner

@tiaga commented on GitHub (May 8, 2026):

Found that disabling KillSwitch can be also used as a workaround.

<!-- gh-comment-id:4405866049 --> @tiaga commented on GitHub (May 8, 2026): Found that disabling KillSwitch can be also used as a workaround.
Author
Owner

@dimadze1337 commented on GitHub (Jun 22, 2026):

This bug still persist

<!-- gh-comment-id:4764687224 --> @dimadze1337 commented on GitHub (Jun 22, 2026): This bug still persist
Author
Owner

@DenisDudnik commented on GitHub (Aug 15, 2026):

ver 5.0.0.5.
This bug still persist

<!-- gh-comment-id:5302126166 --> @DenisDudnik commented on GitHub (Aug 15, 2026): ver 5.0.0.5. This bug still persist
Author
Owner

@garry0garry commented on GitHub (Aug 19, 2026):

ver 5.0.0.5.
This bug still persist

<!-- gh-comment-id:5346857202 --> @garry0garry commented on GitHub (Aug 19, 2026): ver 5.0.0.5. This bug still persist
Author
Owner

@DmitriyTischenko commented on GitHub (Aug 21, 2026):

ver 5.0.0.5.
This bug still persist

<!-- gh-comment-id:5368560120 --> @DmitriyTischenko commented on GitHub (Aug 21, 2026): ver 5.0.0.5. This bug still persist
Author
Owner

@rasolAAaa commented on GitHub (Aug 21, 2026):

باکمال تشکر از مدیریت محترم بله راه‌اندازی ش

در تاریخ جمعه 21 اوت 2026،‏ 14:48 Dmitriy Tischenko <
@.***> نوشت:

DmitriyTischenko left a comment (amnezia-vpn/amnezia-client#2575)
https://github.com/amnezia-vpn/amnezia-client/issues/2575#issuecomment-5368560120

ver 5.0.0.5.
This bug still persist

—
Reply to this email directly, view it on GitHub
https://github.com/amnezia-vpn/amnezia-client/issues/2575?email_source=notifications&email_token=BIQMEYU52CCUF4GHMHPAWVT5LAOWBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMZWHA2TMMBRGIYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5368560120,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/BIQMEYTKCE64FTQNPI67LNL5LAOWBAVCNFSNUABFKJSXA33TNF2G64TZHMZTCNJQGM2TGNZRHNEXG43VMU5TIMZZGIYTKMJUGE2KC5QC
.
You are receiving this because you are subscribed to this thread.Message
ID: @.***>

<!-- gh-comment-id:5368592872 --> @rasolAAaa commented on GitHub (Aug 21, 2026): باکمال تشکر از مدیریت محترم بله راه‌اندازی ش در تاریخ جمعه 21 اوت 2026،‏ 14:48 Dmitriy Tischenko < ***@***.***> نوشت: > *DmitriyTischenko* left a comment (amnezia-vpn/amnezia-client#2575) > <https://github.com/amnezia-vpn/amnezia-client/issues/2575#issuecomment-5368560120> > > ver 5.0.0.5. > This bug still persist > > — > Reply to this email directly, view it on GitHub > <https://github.com/amnezia-vpn/amnezia-client/issues/2575?email_source=notifications&email_token=BIQMEYU52CCUF4GHMHPAWVT5LAOWBA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMZWHA2TMMBRGIYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5368560120>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/BIQMEYTKCE64FTQNPI67LNL5LAOWBAVCNFSNUABFKJSXA33TNF2G64TZHMZTCNJQGM2TGNZRHNEXG43VMU5TIMZZGIYTKMJUGE2KC5QC> > . > You are receiving this because you are subscribed to this thread.Message > ID: ***@***.***> >
Author
Owner

@garry0garry commented on GitHub (Aug 21, 2026):

Workaround: Manually configure DNS using AmneziaVPN addresses and specify a static IP address on the interface.

<!-- gh-comment-id:5369118174 --> @garry0garry commented on GitHub (Aug 21, 2026): Workaround: Manually configure DNS using AmneziaVPN addresses and specify a static IP address on the interface.
Author
Owner

@madpower2000 commented on GitHub (Aug 26, 2026):

I was able to reproduce and investigate this issue in detail on Ubuntu 24.04 / systemd 255 with AmneziaVPN 5.0.1.5, and I believe there is an important additional detail beyond a simple DBus race condition.

Environment

  • Ubuntu 24.04
  • systemd 255
  • kernel 7.0.0-30-generic
  • AmneziaVPN 5.0.1.5
  • Amnezia protocol: AWG
  • Amnezia interface: amn0

I also have Hiddify 4.1.1 installed, but I verified that the problem reproduces from a completely clean networking baseline, with Hiddify not involved at all.


Symptom

Amnezia connects successfully and creates the tunnel, but immediately after connection all normal hostname-based Internet access stops working.

For example:

getent hosts cloudflare.com
resolvectl query cloudflare.com
curl https://cloudflare.com

all fail.

However, the VPN tunnel itself is still functional.

Traffic sent directly by IP through the tunnel works, so this is not a tunnel/routing failure. The failure is specifically in the local DNS path.


What happens during Amnezia connection

When Amnezia connects, I observe the following:

  1. amn0 is created.
  2. Full-tunnel routes are installed, including:
0.0.0.0/1 dev amn0 metric 1
128.0.0.0/1 dev amn0 metric 1
  1. Amnezia configures DNS for amn0, including DNS servers such as:
100.64.0.1
8.8.4.4

and domain:

~.
  1. Amnezia restarts systemd-resolved.

The important part is what happens next.


systemd-resolved gets stuck at ~100% CPU

After Amnezia restarts systemd-resolved, the process enters a persistent busy loop at approximately 100% CPU.

This is not just a brief startup race.

I inspected the stuck process with both gdb and strace.

The stack/runtime behavior points to the sd_event loop, with activity around timerfd_settime, epoll_wait, and read.

strace shows extremely high repeated syscall activity on the order of tens of thousands of calls per second.

While systemd-resolved is in this state, the local stub resolver:

127.0.0.53

stops answering DNS requests.

That explains why all browsers and normal applications report that the Internet is unavailable even though the VPN tunnel itself is healthy.


Restarting systemd-resolved does not fix it

I also tested:

sudo systemctl restart systemd-resolved

while Amnezia is connected.

The newly started systemd-resolved process goes back into the same ~100% CPU loop, so restarting the service is not sufficient.

This makes me think the problem is more than just "Amnezia calls DBus before resolved is ready."

There appears to be a reproducible interaction between Amnezia's DNS setup / resolved restart sequence and systemd 255 that leaves systemd-resolved in a broken state.


Amnezia log errors

At the same time, Amnezia logs DNS-related DBus errors such as:

[ERROR] AmneziaVPN DnsUtilsLinux : Error retrieving the DNS domains from the DBus service
[ERROR] AmneziaVPN DnsUtilsLinux : Error received from the DBus service

This is consistent with Amnezia attempting to configure DNS over DBus while systemd-resolved is already wedged.


Tunnel data plane remains healthy

The key observation is that the tunnel itself continues to work.

With DNS bypassed, HTTPS traffic through amn0 succeeds.

For example, a direct-IP HTTPS request through the Amnezia tunnel returns a valid HTTP response.

The upstream DNS servers assigned to the tunnel also respond normally when queried directly.

So the failure can be classified as:

VPN tunnel / routing: WORKING
TCP / HTTPS:          WORKING
upstream DNS:         WORKING
127.0.0.53 stub:      BROKEN
systemd-resolved:     ~100% CPU busy loop

Temporary workaround that confirms the diagnosis

As a diagnostic workaround, I temporarily bypassed the broken 127.0.0.53 stub and pointed /etc/resolv.conf directly at the live DNS servers used by the Amnezia tunnel:

nameserver 100.64.0.1
nameserver 8.8.4.4

Immediately after doing that:

getent hosts cloudflare.com
curl https://cloudflare.com

started working normally again.

The public IP also correctly changed to the Amnezia VPN exit IP.

So the workaround restores connectivity without touching:

  • routes
  • ip rule
  • nftables
  • iptables
  • the amn0 interface
  • the VPN process

It only bypasses the stuck local systemd-resolved stub.

When Amnezia disconnects, restoring the original /etc/resolv.conf symlink to:

/run/systemd/resolve/stub-resolv.conf

returns the machine to the normal baseline state.


Hiddify was ruled out

Initially I suspected a conflict with Hiddify because both clients are installed on the same machine.

I tested this explicitly.

Hiddify creates:

tun0
routing table 2022
ip rules around priorities 9000-9010

while connected.

After disconnecting Hiddify:

  • tun0 disappears
  • table 2022 disappears
  • all Hiddify ip rule entries disappear
  • sing-box exits
  • /etc/resolv.conf remains unchanged
  • no stale routing or DNS state remains

I repeated this multiple times.

More importantly, the Amnezia DNS failure also occurs from a clean baseline where Hiddify was never connected.

So at least in my case, this is not caused by stale state from another VPN client.


Full reproduction

A simplified reproduction sequence is:

  1. Boot / clean network state.
  2. Confirm normal Internet and DNS work.
  3. Start AmneziaVPN 5.0.1.5.
  4. Connect using AWG.
  5. Confirm amn0 exists and full-tunnel routes are present.
  6. Observe systemd-resolved at ~100% CPU.
  7. Observe DNS queries through 127.0.0.53 fail.
  8. Observe Amnezia DnsUtilsLinux DBus errors.
  9. Confirm direct-IP traffic through the VPN still succeeds.
  10. Bypass 127.0.0.53 and use the tunnel DNS servers directly.
  11. DNS and browser traffic immediately start working.

No reboot is required to reproduce this.


My current workaround

For my system I implemented a small temporary keep-alive workaround:

  • when amn0 appears, /etc/resolv.conf is temporarily pointed at the DNS servers reported for the live tunnel;
  • when amn0 disappears, the original /etc/resolv.conf is restored byte-for-byte;
  • no firewall, routing, policy-routing, or VPN state is modified.

This makes Amnezia usable, but I consider this only a workaround, not an appropriate upstream fix.


Possible area to investigate

I think it would be useful to inspect the Linux DNS lifecycle around DnsUtilsLinux, especially:

  • why Amnezia needs to restart systemd-resolved;
  • whether the restart is required at all;
  • whether DNS configuration can be done only through org.freedesktop.resolve1;
  • what state is programmed immediately before/after the restart;
  • whether Amnezia waits for systemd-resolved to become fully usable after restart;
  • whether repeated DBus DNS operations can trigger this pathological sd_event behavior on systemd 255;
  • whether the interaction with the ~. routing domain is relevant.

I would be cautious about fixing this with only a sleep or retry loop, because in my reproduction systemd-resolved is not merely slow to start — it remains permanently stuck at ~100% CPU until Amnezia is disconnected / the state changes.


Summary

On my Ubuntu 24.04 system, the failure is reproducibly:

Amnezia connects
→ amn0 and routing are correct
→ Amnezia restarts/configures systemd-resolved
→ systemd-resolved enters persistent ~100% CPU sd_event loop
→ 127.0.0.53 stops answering
→ all normal DNS-based Internet access fails
→ tunnel itself remains healthy

Directly bypassing the local stub and using the tunnel's DNS servers restores connectivity immediately.

If useful, I can provide additional strace, gdb, resolvectl, route/rule, and Amnezia log output from the failing state.

<!-- gh-comment-id:5424325204 --> @madpower2000 commented on GitHub (Aug 26, 2026): I was able to reproduce and investigate this issue in detail on **Ubuntu 24.04 / systemd 255** with **AmneziaVPN 5.0.1.5**, and I believe there is an important additional detail beyond a simple DBus race condition. ### Environment * Ubuntu 24.04 * systemd 255 * kernel `7.0.0-30-generic` * AmneziaVPN `5.0.1.5` * Amnezia protocol: AWG * Amnezia interface: `amn0` I also have Hiddify 4.1.1 installed, but I verified that the problem reproduces from a completely clean networking baseline, with Hiddify not involved at all. --- ## Symptom Amnezia connects successfully and creates the tunnel, but immediately after connection all normal hostname-based Internet access stops working. For example: ```bash getent hosts cloudflare.com resolvectl query cloudflare.com curl https://cloudflare.com ``` all fail. However, the VPN tunnel itself is still functional. Traffic sent directly by IP through the tunnel works, so this is not a tunnel/routing failure. The failure is specifically in the local DNS path. --- ## What happens during Amnezia connection When Amnezia connects, I observe the following: 1. `amn0` is created. 2. Full-tunnel routes are installed, including: ```text 0.0.0.0/1 dev amn0 metric 1 128.0.0.0/1 dev amn0 metric 1 ``` 3. Amnezia configures DNS for `amn0`, including DNS servers such as: ```text 100.64.0.1 8.8.4.4 ``` and domain: ```text ~. ``` 4. Amnezia restarts `systemd-resolved`. The important part is what happens next. --- ## `systemd-resolved` gets stuck at ~100% CPU After Amnezia restarts `systemd-resolved`, the process enters a persistent busy loop at approximately 100% CPU. This is not just a brief startup race. I inspected the stuck process with both `gdb` and `strace`. The stack/runtime behavior points to the `sd_event` loop, with activity around `timerfd_settime`, `epoll_wait`, and `read`. `strace` shows extremely high repeated syscall activity on the order of tens of thousands of calls per second. While `systemd-resolved` is in this state, the local stub resolver: ```text 127.0.0.53 ``` stops answering DNS requests. That explains why all browsers and normal applications report that the Internet is unavailable even though the VPN tunnel itself is healthy. --- ## Restarting `systemd-resolved` does not fix it I also tested: ```bash sudo systemctl restart systemd-resolved ``` while Amnezia is connected. The newly started `systemd-resolved` process goes back into the same ~100% CPU loop, so restarting the service is not sufficient. This makes me think the problem is more than just "Amnezia calls DBus before resolved is ready." There appears to be a reproducible interaction between Amnezia's DNS setup / resolved restart sequence and systemd 255 that leaves `systemd-resolved` in a broken state. --- ## Amnezia log errors At the same time, Amnezia logs DNS-related DBus errors such as: ```text [ERROR] AmneziaVPN DnsUtilsLinux : Error retrieving the DNS domains from the DBus service [ERROR] AmneziaVPN DnsUtilsLinux : Error received from the DBus service ``` This is consistent with Amnezia attempting to configure DNS over DBus while `systemd-resolved` is already wedged. --- ## Tunnel data plane remains healthy The key observation is that the tunnel itself continues to work. With DNS bypassed, HTTPS traffic through `amn0` succeeds. For example, a direct-IP HTTPS request through the Amnezia tunnel returns a valid HTTP response. The upstream DNS servers assigned to the tunnel also respond normally when queried directly. So the failure can be classified as: ```text VPN tunnel / routing: WORKING TCP / HTTPS: WORKING upstream DNS: WORKING 127.0.0.53 stub: BROKEN systemd-resolved: ~100% CPU busy loop ``` --- ## Temporary workaround that confirms the diagnosis As a diagnostic workaround, I temporarily bypassed the broken `127.0.0.53` stub and pointed `/etc/resolv.conf` directly at the live DNS servers used by the Amnezia tunnel: ```text nameserver 100.64.0.1 nameserver 8.8.4.4 ``` Immediately after doing that: ```bash getent hosts cloudflare.com curl https://cloudflare.com ``` started working normally again. The public IP also correctly changed to the Amnezia VPN exit IP. So the workaround restores connectivity without touching: * routes * `ip rule` * nftables * iptables * the `amn0` interface * the VPN process It only bypasses the stuck local `systemd-resolved` stub. When Amnezia disconnects, restoring the original `/etc/resolv.conf` symlink to: ```text /run/systemd/resolve/stub-resolv.conf ``` returns the machine to the normal baseline state. --- ## Hiddify was ruled out Initially I suspected a conflict with Hiddify because both clients are installed on the same machine. I tested this explicitly. Hiddify creates: ```text tun0 routing table 2022 ip rules around priorities 9000-9010 ``` while connected. After disconnecting Hiddify: * `tun0` disappears * table `2022` disappears * all Hiddify `ip rule` entries disappear * `sing-box` exits * `/etc/resolv.conf` remains unchanged * no stale routing or DNS state remains I repeated this multiple times. More importantly, the Amnezia DNS failure also occurs from a clean baseline where Hiddify was never connected. So at least in my case, this is not caused by stale state from another VPN client. --- ## Full reproduction A simplified reproduction sequence is: 1. Boot / clean network state. 2. Confirm normal Internet and DNS work. 3. Start AmneziaVPN 5.0.1.5. 4. Connect using AWG. 5. Confirm `amn0` exists and full-tunnel routes are present. 6. Observe `systemd-resolved` at ~100% CPU. 7. Observe DNS queries through `127.0.0.53` fail. 8. Observe Amnezia `DnsUtilsLinux` DBus errors. 9. Confirm direct-IP traffic through the VPN still succeeds. 10. Bypass `127.0.0.53` and use the tunnel DNS servers directly. 11. DNS and browser traffic immediately start working. No reboot is required to reproduce this. --- ## My current workaround For my system I implemented a small temporary keep-alive workaround: * when `amn0` appears, `/etc/resolv.conf` is temporarily pointed at the DNS servers reported for the live tunnel; * when `amn0` disappears, the original `/etc/resolv.conf` is restored byte-for-byte; * no firewall, routing, policy-routing, or VPN state is modified. This makes Amnezia usable, but I consider this only a workaround, not an appropriate upstream fix. --- ## Possible area to investigate I think it would be useful to inspect the Linux DNS lifecycle around `DnsUtilsLinux`, especially: * why Amnezia needs to restart `systemd-resolved`; * whether the restart is required at all; * whether DNS configuration can be done only through `org.freedesktop.resolve1`; * what state is programmed immediately before/after the restart; * whether Amnezia waits for `systemd-resolved` to become fully usable after restart; * whether repeated DBus DNS operations can trigger this pathological `sd_event` behavior on systemd 255; * whether the interaction with the `~.` routing domain is relevant. I would be cautious about fixing this with only a sleep or retry loop, because in my reproduction `systemd-resolved` is not merely slow to start — it remains permanently stuck at ~100% CPU until Amnezia is disconnected / the state changes. --- ## Summary On my Ubuntu 24.04 system, the failure is reproducibly: ```text Amnezia connects → amn0 and routing are correct → Amnezia restarts/configures systemd-resolved → systemd-resolved enters persistent ~100% CPU sd_event loop → 127.0.0.53 stops answering → all normal DNS-based Internet access fails → tunnel itself remains healthy ``` Directly bypassing the local stub and using the tunnel's DNS servers restores connectivity immediately. If useful, I can provide additional `strace`, `gdb`, `resolvectl`, route/rule, and Amnezia log output from the failing state.
Author
Owner

@garry0garry commented on GitHub (Aug 26, 2026):

I can confirm the same failure on Ubuntu 24.04 with systemd 255.4-1ubuntu8.17, kernel 7.0.0-30-generic, AmneziaVPN 5.0.0.5, and AWG.

In our case, amn0 was created and the tunnel remained up, but after Amnezia restarted systemd-resolved, the resolver became unresponsive: busctl, resolvectl, and normal DNS queries timed out.

As a diagnostic workaround, we added a PATH wrapper only to AmneziaVPN.service that turns exactly systemctl restart systemd-resolved into a no-op. All other systemctl calls remain unchanged. Since suppressing this restart, DNS has remained stable without changing /etc/resolv.conf, routes, or the VPN configuration.

This suggests that the systemd-resolved restart itself should be removed from the Linux DNS lifecycle, rather than handled only with a delay or retry after restarting it.

<!-- gh-comment-id:5427034389 --> @garry0garry commented on GitHub (Aug 26, 2026): I can confirm the same failure on Ubuntu 24.04 with systemd 255.4-1ubuntu8.17, kernel 7.0.0-30-generic, AmneziaVPN 5.0.0.5, and AWG. In our case, amn0 was created and the tunnel remained up, but after Amnezia restarted systemd-resolved, the resolver became unresponsive: busctl, resolvectl, and normal DNS queries timed out. As a diagnostic workaround, we added a PATH wrapper only to AmneziaVPN.service that turns exactly `systemctl restart systemd-resolved` into a no-op. All other systemctl calls remain unchanged. Since suppressing this restart, DNS has remained stable without changing /etc/resolv.conf, routes, or the VPN configuration. This suggests that the systemd-resolved restart itself should be removed from the Linux DNS lifecycle, rather than handled only with a delay or retry after restarting it.
Author
Owner

@madpower2000 commented on GitHub (Sep 3, 2026):

Still reproducible on AmneziaVPN 5.0.2.0.

I tested this on 2026-09-03 with the local DNS workaround completely stopped, using 5 consecutive connect/disconnect cycles. The failure reproduced 5/5 times.

Environment

  • Ubuntu 24.04.4 LTS
  • Kernel 7.0.0-30-generic
  • systemd 255 (255.4-1ubuntu8.17)
  • AmneziaVPN 5.0.2.0 Linux x64
  • Protocol: AmneziaWG / AWG
  • Interface: amn0

The installed version was verified from both /opt/AmneziaVPN/components.xml and the application binary.

Reproduction

On every connect:

  1. amn0 comes up normally and the AWG data plane is healthy.
  2. AmneziaVPN-service logs:
DnsUtilsLinux created.
Restarting systemd-resolved.service
Flush dns completed

Immediately afterwards it logs:

DnsUtilsLinux : Error retrieving the DNS domains from the DBus service
DnsUtilsLinux : Error received from the DBus service
DnsUtilsLinux : Error received from the DBus service
  1. The restarted systemd-resolved process enters a persistent ~97–99% CPU busy loop.

  2. The local 127.0.0.53 stub stops responding.

For example:

resolvectl status
→ Failed to get global data: Connection timed out

and:

getent hosts cloudflare.com
→ fails

resolvectl query cloudflare.com
→ times out

curl https://cloudflare.com
→ DNS resolution timeout

The VPN tunnel itself is still healthy

This is specifically a DNS-path failure, not a tunnel/routing failure.

While hostname resolution is completely broken:

curl https://1.1.1.1/

returns HTTP 301.

And:

curl --resolve cloudflare.com:443:104.16.133.229 https://cloudflare.com

also returns HTTP 301.

So TCP/HTTPS through the Amnezia tunnel continues to work while the local resolver is dead.

systemd-resolved busy loop

I captured the spinning systemd-resolved process with strace.

A representative loop is:

epoll_wait(...)
read(timerfd, ...)
timerfd_settime(..., TFD_TIMER_ABSTIME,
                { it_value={0,1} }, ...)

A 5-second sample contained approximately:

149k timerfd_settime calls
149k read calls
149k epoll_wait calls

That is roughly 30k loop iterations/sec, or about 90k syscalls/sec across those three core calls.

Because TFD_TIMER_ABSTIME is used, the {0,1ns} absolute expiration is effectively already in the past, so the timer becomes immediately readable again and the process spins continuously.

Disconnect behavior

The problem also affects disconnect.

On every disconnect Amnezia again logs:

Restarting systemd-resolved.service
Flush dns completed
DnsUtilsLinux : Error received from the DBus service

After amn0 is removed, the restarted systemd-resolved process can remain at ~99% CPU for another 1–2 minutes before eventually settling back to normal.

During that period DNS may remain unavailable even though the VPN has already been disconnected.

DNS configuration

Amnezia attempts to push:

100.64.0.1
8.8.4.4

to amn0, as visible in the service log:

Adding DNS resolver 100.64.0.1 via amn0
Adding DNS resolver 8.8.4.4 via amn0

The upstream DNS servers themselves work correctly when bypassing the broken local stub.

Comparison with 5.0.1.5

The behavior on 5.0.2.0 is effectively unchanged from 5.0.1.5:

  • systemd-resolved ~100% CPU after Amnezia connection
  • 127.0.0.53 stops answering
  • DnsUtilsLinux DBus errors
  • tunnel/data plane remains functional
  • systemd-resolved is still restarted by Amnezia
  • failure reproduced on every connection tested

The same restart → systemd-resolved failure → DBus failure → dead local DNS sequence is therefore still present in 5.0.2.0.

Workaround confirmation

As a control test, I re-enabled my local workaround which bypasses 127.0.0.53 while amn0 exists and points /etc/resolv.conf directly to the tunnel DNS servers.

With that workaround active:

systemd-resolved: still ~99% CPU
DNS via direct tunnel resolvers: works
curl https://cloudflare.com: 301
public IP: Amnezia VPN exit

So the workaround restores connectivity without fixing the underlying systemd-resolved problem.

Suggested area to investigate

The Linux client still appears to restart systemd-resolved as part of DNS handling.

I would strongly suggest investigating whether the client needs to restart systemd-resolved at all.

Ideally DNS configuration should be performed through org.freedesktop.resolve1 (SetLinkDNS, SetLinkDomains, RevertLink, etc.) without restarting the resolver daemon.

If a restart is unavoidable, the client should at least verify that org.freedesktop.resolve1 is healthy and responsive before issuing subsequent DBus calls.

However, this does not appear to be only a short DBus initialization delay: in this reproduction the new systemd-resolved process itself enters a persistent CPU busy loop and stops servicing the local DNS stub.

<!-- gh-comment-id:5527468561 --> @madpower2000 commented on GitHub (Sep 3, 2026): Still reproducible on **AmneziaVPN 5.0.2.0**. I tested this on **2026-09-03** with the local DNS workaround completely stopped, using **5 consecutive connect/disconnect cycles**. The failure reproduced **5/5 times**. ### Environment * Ubuntu 24.04.4 LTS * Kernel `7.0.0-30-generic` * systemd `255` (`255.4-1ubuntu8.17`) * AmneziaVPN `5.0.2.0` Linux x64 * Protocol: AmneziaWG / AWG * Interface: `amn0` The installed version was verified from both `/opt/AmneziaVPN/components.xml` and the application binary. ### Reproduction On every connect: 1. `amn0` comes up normally and the AWG data plane is healthy. 2. `AmneziaVPN-service` logs: ```text DnsUtilsLinux created. Restarting systemd-resolved.service Flush dns completed ``` Immediately afterwards it logs: ```text DnsUtilsLinux : Error retrieving the DNS domains from the DBus service DnsUtilsLinux : Error received from the DBus service DnsUtilsLinux : Error received from the DBus service ``` 3. The restarted `systemd-resolved` process enters a persistent ~97–99% CPU busy loop. 4. The local `127.0.0.53` stub stops responding. For example: ```text resolvectl status → Failed to get global data: Connection timed out ``` and: ```text getent hosts cloudflare.com → fails resolvectl query cloudflare.com → times out curl https://cloudflare.com → DNS resolution timeout ``` ### The VPN tunnel itself is still healthy This is specifically a DNS-path failure, not a tunnel/routing failure. While hostname resolution is completely broken: ```bash curl https://1.1.1.1/ ``` returns HTTP `301`. And: ```bash curl --resolve cloudflare.com:443:104.16.133.229 https://cloudflare.com ``` also returns HTTP `301`. So TCP/HTTPS through the Amnezia tunnel continues to work while the local resolver is dead. ### systemd-resolved busy loop I captured the spinning `systemd-resolved` process with `strace`. A representative loop is: ```text epoll_wait(...) read(timerfd, ...) timerfd_settime(..., TFD_TIMER_ABSTIME, { it_value={0,1} }, ...) ``` A 5-second sample contained approximately: ```text 149k timerfd_settime calls 149k read calls 149k epoll_wait calls ``` That is roughly **30k loop iterations/sec**, or about **90k syscalls/sec** across those three core calls. Because `TFD_TIMER_ABSTIME` is used, the `{0,1ns}` absolute expiration is effectively already in the past, so the timer becomes immediately readable again and the process spins continuously. ### Disconnect behavior The problem also affects disconnect. On every disconnect Amnezia again logs: ```text Restarting systemd-resolved.service Flush dns completed DnsUtilsLinux : Error received from the DBus service ``` After `amn0` is removed, the restarted `systemd-resolved` process can remain at ~99% CPU for another **1–2 minutes** before eventually settling back to normal. During that period DNS may remain unavailable even though the VPN has already been disconnected. ### DNS configuration Amnezia attempts to push: ```text 100.64.0.1 8.8.4.4 ``` to `amn0`, as visible in the service log: ```text Adding DNS resolver 100.64.0.1 via amn0 Adding DNS resolver 8.8.4.4 via amn0 ``` The upstream DNS servers themselves work correctly when bypassing the broken local stub. ### Comparison with 5.0.1.5 The behavior on 5.0.2.0 is effectively unchanged from 5.0.1.5: * `systemd-resolved` ~100% CPU after Amnezia connection * `127.0.0.53` stops answering * `DnsUtilsLinux` DBus errors * tunnel/data plane remains functional * `systemd-resolved` is still restarted by Amnezia * failure reproduced on every connection tested The same **restart → systemd-resolved failure → DBus failure → dead local DNS** sequence is therefore still present in 5.0.2.0. ### Workaround confirmation As a control test, I re-enabled my local workaround which bypasses `127.0.0.53` while `amn0` exists and points `/etc/resolv.conf` directly to the tunnel DNS servers. With that workaround active: ```text systemd-resolved: still ~99% CPU DNS via direct tunnel resolvers: works curl https://cloudflare.com: 301 public IP: Amnezia VPN exit ``` So the workaround restores connectivity without fixing the underlying `systemd-resolved` problem. ### Suggested area to investigate The Linux client still appears to restart `systemd-resolved` as part of DNS handling. I would strongly suggest investigating whether the client needs to restart `systemd-resolved` at all. Ideally DNS configuration should be performed through `org.freedesktop.resolve1` (`SetLinkDNS`, `SetLinkDomains`, `RevertLink`, etc.) without restarting the resolver daemon. If a restart is unavoidable, the client should at least verify that `org.freedesktop.resolve1` is healthy and responsive before issuing subsequent DBus calls. However, this does not appear to be only a short DBus initialization delay: in this reproduction the new `systemd-resolved` process itself enters a persistent CPU busy loop and stops servicing the local DNS stub.
Author
Owner

@HeisLuka commented on GitHub (Sep 9, 2026):

I traced this through the current dev source. The race is real, but there appears to be an even more fundamental lifecycle problem than simply "we restart resolved and configure DNS too early".

Current ordering

During Daemon::activate() the WireGuard/AWG path calls:

if (!maybeUpdateResolvers(config)) {
    return false;
}

before activation completes.

On Linux, maybeUpdateResolvers() reaches DnsUtilsLinux::updateResolvers(), which schedules:

  • SetLinkDNS
  • SetLinkDefaultRoute
  • Get(Domains) followed by SetLinkDomains

against org.freedesktop.resolve1.

However, DnsUtilsLinux::updateResolvers() returns true immediately after scheduling those asynchronous calls:

setLinkDNS(m_ifindex, resolvers);
setLinkDefaultRoute(m_ifindex, true);
updateLinkDomains();
return true;

Actual D-Bus failures are handled later only by logging:

if (reply.isError()) {
    logger.error() << "Error received from the DBus service";
}

so resolver configuration failure does not fail activation.

Then, after the VPN reaches Connected, VpnConnection::onConnectionStateChanged() calls flushDns() through the service.

On Linux RouterLinux::flushDns() currently does:

p.start("systemctl", { "restart", "systemd-resolved" });
p.waitForFinished();
...
return true;

So the current sequence is effectively:

configure per-link DNS through resolved
        ↓
VPN becomes Connected
        ↓
flushDns()
        ↓
restart systemd-resolved

That means systemd-resolved can be restarted after the per-link DNS state has already been configured.

Even if all of the original SetLink* calls succeeded, restarting the service can invalidate the transient resolver state that was just installed.

And if a D-Bus call happens while resolved is unavailable/restarting, it can fail asynchronously while the VPN activation path has already considered DNS setup successful.

Suggested first fix: do not restart systemd-resolved to flush its cache

systemd-resolved already exposes the native:

org.freedesktop.resolve1.Manager.FlushCaches()

D-Bus method.

So for the systemd-resolved branch, RouterLinux::flushDns() should use FlushCaches() rather than:

systemctl restart systemd-resolved

A CLI equivalent would be:

resolvectl flush-caches

but since DnsUtilsLinux already owns a D-Bus interface to org.freedesktop.resolve1, using the D-Bus API directly seems cleaner.

Conceptually:

bool DnsUtilsLinux::flushCaches()
{
    QDBusReply<void> reply =
        m_resolver->call(QStringLiteral("FlushCaches"));

    if (!reply.isValid()) {
        logger.error() << "Failed to flush resolved cache:"
                       << reply.error().message();
        return false;
    }

    return true;
}

and then the Linux router/service layer can delegate to that instead of restarting the daemon.

The existing nscd branch can remain separate if restarting nscd is actually required there.

A readiness wait alone is not sufficient

Adding something like:

wait until org.freedesktop.resolve1 appears

after systemctl restart would fix only one half of the problem.

It would make the restarted service ready, but it would not restore per-link DNS state that was configured before the restart.

So I would avoid the restart entirely rather than adding a sleep/poll after it.

Second fix: make resolver configuration observable

DnsUtilsLinux::updateResolvers() currently has fire-and-forget semantics.

A stronger invariant would be:

resolved ready
    ↓
SetLinkDNS
SetLinkDefaultRoute
SetLinkDomains
    ↓
observe successful replies
    ↓
DNS configuration considered successful
    ↓
connection may complete

This could be implemented either with bounded synchronous D-Bus calls or a small async completion barrier/state machine.

The important part is that a D-Bus error should propagate back to activation rather than only producing:

Error received from the DBus service

after activation has already succeeded.

If org.freedesktop.resolve1 is temporarily unavailable, a bounded readiness/retry step before applying the resolver state also makes sense.

There is also an error-reporting problem in flushDns()

RouterLinux::flushDns() currently does not use the result of waitForFinished() or the systemctl exit status to determine its return value.

It eventually returns:

return true;

even if restart did not complete successfully.

So today "Flush dns completed" / true does not really establish the postcondition "DNS service is usable".

Regression coverage

I would test the behavior by state/postcondition instead of adding timing sleeps:

  1. Connect WG/AWG on a system using systemd-resolved.
  2. Verify the Connected path does not restart systemd-resolved.service.
  3. Verify DNS configured on amn0 survives the cache-flush path.
  4. Inject a SetLinkDNS D-Bus failure and verify DNS configuration/activation does not silently report success.
  5. Temporarily make org.freedesktop.resolve1 unavailable and verify bounded readiness/retry behavior.
  6. Repeated connect/disconnect/split-tunnel transitions must not generate repeated systemd-resolved restarts.

This may also explain or share a root cause with #2869, where repeated transitions eventually cause:

systemd-resolved.service: Start request repeated too quickly
systemd-resolved.service: Failed with result 'start-limit-hit'

because the current implementation turns a logical DNS cache flush into a full service restart.

So I think the narrowest safe first change is:

replace the systemd-resolved restart in Linux flushDns() with org.freedesktop.resolve1.Manager.FlushCaches(), then separately make the SetLink* configuration path observable instead of fire-and-forget.

<!-- gh-comment-id:5607326432 --> @HeisLuka commented on GitHub (Sep 9, 2026): I traced this through the current `dev` source. The race is real, but there appears to be an even more fundamental lifecycle problem than simply "we restart resolved and configure DNS too early". ### Current ordering During `Daemon::activate()` the WireGuard/AWG path calls: ```cpp if (!maybeUpdateResolvers(config)) { return false; } ``` before activation completes. On Linux, `maybeUpdateResolvers()` reaches `DnsUtilsLinux::updateResolvers()`, which schedules: * `SetLinkDNS` * `SetLinkDefaultRoute` * `Get(Domains)` followed by `SetLinkDomains` against `org.freedesktop.resolve1`. However, `DnsUtilsLinux::updateResolvers()` returns `true` immediately after scheduling those asynchronous calls: ```cpp setLinkDNS(m_ifindex, resolvers); setLinkDefaultRoute(m_ifindex, true); updateLinkDomains(); return true; ``` Actual D-Bus failures are handled later only by logging: ```cpp if (reply.isError()) { logger.error() << "Error received from the DBus service"; } ``` so resolver configuration failure does not fail activation. Then, after the VPN reaches `Connected`, `VpnConnection::onConnectionStateChanged()` calls `flushDns()` through the service. On Linux `RouterLinux::flushDns()` currently does: ```cpp p.start("systemctl", { "restart", "systemd-resolved" }); p.waitForFinished(); ... return true; ``` So the current sequence is effectively: ```text configure per-link DNS through resolved ↓ VPN becomes Connected ↓ flushDns() ↓ restart systemd-resolved ``` That means `systemd-resolved` can be restarted **after the per-link DNS state has already been configured**. Even if all of the original `SetLink*` calls succeeded, restarting the service can invalidate the transient resolver state that was just installed. And if a D-Bus call happens while resolved is unavailable/restarting, it can fail asynchronously while the VPN activation path has already considered DNS setup successful. ### Suggested first fix: do not restart systemd-resolved to flush its cache `systemd-resolved` already exposes the native: ```text org.freedesktop.resolve1.Manager.FlushCaches() ``` D-Bus method. So for the `systemd-resolved` branch, `RouterLinux::flushDns()` should use `FlushCaches()` rather than: ```text systemctl restart systemd-resolved ``` A CLI equivalent would be: ```text resolvectl flush-caches ``` but since `DnsUtilsLinux` already owns a D-Bus interface to `org.freedesktop.resolve1`, using the D-Bus API directly seems cleaner. Conceptually: ```cpp bool DnsUtilsLinux::flushCaches() { QDBusReply<void> reply = m_resolver->call(QStringLiteral("FlushCaches")); if (!reply.isValid()) { logger.error() << "Failed to flush resolved cache:" << reply.error().message(); return false; } return true; } ``` and then the Linux router/service layer can delegate to that instead of restarting the daemon. The existing `nscd` branch can remain separate if restarting nscd is actually required there. ### A readiness wait alone is not sufficient Adding something like: ```text wait until org.freedesktop.resolve1 appears ``` after `systemctl restart` would fix only one half of the problem. It would make the restarted service ready, but it would not restore per-link DNS state that was configured **before** the restart. So I would avoid the restart entirely rather than adding a sleep/poll after it. ### Second fix: make resolver configuration observable `DnsUtilsLinux::updateResolvers()` currently has fire-and-forget semantics. A stronger invariant would be: ```text resolved ready ↓ SetLinkDNS SetLinkDefaultRoute SetLinkDomains ↓ observe successful replies ↓ DNS configuration considered successful ↓ connection may complete ``` This could be implemented either with bounded synchronous D-Bus calls or a small async completion barrier/state machine. The important part is that a D-Bus error should propagate back to activation rather than only producing: ```text Error received from the DBus service ``` after activation has already succeeded. If `org.freedesktop.resolve1` is temporarily unavailable, a bounded readiness/retry step before applying the resolver state also makes sense. ### There is also an error-reporting problem in `flushDns()` `RouterLinux::flushDns()` currently does not use the result of `waitForFinished()` or the `systemctl` exit status to determine its return value. It eventually returns: ```cpp return true; ``` even if restart did not complete successfully. So today `"Flush dns completed"` / `true` does not really establish the postcondition "DNS service is usable". ### Regression coverage I would test the behavior by state/postcondition instead of adding timing sleeps: 1. Connect WG/AWG on a system using `systemd-resolved`. 2. Verify the Connected path does **not** restart `systemd-resolved.service`. 3. Verify DNS configured on `amn0` survives the cache-flush path. 4. Inject a `SetLinkDNS` D-Bus failure and verify DNS configuration/activation does not silently report success. 5. Temporarily make `org.freedesktop.resolve1` unavailable and verify bounded readiness/retry behavior. 6. Repeated connect/disconnect/split-tunnel transitions must not generate repeated `systemd-resolved` restarts. This may also explain or share a root cause with #2869, where repeated transitions eventually cause: ```text systemd-resolved.service: Start request repeated too quickly systemd-resolved.service: Failed with result 'start-limit-hit' ``` because the current implementation turns a logical DNS cache flush into a full service restart. So I think the narrowest safe first change is: **replace the `systemd-resolved` restart in Linux `flushDns()` with `org.freedesktop.resolve1.Manager.FlushCaches()`**, then separately make the `SetLink*` configuration path observable instead of fire-and-forget.
Author
Owner

@HeisLuka commented on GitHub (Sep 9, 2026):

I rechecked this against current dev, and the failure mode is still present.

There is one important clarification to the original root-cause description:

the current code does not only risk configuring DNS too soon after restarting systemd-resolved; it can configure the VPN link first and then restart systemd-resolved afterwards.

That makes the lifecycle problem even more direct.

Current activation ordering

For WireGuard / AmneziaWG, Daemon::activate() currently reaches:

create/configure interface
-> configure peer
-> maybeUpdateResolvers()
-> install routes
-> bring connection Up

maybeUpdateResolvers() calls:

dnsutils()->updateResolvers(
    wgutils()->interfaceName(),
    resolvers);

On Linux, DnsUtilsLinux::updateResolvers() does:

setLinkDNS(m_ifindex, resolvers);
setLinkDefaultRoute(m_ifindex, true);
updateLinkDomains();
return true;

However, all of those resolver operations are asynchronous D-Bus operations.

For example, SetLinkDNS is sent through:

m_resolver->asyncCallWithArgumentList(
    QStringLiteral("SetLinkDNS"),
    argumentList);

and completion is handled later by dnsCallCompleted().

If D-Bus returns an error, the current handler only does:

logger.error()
    << "Error received from the DBus service";

There is no propagation back to the activation transaction.

So currently:

D-Bus request queued
        ↓
updateResolvers() returns true
        ↓
VPN activation continues

does not mean:

DNS configuration was actually accepted

Then Connected restarts the resolver

When the desktop client receives:

ConnectionState::Connected

VpnConnection::onConnectionStateChanged() immediately calls:

iface->flushDns();

On Linux that eventually reaches RouterLinux::flushDns().

For a system using systemd-resolved, the current implementation is:

p.start(
    "systemctl",
    { "restart", "systemd-resolved" });
p.waitForFinished();
...
return true;

So the effective lifecycle can be:

SetLinkDNS(amn0)
SetLinkDefaultRoute(amn0)
SetLinkDomains(amn0)
        ↓
VPN reaches Connected
        ↓
flushDns()
        ↓
systemctl restart systemd-resolved

This means even successfully applied transient per-link state can be destroyed immediately after activation.

And if the asynchronous D-Bus operations are still in flight when the restart starts, they can fail against the disappearing/restarting resolver service.

That directly matches the log sequence reported here:

Restarting systemd-resolved.service
Flush dns completed
Error retrieving the DNS domains from the DBus service
Error received from the DBus service

flushDns() also does not verify success correctly

There is another smaller problem in the same function.

The return value from:

p.waitForFinished();

is ignored.

The process exit status is also not checked.

The implementation logs:

Flush dns completed

when stdout/stderr is empty and then returns:

true

regardless of whether restarting the resolver actually produced the intended postcondition.

So:

flushDns() == true

currently does not establish:

systemd-resolved ready
AND
VPN DNS configuration intact

Restarting systemd-resolved is unnecessary for cache flushing

systemd-resolved already exposes a dedicated D-Bus method:

org.freedesktop.resolve1.Manager.FlushCaches()

and the corresponding command is:

resolvectl flush-caches

The systemd documentation also explicitly describes using:

SetLinkDNS()
SetLinkDomains()
SetLinkDefaultRoute()

for VPN per-link DNS configuration.

So the narrow fix does not need a sleep around systemctl restart.

I think the stronger fix is:

do not restart systemd-resolved at all

for a DNS cache flush.

For example:

resolver ready
        ↓
SetLinkDNS
SetLinkDomains
SetLinkDefaultRoute
        ↓
observe successful D-Bus replies
        ↓
optional FlushCaches()
        ↓
DNS_READY
        ↓
Connected

Why adding a delay alone is insufficient

A workaround such as:

restart systemd-resolved
sleep(1)
configure amn0

could reduce the D-Bus readiness race.

But it keeps an unnecessary destructive lifecycle operation in the connection path.

More importantly, simply waiting after the current restart would not solve the ordering where the VPN DNS state was already configured before the restart.

The invariant should instead be:

once VPN per-link DNS has been committed,
nothing in the Connected path destroys
the resolver instance that owns that state

Suggested implementation direction

  1. For systemd-resolved, replace:
systemctl restart systemd-resolved

with:

org.freedesktop.resolve1.Manager.FlushCaches()

or resolvectl flush-caches.

  1. Keep the existing restart behavior for nscd separate if it is genuinely required there.

  2. Make DnsUtilsLinux::updateResolvers() observable rather than fire-and-forget:

    • wait for or aggregate the relevant D-Bus replies;
    • use a bounded timeout;
    • propagate failures to activation.
  3. If org.freedesktop.resolve1 is temporarily unavailable, use bounded readiness/retry rather than declaring resolver configuration successful.

  4. Do not declare the connection fully healthy until the DNS configuration postcondition is known.

Regression cases

  1. Connect AWG/WG on a systemd-resolved host:

    • systemd-resolved.service PID does not change because of DNS cache flush.
  2. After Connected:

resolvectl status amn0

still shows the expected DNS servers, routing domain and default-route state.

  1. Inject SetLinkDNS D-Bus failure:

    • VPN activation must not silently treat resolver configuration as successful.
  2. Temporarily make org.freedesktop.resolve1 unavailable:

    • bounded retry succeeds when the service appears;
    • deterministic failure occurs after timeout.
  3. Repeated connect/disconnect/reconnect:

    • no burst of systemd-resolved service restarts.
  4. Cache flushing:

    • caches are cleared without destroying per-link VPN DNS state.
  5. Split-tunnel transitions:

    • per-link DNS state remains deterministic across repeated changes.

This may also explain part of #2869, where repeated split-tunnel activity can drive systemd-resolved into start-limit-hit: the current implementation turns a logical DNS-cache flush into a service restart.

So I think the core issue is source-confirmed in current dev:

cache invalidation is implemented as destruction of the resolver service that owns the per-link DNS state, while the DNS actuation itself is asynchronous and has no success barrier.

<!-- gh-comment-id:5608404657 --> @HeisLuka commented on GitHub (Sep 9, 2026): I rechecked this against current `dev`, and the failure mode is still present. There is one important clarification to the original root-cause description: **the current code does not only risk configuring DNS too soon after restarting `systemd-resolved`; it can configure the VPN link first and then restart `systemd-resolved` afterwards.** That makes the lifecycle problem even more direct. ### Current activation ordering For WireGuard / AmneziaWG, `Daemon::activate()` currently reaches: ```text create/configure interface -> configure peer -> maybeUpdateResolvers() -> install routes -> bring connection Up ``` `maybeUpdateResolvers()` calls: ```cpp dnsutils()->updateResolvers( wgutils()->interfaceName(), resolvers); ``` On Linux, `DnsUtilsLinux::updateResolvers()` does: ```cpp setLinkDNS(m_ifindex, resolvers); setLinkDefaultRoute(m_ifindex, true); updateLinkDomains(); return true; ``` However, all of those resolver operations are asynchronous D-Bus operations. For example, `SetLinkDNS` is sent through: ```cpp m_resolver->asyncCallWithArgumentList( QStringLiteral("SetLinkDNS"), argumentList); ``` and completion is handled later by `dnsCallCompleted()`. If D-Bus returns an error, the current handler only does: ```cpp logger.error() << "Error received from the DBus service"; ``` There is no propagation back to the activation transaction. So currently: ```text D-Bus request queued ↓ updateResolvers() returns true ↓ VPN activation continues ``` does not mean: ```text DNS configuration was actually accepted ``` ### Then `Connected` restarts the resolver When the desktop client receives: ```text ConnectionState::Connected ``` `VpnConnection::onConnectionStateChanged()` immediately calls: ```cpp iface->flushDns(); ``` On Linux that eventually reaches `RouterLinux::flushDns()`. For a system using `systemd-resolved`, the current implementation is: ```cpp p.start( "systemctl", { "restart", "systemd-resolved" }); p.waitForFinished(); ... return true; ``` So the effective lifecycle can be: ```text SetLinkDNS(amn0) SetLinkDefaultRoute(amn0) SetLinkDomains(amn0) ↓ VPN reaches Connected ↓ flushDns() ↓ systemctl restart systemd-resolved ``` This means even successfully applied transient per-link state can be destroyed immediately after activation. And if the asynchronous D-Bus operations are still in flight when the restart starts, they can fail against the disappearing/restarting resolver service. That directly matches the log sequence reported here: ```text Restarting systemd-resolved.service Flush dns completed Error retrieving the DNS domains from the DBus service Error received from the DBus service ``` ### `flushDns()` also does not verify success correctly There is another smaller problem in the same function. The return value from: ```cpp p.waitForFinished(); ``` is ignored. The process exit status is also not checked. The implementation logs: ```text Flush dns completed ``` when stdout/stderr is empty and then returns: ```cpp true ``` regardless of whether restarting the resolver actually produced the intended postcondition. So: ```text flushDns() == true ``` currently does not establish: ```text systemd-resolved ready AND VPN DNS configuration intact ``` ### Restarting `systemd-resolved` is unnecessary for cache flushing `systemd-resolved` already exposes a dedicated D-Bus method: ```text org.freedesktop.resolve1.Manager.FlushCaches() ``` and the corresponding command is: ```text resolvectl flush-caches ``` The systemd documentation also explicitly describes using: ```text SetLinkDNS() SetLinkDomains() SetLinkDefaultRoute() ``` for VPN per-link DNS configuration. So the narrow fix does not need a sleep around `systemctl restart`. I think the stronger fix is: ```text do not restart systemd-resolved at all ``` for a DNS cache flush. For example: ```text resolver ready ↓ SetLinkDNS SetLinkDomains SetLinkDefaultRoute ↓ observe successful D-Bus replies ↓ optional FlushCaches() ↓ DNS_READY ↓ Connected ``` ### Why adding a delay alone is insufficient A workaround such as: ```text restart systemd-resolved sleep(1) configure amn0 ``` could reduce the D-Bus readiness race. But it keeps an unnecessary destructive lifecycle operation in the connection path. More importantly, simply waiting *after the current restart* would not solve the ordering where the VPN DNS state was already configured **before** the restart. The invariant should instead be: ```text once VPN per-link DNS has been committed, nothing in the Connected path destroys the resolver instance that owns that state ``` ### Suggested implementation direction 1. For `systemd-resolved`, replace: ```text systemctl restart systemd-resolved ``` with: ```text org.freedesktop.resolve1.Manager.FlushCaches() ``` or `resolvectl flush-caches`. 2. Keep the existing restart behavior for `nscd` separate if it is genuinely required there. 3. Make `DnsUtilsLinux::updateResolvers()` observable rather than fire-and-forget: * wait for or aggregate the relevant D-Bus replies; * use a bounded timeout; * propagate failures to activation. 4. If `org.freedesktop.resolve1` is temporarily unavailable, use bounded readiness/retry rather than declaring resolver configuration successful. 5. Do not declare the connection fully healthy until the DNS configuration postcondition is known. ### Regression cases 1. Connect AWG/WG on a `systemd-resolved` host: * `systemd-resolved.service` PID does not change because of DNS cache flush. 2. After `Connected`: ```text resolvectl status amn0 ``` still shows the expected DNS servers, routing domain and default-route state. 3. Inject `SetLinkDNS` D-Bus failure: * VPN activation must not silently treat resolver configuration as successful. 4. Temporarily make `org.freedesktop.resolve1` unavailable: * bounded retry succeeds when the service appears; * deterministic failure occurs after timeout. 5. Repeated connect/disconnect/reconnect: * no burst of `systemd-resolved` service restarts. 6. Cache flushing: * caches are cleared without destroying per-link VPN DNS state. 7. Split-tunnel transitions: * per-link DNS state remains deterministic across repeated changes. This may also explain part of #2869, where repeated split-tunnel activity can drive `systemd-resolved` into `start-limit-hit`: the current implementation turns a logical DNS-cache flush into a service restart. So I think the core issue is source-confirmed in current `dev`: **cache invalidation is implemented as destruction of the resolver service that owns the per-link DNS state, while the DNS actuation itself is asynchronous and has no success barrier.**
Author
Owner

@Spiceman161 commented on GitHub (Oct 23, 2026):

I can confirm the same issue on Linux Mint with AmneziaVPN 5.0.3.0 (de93650, Sep 18 2026).

The VPN profile itself contains valid DNS servers:

[Interface]
Address = 172.16.18.19/32
DNS = 1.1.1.1, 8.8.8.8

During the failure:

$ timeout 5 resolvectl status
Failed to get global data: Connection timed out

$ dig +time=2 +tries=1 @127.0.0.53 www.google.com A
;; communications error to 127.0.0.53#53: timed out
;; no servers could be reached

At the same time systemd-resolved was still reported as active, but was clearly stuck:

Active: active (running) since Fri 2026-10-23 12:09:14 MSK; 11min ago
Status: "Processing requests..."
Tasks: 1
CPU: 11min 29.497s

The VPN data path itself was working correctly. Direct DNS queries through the tunnel to 8.8.8.8 succeeded over both UDP and TCP:

$ dig @8.8.8.8 www.google.com A
status: NOERROR
SERVER: 8.8.8.8#53
Query time: 65 msec

$ dig +tcp @8.8.8.8 www.google.com A
status: NOERROR
SERVER: 8.8.8.8#53
Query time: 67 msec

The journal also showed several systemd-resolved restarts within a short period:

12:08:44 systemd-resolved: Failed to send hostname reply: Transport endpoint is not connected
12:08:44 systemd: Stopping systemd-resolved.service...
12:08:44 systemd: Started systemd-resolved.service...

12:09:06 systemd: Stopping systemd-resolved.service...
12:09:06 systemd-resolved: Failed to send hostname reply: Transport endpoint is not connected
12:09:06 systemd: systemd-resolved.service: Consumed 20.544s CPU time.
12:09:06 systemd: Started systemd-resolved.service...

12:09:14 systemd: Stopping systemd-resolved.service...
12:09:14 systemd: systemd-resolved.service: Consumed 7.209s CPU time.
12:09:14 systemd: Started systemd-resolved.service...

Restarting systemd-resolved restored responsiveness, but the DNS configuration for amn0 was gone. Manually configuring DNS and the catch-all routing domain fixed name resolution immediately:

sudo systemctl restart systemd-resolved
sudo resolvectl dns amn0 8.8.8.8
sudo resolvectl domain amn0 '~.'

After that:

$ resolvectl query www.google.com
www.google.com: ... -- link: amn0
-- Information acquired via protocol DNS

After a later normal reconnect, Amnezia successfully configured the interface itself:

Link 8 (amn0)
    Current Scopes: DNS
    Protocols: +DefaultRoute ...
    Current DNS Server: 1.1.1.1
    DNS Servers: 1.1.1.1 8.8.8.8
    DNS Domain: ~.

So the issue is intermittent and appears to be related to the Linux client / systemd-resolved integration rather than the VPN profile itself.

<!-- gh-comment-id:6362163184 --> @Spiceman161 commented on GitHub (Oct 23, 2026): I can confirm the same issue on **Linux Mint with AmneziaVPN 5.0.3.0 (`de93650`, Sep 18 2026)**. The VPN profile itself contains valid DNS servers: ```ini [Interface] Address = 172.16.18.19/32 DNS = 1.1.1.1, 8.8.8.8 ``` During the failure: ```text $ timeout 5 resolvectl status Failed to get global data: Connection timed out $ dig +time=2 +tries=1 @127.0.0.53 www.google.com A ;; communications error to 127.0.0.53#53: timed out ;; no servers could be reached ``` At the same time `systemd-resolved` was still reported as active, but was clearly stuck: ```text Active: active (running) since Fri 2026-10-23 12:09:14 MSK; 11min ago Status: "Processing requests..." Tasks: 1 CPU: 11min 29.497s ``` The VPN data path itself was working correctly. Direct DNS queries through the tunnel to `8.8.8.8` succeeded over both UDP and TCP: ```text $ dig @8.8.8.8 www.google.com A status: NOERROR SERVER: 8.8.8.8#53 Query time: 65 msec $ dig +tcp @8.8.8.8 www.google.com A status: NOERROR SERVER: 8.8.8.8#53 Query time: 67 msec ``` The journal also showed several `systemd-resolved` restarts within a short period: ```text 12:08:44 systemd-resolved: Failed to send hostname reply: Transport endpoint is not connected 12:08:44 systemd: Stopping systemd-resolved.service... 12:08:44 systemd: Started systemd-resolved.service... 12:09:06 systemd: Stopping systemd-resolved.service... 12:09:06 systemd-resolved: Failed to send hostname reply: Transport endpoint is not connected 12:09:06 systemd: systemd-resolved.service: Consumed 20.544s CPU time. 12:09:06 systemd: Started systemd-resolved.service... 12:09:14 systemd: Stopping systemd-resolved.service... 12:09:14 systemd: systemd-resolved.service: Consumed 7.209s CPU time. 12:09:14 systemd: Started systemd-resolved.service... ``` Restarting `systemd-resolved` restored responsiveness, but the DNS configuration for `amn0` was gone. Manually configuring DNS and the catch-all routing domain fixed name resolution immediately: ```bash sudo systemctl restart systemd-resolved sudo resolvectl dns amn0 8.8.8.8 sudo resolvectl domain amn0 '~.' ``` After that: ```text $ resolvectl query www.google.com www.google.com: ... -- link: amn0 -- Information acquired via protocol DNS ``` After a later normal reconnect, Amnezia successfully configured the interface itself: ```text Link 8 (amn0) Current Scopes: DNS Protocols: +DefaultRoute ... Current DNS Server: 1.1.1.1 DNS Servers: 1.1.1.1 8.8.8.8 DNS Domain: ~. ``` So the issue is intermittent and appears to be related to the Linux client / `systemd-resolved` integration rather than the VPN profile itself.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amnezia-client#1166
No description provided.