VPN doesn't come back after sleep: why and how to fix it

When a computer sleeps, its network adapter goes off, and on waking it joins the network again, sometimes with a new address or on another network. By then the tunnel's connections are dead, the router may have forgotten the VPN's UDP traffic and the server may have closed the session, yet the client can still show Connected. Reconnecting fixes it at once. A client that checks whether traffic really flows, keepalive in WireGuard and the right power settings keep it from happening.

Updated

On this page

What happens to a VPN during sleep

A VPN is a few connections that have to stay alive: the tunnel to the server and, inside it, each app's own connections. During sleep the computer sends nothing, the Wi-Fi adapter usually powers down, and the other side waits only so long. On waking, Wi-Fi reconnects, the router may hand out a new address, and if you opened the lid somewhere else, it's another network altogether. The client often doesn't notice: it was frozen along with everything else, so it shows Connected while nothing goes through.

Why the tunnel doesn't come back

  • The network went away and came back — maybe with a new IP. A client tied to the old address or interface keeps sending into nothing.
  • The route to the server points at the old router — a VPN client sends traffic for the server's address through your router. Wake up on another network, and that route leads nowhere until the client rebuilds it.
  • The connections inside are dead — the server closed idle connections while you slept. Protocols over TCP (VLESS, Trojan, VMess, Shadowsocks) need new ones, and apps that kept an old one hang until it times out.
  • The router forgot the UDP mapping — routers and carriers keep UDP mappings only briefly. WireGuard, AmneziaWG and Hysteria2 make a new one with the first packet after waking.
  • The clock jumped — if it is set back after waking, a WireGuard server ignores handshakes stamped earlier than the last one it accepted, and VMess fails with a clock more than 90 seconds off.
  • The name was resolved before sleep — WireGuard looks up an Endpoint given by name once, when the tunnel starts. If the server's address changed meanwhile, it keeps knocking on the old one.
  • The system held the app back — on laptops with Modern Standby, Windows keeps the network on or off in sleep depending on the model; Android's Doze and brand battery savers can suspend or stop a VPN app.
  • A sign-in page — hotel and café Wi-Fi often wants its terms accepted again after waking, and a kill switch can block that page too: disconnect for a moment, sign in, connect again.

What you see, why, and what to do

  • Connected after waking, but nothing loads

    CauseThe tunnel's connections died in sleep, and the client hasn't noticed

    What to doReconnect; turn on the client's check that traffic flows

  • New sites open, but a chat, a download or a call hangs

    CauseThose apps kept connections that died during sleep

    What to doWait a minute or restart that app: the VPN itself is fine

  • It works after waking at home, not somewhere else

    CauseThe route to the server still goes through the old router

    What to doReconnect after joining the new network

  • The VPN keeps reconnecting, Wi-Fi is up

    CauseThe network wants you to sign in, or doesn't let this protocol through

    What to doAccept the network's sign-in page; if there is none, try another protocol

  • WireGuard: wg show has no fresh handshake after waking

    CauseThe Endpoint name points at an old address, or the clock went back

    What to doRestart the tunnel; check the time

  • Wi-Fi itself comes back slowly, or not at all

    CauseThe adapter's power saving

    What to doTurn off power saving for the network adapter

  • The phone's VPN is off after it lay unused

    CauseDoze or a battery saver stopped the app

    What to doRemove battery limits for the VPN app, turn on Always-on VPN

What helps

  1. 1

    Reconnect

    Turn the VPN off and on. It does everything at once: a new route, new connections, a fresh handshake.

  2. 2

    Let the client watch the tunnel

    Many clients can reconnect after a drop or a network change; turn that on. The most useful kind checks that traffic actually flows, because after sleep the tunnel exists and carries nothing.

  3. 3

    Add keepalive to WireGuard

    PersistentKeepalive = 25 in [Peer] sends a tiny packet every 25 seconds while the tunnel is idle. Nothing goes out during sleep itself, but it keeps the router's mapping open while the machine sits idle and helps the handshake come back right after waking.

  4. 4

    Turn off the adapter's power saving

    On Windows: Device Manager → Network adapters → your Wi-Fi adapter → Properties → Power Management, untick “Allow the computer to turn off this device to save power”. Some laptops don't have this tab.

  5. 5

    On a phone, remove the battery limits

    Settings → Apps → the VPN app → Battery: Unrestricted (names differ between brands). Then Settings → Network & internet → VPN → the gear next to the app → Always-on VPN: the system starts the VPN by itself and keeps it running.

