
VPN Stability: Keepalive & Auto-Reconnect
If Kali NetworkManager drops your connection mid-scan, the problem usually isnโt your pentesting tools. Itโs the gap between โVPN says connectedโ and โtraffic is actually taking the tunnel.โ
Tiny Wi-Fi hiccups and NAT idle timers only show up once youโve settled into the work. Keep guessing and you lose more than a sessionโyou lose momentum, results, and clean baselines for what changed.
This guide is built around evidence: journalctl, interface checks, and repeatable testsโnot UI vibes. Youโll see the failure before you โfixโ it. Then youโll fix the right thing. Then youโll lock it in.
Table of Contents
1) Symptom fingerprint first: what โmid-scan dropsโ usually means
โVPN droppedโ is the symptom. The cause is usually one of three patternsโand each pattern wants a different fix. The trick is to stop guessing and start classifying.
Quick tells in 30 seconds (GUI lies, logs donโt)
- NetworkManager still says โConnectedโ but targets stop responding โ often route/DNS flip, not a dead tunnel.
- VPN shows โDisconnectedโ after a quiet period โ often idle timeout / keepalive missing (especially with NAT + Wi-Fi).
- Drop coincides with Wi-Fi roaming, AP switch, or laptop lid moment โ often link loss + no reliable reconnect chain.
The 3 common dropout patterns (idle timeout / Wi-Fi roam / route flip)
Pattern A: โQuiet tunnel deathโ (10โ30 minutes of silence, then disconnect). This is classic โno keepalive + NAT state expires + server/client stops hearing each other.โ
Pattern B: โWi-Fi wobbleโ (a brief network hiccup). Your base network drops for 2โ8 seconds, and the VPN never returns cleanly unless auto-reconnect is correctly set.
Pattern C: โFake connectedโ (tunnel is technically up, traffic goes somewhere else). Routes or DNS changed, so your scan is now shouting into the wrong hallway.
Open loop: why it only happens after 10โ30 minutes? Because thatโs where real networks betray you: NAT idle timers, AP roam windows, and โhelpfulโ network scripts tend to converge there.
- Keepalive prevents silent tunnel death
- Auto-reconnect recovers from link hiccups
- Route/DNS checks prevent โconnected but uselessโ states
Apply in 60 seconds: Decide which pattern youโre seeing before changing anything.

2) Who this is for / not for
For: long Nmap/enum sessions, lab VMs, hotel Wi-Fi, flaky routers
If youโre doing long enumeration (Nmap, gobuster, smbclient, enum4linux, masscan, web fuzzing) and your tunnel dies mid-session, this is for you. Itโs also for the โIโm on cafรฉ Wi-Fi and living dangerouslyโ crowd.
Not for: corporate VPN policies, locked-down managed endpoints
If youโre on a managed machine with corporate policies, custom VPN concentrators, or locked profiles, your constraints are different. You can still learn the logic here, but you may not be allowed to apply it.
If youโre not on NetworkManager (or youโre on headless), read this anyway
Even if you run OpenVPN from CLI on a headless box, the two-layer idea still applies: keepalive to prevent silent death, and reconnection logic to recover from link loss. The difference is where you configure it.
- Yes: You connect via NetworkManagerโs VPN UI or a saved NM connection
- Yes: Drops happen during long scans or after idle periods
- Yes: You want a fix that survives reboots and updates
Apply in 60 seconds: If you answered โyesโ to two or more, continueโthis is your playbook.
3) Evidence, not vibes: capture the exact failure (before you โfixโ it)
Hereโs the uncomfortable truth: the GUI is a storyteller. Logs are a historian. If you want a fix that sticks, you need the historian.
One command to watch the tunnel in real time (journalctl + NM)
On Kali (systemd-based), you can watch NetworkManager logs live while you reproduce the issueโone of those essential Kali tools that saves you from guessing:
sudo journalctl -u NetworkManager -f
If your OpenVPN plugin logs are noisy or split, you can also look for OpenVPN mentions:
sudo journalctl -u NetworkManager --since "30 min ago" | egrep -i "vpn|openvpn|tun|tap|disconnect|timeout|dhcp"
Verify the interface + routes (what should stay stable)
Before and after the drop, snapshot the three things that decide whether you can reach a TryHackMe target:
- Is the tunnel interface present? (
ip a) - Is the route pointing into the tunnel? (
ip route) - Is DNS resolving sensibly? (
resolvectl statusor checking/etc/resolv.confdepending on setup)
ip a | egrep -A2 "tun|tap"
ip route
resolvectl status 2>/dev/null || cat /etc/resolv.conf
Open loop: the single line in logs that predicts the next drop
Often youโll see a hint before the fall: keepalive timeouts, TLS renegotiation issues, route changes, or a base network disconnect event. The precise wording varies by OpenVPN version and NM plugin, but the โshapeโ is consistent: something stopped hearing something else.
Short Story: Midnight scan, the tunnel โsmilesโ and then vanishes โฆ
Itโs 12:47 AM. Your terminal is a steady drip of discoveriesโan open port here, a suspicious service banner there. Youโre not rushing; youโre finally in that calm, focused rhythm CTFs can give you. Then the output pauses. Not an error. Not a crash. Justโฆ silence. You glance at the NetworkManager icon. It still looks friendly, still says โconnected,โ like a coworker insisting they definitely sent the email.
You rerun a quick ping to the target. Nothing. You try a new scan. Nothing. Now the clock is the loudest thing in the room, and you can feel the momentum slipping away. Thatโs when you learn the most expensive lesson in labs: a โconnectedโ VPN is not the same as a working path. The fix isnโt heroicโitโs boring. Logs, keepalive, reconnect, route checks. Boring saves the night.

