FULL AI ANALYSIS

OpenVPN client loses DNS and routes when systemd-resolved restarts on Ubuntu 22.04

Generated Oct 19, 2026, 9:33:36 AM

Analysis summary

This is a classic mismatch between legacy resolv.conf-updating scripts and systemd-resolved's stub resolver. update-resolv-conf tries to directly edit /etc/resolv.conf, but on modern Ubuntu that's a symlink to a transient file owned by systemd-resolved; whenever resolved restarts it restores its stub and drops per-link configuration applied by the script. The robust approach is to use systemd-resolved's API (resolvectl) to add DNS servers and domains for the tun0 link in OpenVPN's up/down scripts or to run OpenVPN via NetworkManager which integrates with resolved. Other causes like permission/immutable attributes on /etc/resolv.conf or improper systemd unit ordering are secondary.

Possible causes

update-resolv-conf (legacy script) overwrites /etc/resolv.conf which is managed by systemd-resolved; resolved restarts revert those changes

90%

OpenVPN systemd unit lacks proper Wants/After dependencies for systemd-resolved and network services, causing ordering/race issues

50%

NetworkManager or another process restarts frequently and overwrites resolv settings despite OpenVPN attempts to set them

30%

Permissions or immutable attribute set on /etc/resolv.conf causing script failures or inconsistent state

20%

Suggested fixes

1

Diagnostic step 1

Replace update-resolv-conf calls in your OpenVPN up/down scripts with resolvectl commands: in the 'up' script run: resolvectl dns "$dev" 1.1.1.1 1.0.0.1 and resolvectl domain "$dev" '~example.internal' ; in 'down' run resolvectl revert "$dev".

2

Diagnostic step 2

If using systemd service for OpenVPN, set unit dependencies so the service starts After=systemd-resolved.service and add Wants=systemd-resolved.service; reload daemon and restart OpenVPN.

3

Diagnostic step 3

Test by restarting systemd-resolved (sudo systemctl restart systemd-resolved) while OpenVPN is up; verify with resolvectl status and 'dig' that DNS entries for tun0 persist.

4

Diagnostic step 4

As an alternative, use NetworkManager's OpenVPN plugin (nmcli connection import) which integrates with systemd-resolved, or run a small script triggered on link-up to apply resolvectl settings.

5

Diagnostic step 5

Keep backups of original up/down scripts and undo resolvectl changes with resolvectl revert "$dev" if needed; escalate to distro maintainers only if systemd-resolved has regression.