Find out what happened

Match the time the machine woke up with the moment the VPN failed.

Windows: PowerShell
Get-WinEvent -FilterHashtable @{LogName='System'; ProviderName='Microsoft-Windows-Power-Troubleshooter'} -MaxEvents 5 | Format-List TimeCreated, Message

Each entry is one wake: the sleep time, the wake time and what woke the machine.

Windows: PowerShell or cmd
powercfg /a

Standby (S0 Low Power Idle) Network Connected — the laptop keeps Wi-Fi on in sleep. Network Disconnected — it turns Wi-Fi off, so even a short sleep takes the tunnel's connection down.

Windows: PowerShell as administrator
Restart-Service 'WireGuardTunnel$wg0'

Restarts the tunnel named wg0 in the official WireGuard app; put your tunnel's name after the $.

macOS: Terminal
pmset -g log | grep -E "Sleep|Wake" | tail -n 20

The latest sleeps and wakes, with times and reasons.

Linux: Terminal
sudo journalctl -b -k | grep -E "PM: suspend (entry|exit)"
sudo wg show

Each suspend entry and suspend exit pair is one sleep since boot. After waking, latest handshake in wg show should be seconds old again; if it stays minutes old, sudo wg-quick down wg0 && sudo wg-quick up wg0.

Which protocols take sleep better

WireGuard and AmneziaWG have no connection to lose: after waking they do a fresh handshake with the next packet and carry on, even from a new address, since the server learns where the client is from its signed packets. When they don't recover, the cause is usually the route, the Endpoint name or the clock. Protocols over TCP, such as VLESS, Trojan, VMess and Shadowsocks, keep connections open to the server, and those don't survive a long sleep: new ones usually work at once, the old ones hang, and the client has to notice.

In Veli

Veli reconnects by itself and checks that traffic flows

On a computer the switches for this are in Settings → Connection, and two of them are on from the start: “Reconnect after a drop” (the pause between attempts grows up to a minute) and “Check that traffic flows” (after 30 seconds without an answer the tunnel restarts). The second one catches exactly the tunnel that looks up after sleep but carries nothing. Under them is “Fallback servers”: once you turn it on, after 3 failed attempts the app moves to the fastest of the other profiles. With the kill switch on (Settings → Security), the internet past the tunnel stays closed while the VPN reconnects. If it isn't back within three minutes while there is a network, the app stops and says why; while there is no network, it waits for one.

On Android the app also brings the tunnel back by itself when the link goes, with the attempt and the reason in the notification. On the first run it asks for “No battery restrictions”: choose Veli → “Don't optimize”, so the system doesn't stop the VPN in the background; the Kill switch row in Settings points to Android's own “Always-on VPN” and “Block connections without VPN”. Every drop is a record in Diagnostics → Log with its reason, and on a drop the app checks at once whose fault it is: your network, the server or something on the way.

FAQ

Why does my VPN stop working after my laptop wakes up?

While it slept, the tunnel's connections died and the network came back, sometimes with a new address, but the client still thinks it's connected. Reconnect, and turn on the client's automatic reconnect or traffic check.

Why does WireGuard survive sleep when VLESS doesn't?

WireGuard has no connection to lose and does a new handshake with the next packet. VLESS runs over TCP connections that the server closed while you slept, and the client has to notice and open new ones.

Does PersistentKeepalive keep the VPN alive during sleep?

No, nothing is sent while the machine sleeps. It keeps the path open while the device is awake but idle, and helps the handshake come back right after waking.

Why does the VPN on my Android phone turn off overnight?

Doze or the brand's battery saver stops the VPN app. Remove its battery limits and turn on Always-on VPN in Android's VPN settings.

A VPN that notices it went quiet

On a computer, Veli reconnects after a drop and restarts a tunnel silent for 30 seconds, both on from the start; with “Fallback servers” on, it moves to another profile after three failed attempts.