4) Keepalive that actually keeps alive (OpenVPN ping / ping-restart)
Keepalive is not magic. Itโs a heartbeat. And heartbeats matter most when everything seems fineโbecause thatโs when networks quietly age out state.
What keepalive does (and what it cannot do)
Keepalive does: send periodic traffic so NAT mappings and stateful firewalls donโt forget your tunnel exists. It also detects dead peers sooner.
Keepalive does not: fix Wi-Fi power saving, prevent route flips, or correct DNS chaos. Itโs one layer, not the whole sandwich.
Add keepalive safely: client config vs NM โadvancedโ fields
In pure OpenVPN config terms, youโll usually see either:
keepalive 10 60(shorthand for ping + ping-restart)- or the explicit pair:
ping 10andping-restart 60
NetworkManagerโs OpenVPN plugin supports a defined set of options, not an arbitrary OpenVPN configuration field. Check the installed pluginโs supported keepalive/ping settings and verify the effective imported profile and logs. Server-pushed ping/ping-restart values can override local client settings. Keep the original TryHackMe profile backed up and avoid duplicate/conflicting directives.
Set sane values for labs (stable, not spammy)
For TryHackMe/CTF use, you want values that are polite and effective. โEffectiveโ means frequent enough to prevent NAT idle expiry. โPoliteโ means youโre not hammering a server with unnecessary chatter.
- Common lab-friendly starting point:
keepalive 10 60 - If your network is very flaky: consider
keepalive 10 120(less restart-trigger-happy) - Avoid extremes:
ping 1is usually overkill;ping 120may be too quiet for some NATs
Micro truth: Letโs be honestโฆ your tunnel isnโt โstable,โ itโs just โquiet.โ Keepalive is how you keep quiet from turning into dead.
Show me the nerdy details
Many mid-scan drops look โrandomโ because the failure is time-based: NAT mappings can expire when thereโs no traffic; Wi-Fi roam can pause packets; and UDP tunnels can fail silently until a heartbeat detects it. Keepalive creates regular packets that keep state warm and also gives you a predictable failure window instead of a surprise collapse.
- Shorter ping = quicker detection, more chatter
- Longer ping-restart = fewer false restarts on shaky Wi-Fi
- Labs usually prefer reliability over elegance
Apply in 60 seconds: Start with keepalive 10 60, then tune only if logs prove you need to.
Mini calculator: keepalive sanity check (no guesswork)
This doesnโt โdiscoverโ your NAT timerโit just helps you pick values that arenโt accidentally self-sabotaging.
Suggested starting point will appear here.
5) VPN activation and recovery: NetworkManager + nmcli settings
If keepalive prevents silent death, auto-reconnect is what saves you from the real world: brief Wi-Fi hiccups, AP roaming, and โmy laptop decided to nap for 6 seconds.โ The goal is simple: when the base link blinks, the VPN should come back without drama.
Start the VPN when the base network activates
First, list connections and identify your VPN profile name:
nmcli connection show
VPN-profile connection.autoconnect is not implemented by NetworkManager. Instead, attach the VPN UUID to the base Wi-Fi/Ethernet profileโs connection.secondaries. Replace both placeholders; + preserves existing secondary UUIDs. This starts the VPN when the base profile activates, not a continuous VPN-drop watchdog. See NetworkManagerโs connection settings.
nmcli -f NAME,UUID,TYPE connection show
nmcli connection modify "YOUR_BASE_CONNECTION" connection.autoconnect yes
nmcli connection modify "YOUR_BASE_CONNECTION" +connection.secondaries "YOUR_VPN_UUID"
nmcli connection up uuid "YOUR_VPN_UUID"
If only the VPN drops while the base link remains active, secondaries does not guarantee restart. Inspect OpenVPNโs restart behavior and logs; reconnect manually with nmcli connection up uuid "YOUR_VPN_UUID" if necessary. Unattended retries require a separately tested mechanism and available credentials.
Tie VPN to the right base network (Wi-Fi/Ethernet) without surprises
The โit reconnects, but not when I need itโ problem often comes from a missing relationship: the VPN should start when your base network is up. In practice, the cleanest approach is to ensure your base Wi-Fi/Ethernet connection is stable and set to autoconnect, and then keep the VPN profile ready to be brought up reliably.
A practical workflow for labs:
- Base network (Wi-Fi/Ethernet): autoconnect enabled
- VPN: UUID linked through the base profileโs secondaries, plus a tested recovery procedure
- Never stack multiple managers fighting over the same tunnel
Stop โhelpfulโ behaviors: avoid random re-prompts and state drift
Unattended recovery needs credentials available through the appropriate NetworkManager secret agent or protected profile. Do not remove authentication or expose private keys to eliminate prompts. Preserve the original TryHackMe profile and test reconnection after login and reboot.
Open loop: why the GUI checkbox fails while nmcli survives updates
Because UI settings and plugin fields sometimes change names, default behaviors, or storage locations. nmcli changes the underlying connection profile directlyโso the setting remains even when the UI gets a new haircut.
Show me the nerdy details
NetworkManager stores connection profiles and applies them through its dispatcher and plugins. UI toggles can be version-specific, but the profile properties nmcli modifies are the durable โsource of truth.โ When you want repeatability, you want the source of truthโnot the checkbox.
- Use NetworkManager if you want persistent profiles + simple reconnect behavior
- Use OpenVPN CLI if you want full control and youโre comfortable scripting retries
- Donโt mix NM + CLI + random scripts on the same profile (it creates ghost bugs)
Apply in 60 seconds: Decide: โNM owns the tunnelโ or โCLI owns the tunnel.โ Then commit.
6) Hardening the path: routes, DNS, and โsplit-brainโ networking
Sometimes the tunnel is alive, but your traffic isnโt using it. Thatโs the split-brain feeling: one part of your system believes the VPN exists; another part routes around it like itโs late for a meeting.
Route priority: ensure the VPN stays the default when it should
For most TryHackMe lab VPNs, you want traffic to lab subnets to go through the tunnel. Depending on your profile, it might be full-tunnel (default route through VPN) or split-tunnel (only lab ranges through VPN). Either is fineโwhatโs not fine is unpredictability.
After connecting, check the route to your actual assigned lab target, not just the default route. Replace the placeholder below with an authorized target IP:
ip route get "YOUR_LAB_IP"
ip route | head -n 20
If you see your default route flip back and forth during a session, youโre not dealing with โVPN instability,โ youโre dealing with a route ownership dispute.
DNS handling: avoid resolution breakage that looks like a VPN drop
A very common โdropโ is actually DNS failure: the tunnel stays up, but name resolution breaks, and tools that rely on names (or API calls) fail. On systemd-resolved setups, resolvectl is your friend. On classic setups, /etc/resolv.conf tells the tale.
Check DNS state right after connect and right after the โdropโ moment:
resolvectl status 2>/dev/null || cat /etc/resolv.conf
IPv6 and DoH gotchas (when the tunnel is up but traffic leaks/bypasses)
Two silent bypass routes in modern setups:
- IPv6: if your VPN is IPv4-only but your system prefers IPv6, some traffic may go outside the tunnel.
- DNS-over-HTTPS (DoH): browsers can resolve DNS in ways that donโt match your system resolver expectations, creating confusing โit works here but not thereโ behavior.
Show me the nerdy details
Route selection is deterministic, but humans experience it as โrandomโ because multiple components may alter routes: DHCP renewals, Wi-Fi roaming events, VPN up/down scripts, and resolver updates. Your job is to reduce the number of writers touching the same state.
7) Common mistakes (the ones that waste an hour)
Everyone loses one CTF night to one of these. Consider this your refund.
Mistake #1: fixing Wi-Fi symptoms instead of VPN keepalive
If your tunnel dies after quiet periods, keepalive is the first lever. Tweaking Wi-Fi settings can help, but itโs not the correct first diagnosis for โquiet tunnel death.โ
Mistake #2: setting keepalive values that cause constant renegotiation
Overly aggressive values can make your connection twitchyโespecially on unstable Wi-Fi. If you see frequent reconnect loops, you may be forcing restarts too eagerly.
Mistake #3: โautoconnectโ without binding to the right interface
If your base connection isnโt stable or autoconnected, the VPN doesnโt have a solid floor to stand on. Fix the floor first.
Mistake #4: ignoring sleep/power management on laptops
Laptop power saving can pause your NIC just long enough to sever a tunnel. If drops correlate with screen dimming, lid movement, or idle timers, power management deserves a hard look.
Micro anecdote (scene): the most common โmystery dropโ happens right after you lean back, stop typing, and your laptop decides youโve achieved enlightenment and no longer need networking.
8) Donโt do this mid-scan: two โfixesโ that backfire
Donโt restart NetworkManager blindly (youโll nuke routes + state)
Restarting NetworkManager is the digital equivalent of turning off the buildingโs power because one desk lamp flickered. It can obliterate route state, DNS state, and your tunnelโcreating a new problem that looks like the old one.
Donโt stack multiple VPN tools (NM + openvpn CLI + scripts) at once
If NetworkManager thinks it owns the tunnel, and you also start a CLI OpenVPN process, you can end up with dueling routes, conflicting DNS, and intermittent โworks for 3 minutesโ nonsense.
Pattern interrupt: Hereโs what no one tells youโฆ stability is often โless automation,โ not more. One owner. One profile. One truth.
9) Prove it works: a repeatable stability test (no guesswork)
Donโt trust a fix because it feels good. Trust it because it survives a test.
The 10-minute torture test (controlled packet loss + reconnect)
Pick a simple, repeatable target: a known TryHackMe resource or a stable ping endpoint inside the lab. Then:
- Start your VPN
- Start a continuous watch (logs + route + a simple reachability check)
- Introduce a controlled disruption: toggle Wi-Fi off/on once, or roam networks if youโre brave
- Confirm the VPN returns and the route/DNS state returns with it
Recommended watch trio (three terminals):
# Terminal 1
sudo journalctl -u NetworkManager -f
# Terminal 2
watch -n 2 'ip route | sed -n "1,15p"'
# Terminal 3: replace with an authorized lab IP that responds to ICMP
ping -n -i 2 "YOUR_LAB_IP"
What โsuccessโ looks like (tunnel, route, DNS all consistent)
- Tunnel interface returns (tun/tap present)
- Routes are correct (lab subnets route through tunnel; default route behavior is consistent)
- DNS is consistent (resolver doesnโt flip into a broken state)
keepalive 10 60base profile: +connection.secondaries VPN_UUIDjournalctl + ip route + resolvectlIf it still drops: the three next most likely culprits
- Power saving: Wi-Fi NIC goes into a mode that breaks long-lived flows
- Credential prompts: reconnect requires interaction you donโt see
- Route ownership disputes: multiple tools rewriting routing/DNS state
FAQ
Why does TryHackMe VPN disconnect after a few minutes on Kali?
Possible causes include link loss, server/session limits, route changes, or peer timeouts. Use logs to identify the cause. An actively scanning tunnel is not necessarily idle, and a fixed elapsed time alone does not diagnose a missing keepalive.
Does ping-restart fix VPN drops during Nmap scans?
It can help with โsilent tunnel deathโ by detecting dead peers and restarting the session, but it wonโt fix route flips, DNS breakage, or Wi-Fi power saving. Think of it as a heartbeat and an early-warning system, not a full repair kit.
How do I auto-reconnect OpenVPN in NetworkManager on Kali?
Attach the VPN UUID to connection.secondaries on the base profile. This starts it with base-link activation, not every VPN-only drop. Validate both failure cases while watching NetworkManager logs.
Why does the VPN show โconnectedโ but I canโt reach target IPs?
This is the classic fake-connected state: routes or DNS changed. Check ip route and your resolver state (resolvectl status or /etc/resolv.conf) immediately after the failure. If the tunnel interface exists but routes donโt point into it, your traffic is bypassing.
Should I use the OpenVPN CLI instead of NetworkManager?
If you want maximum control and youโre comfortable scripting retries and logging, CLI can be great. If you want durable โset it onceโ profiles and easy toggling, NetworkManager is usually the smoother path. What matters most is choosing one owner and avoiding tool conflicts.
Can sleep mode or power saving kill my VPN tunnel?
Yes. Even short power-saving transitions can pause or reset networking long enough to break a tunnel. If drops correlate with idle time, screen dimming, or lid movement, power management is a prime suspect.
How do I check logs for NetworkManager VPN failures?
Use sudo journalctl -u NetworkManager -f to watch live, or query the last 30 minutes and filter for VPN keywords. This gives you a reliable timeline instead of a vague โit dropped again.โ

