OpenVPN client loses DNS and routes when systemd-resolved restarts on Ubuntu 22.04
Environment
Ubuntu 22.04 desktop and server machines using OpenVPN 2.5 managed by systemd (client.service). systemd-resolved is active with /etc/resolv.conf symlinked to /run/systemd/resolve/stub-resolv.conf. OpenVPN uses the community up/down scripts update-resolv-conf to update DNS on connect.
Symptoms
OpenVPN shows as connected but DNS resolution fails (names not resolved). Some destinations are reachable by IP but others time out. After systemd-resolved restart (e.g. triggered by NetworkManager or a package update), /etc/resolv.conf reverts and the update-resolv-conf script logs errors 'could not replace /etc/resolv.conf'. OpenVPN tunnel still up but clients lose name resolution until reconnect.
Observations
Journal shows systemd-resolved restarted at times coincident with the outage. update-resolv-conf attempts to write /etc/resolv.conf which is a symlink to a runtime stub; writing fails or gets reverted by resolved when it restarts. Using 'resolvectl status' shows DNS per-link entries missing for tun0. Disabling update-resolv-conf prevents overwrite but leaves no DNS pushed into systemd-resolved.
Already attempted
Tried installing resolvconf package (conflicts with systemd-resolved). Modified update-resolv-conf to use resolvectl but changes were brittle. Added 'After=systemd-resolved.service' to OpenVPN systemd unit (improved ordering but did not prevent resolved restarts later). Tried using NetworkManager OpenVPN plugin which handles resolvectl correctly but not usable on servers.
Question
How can I make OpenVPN reliably set DNS and routes on Ubuntu 22.04 so a systemd-resolved restart doesn't break name resolution? Prefer a reversible, systemd-friendly approach.
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Linux33% match
systemd-resolved ignores per-connection DNS split-horizon rules after NetworkManager upgrade on Ubuntu 22.04
Open0 answers - Linux32% match
Ubuntu 22.04 laptop: Docker containers lose DNS resolution after suspend/resume (systemd-resolved stub resolver conflict)
Open0 answers - Virtualization30% match
Docker containers lose DNS resolution after laptop resume on Ubuntu 22.04 due to systemd-resolved stub resolver change
Open0 answers - Linux29% match
Ubuntu 22.04: Docker containers intermittently lose DNS after host switches to systemd-resolved stub resolver during network changes
Solved1 answer - Linux27% match
Ubuntu 22.04 laptop: Docker containers lose DNS after suspend/resume due to systemd-resolved stub resolver race with NetworkManager
Open1 answer