FULL AI ANALYSIS

systemd-networkd restores stale IPv4 default route after VPN disconnect on Ubuntu 22.04

Generated Oct 27, 2026, 9:31:39 AM

Analysis summary

Symptoms point to a teardown timing or state reconciliation problem between OpenVPN and systemd-networkd. Most likely, OpenVPN's up/down scripts or the kernel netlink notifications aren't causing systemd-networkd to remove routes it previously configured, leaving an orphaned route entry. Other possibilities include netplan-generated static routes persisting across reconfigures, OpenVPN's use of 'route' vs 'ip route' mechanisms, or a mismatch in route metrics that makes the kernel prefer an interface that is logically down. Race conditions during service stop or lingering /run state files can also cause networkd to believe the route is still valid.

Possible causes

OpenVPN up/down route operations and systemd-networkd/netlink events race, leaving orphaned route entries that networkd doesn't clean up

75%

Netplan/systemd-networkd config contains static or DHCP-provided default route settings that reassert when networkd reconciling state, causing the tun route to be re-applied

45%

OpenVPN uses legacy 'route' commands (or external script) which don't fully remove kernel routes on SIGTERM due to ordering or permission problems

40%

systemd-networkd bug or stale runtime state under /run/systemd/netif/state that preserves previous routing info until restart

30%

Suggested fixes

1

Diagnostic step 1

Collect current state immediately after disconnect: ip route show, ip -d link show, journalctl -b -u systemd-networkd --since '5 minutes ago', and check /run/systemd/netif/state contents.

2

Diagnostic step 2

Temporarily fix without reboot: ip route del default dev <tun0> followed by systemctl reload-or-restart systemd-networkd and confirm ip route shows correct default via enp3s0.

3

Diagnostic step 3

Inspect OpenVPN client config for use of 'route' vs 'ip route' scripts and add explicit --route-noexec to let systemd-networkd manage routes, or add a clean PostDown script that uses 'ip route flush dev <tun0>' to remove any leftover default route.

4

Diagnostic step 4

Set explicit route metrics in netplan/systemd .network files so physical NIC default has lower metric (higher priority) than ephemeral tun0. Example netplan: set 'metric: 100' on enp3s0.

5

Diagnostic step 5

If issue persists, enable verbose systemd-networkd logging (SYSTEMD_LOG_LEVEL=debug) and openvpn up/down script logging to capture the sequence and escalate with collected logs to distro bug tracker if reproducible.