11) Next step: do one change, then lock it in
You donโt need a giant overhaul. You need one clean improvement, proven, then saved as your known-good baseline. Hereโs a sane order of operations that respects your time and your sanity.
Run a single nmcli audit (confirm autoconnect + keepalive present)
Audit what NetworkManager thinks your VPN profile contains:
nmcli connection show "YOUR_THM_VPN_NAME"
Look for:
- Base profile: autoconnect enabled and the correct VPN UUID listed in secondaries
- VPN settings: presence of keepalive directives (or equivalent fields)
- No interactive prompts: that would block reconnect
Export/save the working VPN profile (so you can restore fast)
When you get a stable configuration, save it like it mattersโbecause Future You will eventually break it with one well-intentioned tweak.
- Keep a copy of the original TryHackMe config you downloaded
- Keep notes of your keepalive values
- Keep your โaudit command outputโ in a text file for quick comparison
Put your โknown-goodโ test on autopilot (so future you doesnโt suffer)
When something breaks, you want a short checklist you can run in under 15 minutes:
- Reconnect VPN
- Watch
journalctlfor disconnect reasons - Verify tunnel interface
- Verify route(s)
- Verify DNS
- Your VPN profile name as shown in
nmcli connection show - Last 30 minutes of NM logs (saved once when it fails)
- One โknown-goodโ keepalive pair (e.g.,
10/60)
Apply in 60 seconds: Save one working profile snapshot and one failure log snippet today.
Conclusion (close the loop)
Logs must distinguish idle expiry, link loss, and route changes. Keepalive can detect an unresponsive peer; base-profile secondaries start the VPN when that network activates. Neither setting guarantees continuous recovery from every VPN-only failure. Verify tunnel, target route, and reachability after each test.
Your 15-minute next step: set one keepalive pair (start at 10/60), link the VPN through the base profileโs secondaries, then run the 10-minute torture test while watching logs. If it passes once, youโve bought yourself many future CTF nights back.
Original review: 2025-12-24
Technical guidance updated: 2026-10-13. Corrected VPN activation settings, Linux ping syntax, target-route checks, and recovery limits.