systemd-networkd restores stale IPv4 default route after VPN disconnect on Ubuntu 22.04
Environment
Ubuntu 22.04 LTS server, systemd 249, systemd-networkd managing enp3s0 (DHCPv4), OpenVPN 2.5.5 client (tun0) started from systemd unit, netplan YAML present under /etc/netplan/01-netcfg.yaml, no NetworkManager installed.
Symptoms
After disconnecting the OpenVPN tunnel (systemctl stop openvpn-client@myvpn), the machine loses internet access. ip route shows default route via tun0 still present or a lower-priority default via tun0 in addition to physical NIC route. Connectivity restored only after systemd-networkd restart or full reboot; short wiggle like toggling link does not consistently fix.
Observations
ip route output immediately after disconnect: two default routes; the tun0 route has metric 0 and persists even though tun0 is down. journalctl -u systemd-networkd shows 'configured default route' messages referencing the tun interface long after OpenVPN stopped. /run/systemd/netif/state contains stale link info. openvpn logs show proper SIGTERM and TAP teardown; no explicit 'route delete' errors logged by OpenVPN.
Already attempted
Manually removed the stale default route with ip route del default via <vpn_gw> dev tun0 — internet restored until next VPN connect/disconnect cycle. Restarting systemd-networkd (systemctl restart systemd-networkd) clears the stale route. Tried adding 'route-noexec' and 'route-delay' in OpenVPN client config; no change. Disabled netplan and re-applied; issue recurs after next VPN disconnect.
Question
Why does systemd-networkd reapply or keep a default route for a VPN interface after the peer disconnects, and how can I prevent stale VPN routes from persisting without rebooting the host?
Verified community troubleshooting
First check whether the kernel actually keeps the orphan route: after you stop the VPN run 'ip route' and 'ip -d route show table main' — if the default via the tun interface is present, delete it with 'ip route del default dev <tun0>' and confirm connectivity. To prevent recurrence prefer letting systemd-networkd manage routes: start OpenVPN with --route-noexec (or add 'route-noexec' to client config) and implement a simple PostDown script that runs 'ip route flush dev $dev' (safe, reversible). Also set an explicit metric for the physical NIC in netplan so it remains preferred if a stale route appears. Verify fix by cycling the VPN and confirming ip route shows only the intended default; roll back by removing route-noexec or the PostDown script if it causes regressions.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Networking31% match
systemd-networkd drops IPv6 default route after netplan apply/resume on Ubuntu 22.04 — RA visible but no ::/0 route
Open1 answer - Linux29% match
OpenVPN client loses DNS and routes when systemd-resolved restarts on Ubuntu 22.04
Open0 answers - Networking23% match
OpenWrt: DHCPv6 PD present but clients intermittently lack IPv6 default route after enabling RA firewall filtering
Open1 answer - Linux21% match
NFS client mounts switch to read-only with 'stale file handle' after server cluster failover
Open0 answers - Networking21% match
Clients receive IPv6 addresses but no default route after enabling DHCPv6-only mode on OpenWrt router
Open0 answers