VPN keeps disconnecting: why and how to make it stable

A VPN drops when one of three things breaks: your network for a moment, the path to the server, or the system stops the app. When the drop happens says which one: on moving to mobile data, after the phone's screen goes off, every few idle minutes, a minute after connecting, on a big download. Most cases are fixed in the settings: reconnect after a drop, keepalive for UDP protocols, no battery limits for the VPN app, one key per device, another protocol where the network cuts this one.

Updated

On this page

When it drops, and why

“Disconnects, but the internet is fine” is the usual case: the internet works, the path to the server or the protocol doesn't. Start from the moment of the drop.

  • When you go from Wi-Fi to mobile data, or between access points

    Likely causeThe network changed under the tunnel

    What to doTurn on reconnect after a drop; on Android, Always-on VPN too

  • Every few minutes while nothing is going on

    Likely causeThe router or the operator forgot the UDP mapping of WireGuard, AmneziaWG or Hysteria2

    What to doKeepalive: PersistentKeepalive = 25 in WireGuard

  • On the phone, a while after the screen goes off

    Likely causeA battery saver stopped the VPN app

    What to doRemove battery limits for the VPN app

  • A minute or a few after connecting, or when a big download starts

    Likely causeThe network recognises the protocol and cuts it or freezes it

    What to doAnother protocol or port

  • When a second device connects with the same config

    Likely causeTwo devices with one key push each other off the server

    What to doA separate key or config for each device

  • Big pages and downloads hang, small things work

    Likely causePackets are too large for this network (MTU)

    What to doLower the MTU, for WireGuard MTU = 1280

  • At about the same time every day

    Likely causeThe provider renews your address or the router restarts

    What to doNothing in the VPN: reconnect after a drop covers it

  • Only on one Wi-Fi: a hotel, an office, a café

    Likely causeThe network blocks VPNs or wants its sign-in page again

    What to doSign in on the network's page; if it still drops, another protocol

  • After sleep

    Likely causeThe tunnel's connections died while the machine slept

    What to doSee the guide on VPN after sleep

The causes in more detail

  • The network changes. Moving from Wi-Fi to mobile data, or between two access points, gives the device a new address. A client that doesn't notice keeps sending into the old network. It lasts a few seconds if the client reconnects by itself, and forever if it doesn't.
  • The router forgets idle UDP. Home routers and mobile operators keep a UDP mapping only for a short while without traffic, often from half a minute to a few minutes. WireGuard is silent when nothing is sent, so the next packet after a pause may not get back to you.
  • The phone saves battery. Android's Doze and the brands' own battery savers stop apps in the background, and a VPN app is one of them. On some phones that happens within minutes of the screen going off.
  • The network cuts the protocol. Where VPNs are filtered, a connection can be reset after a minute, or frozen once more data has gone through it. The client reconnects, the network cuts it again, and it looks like constant drops.
  • One key on two devices. A WireGuard server knows one key at one address: when the second device makes a handshake, the first one loses the tunnel, and then the other way round. Panels with a limit on devices or addresses cut the extra connection too.
  • Packets are too big. If the tunnel's MTU is larger than the network carries, small requests pass and large ones are lost. Pages half-load, downloads hang, and the client may decide the tunnel is dead.
  • The server side. The server restarts, the subscription has run out of time or traffic, or the panel limits the number of connections.
  • Two VPNs at once. Two VPN apps fight over routes and the system's VPN slot: on Android, starting a second one stops the first.

What helps

  1. 1

    Turn on reconnect after a drop

    Most clients can bring the tunnel back by themselves. The most useful kind also checks that traffic really flows, because a tunnel can be up and carry nothing.

  2. 2

    Add keepalive to UDP protocols

    In a WireGuard or AmneziaWG config, PersistentKeepalive = 25 in [Peer] sends a tiny packet every 25 seconds of silence, and the router keeps the path open.

  3. 3

    Remove the battery limits on the phone

    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 restarts the VPN by itself.

  4. 4

    One key per device

    Make a separate key, profile or config for each phone and computer. On your own server this is a new user or key; with a provider, check how many devices the subscription allows.

  5. 5

    Change the protocol where the network cuts

    If drops start a minute after connecting or on big downloads, the network is cutting this protocol. Try one that disguises itself as ordinary HTTPS, such as VLESS with Reality, or one over UDP (Hysteria2), whichever the network leaves alone.

  6. 6

    Lower the MTU

    For WireGuard and AmneziaWG, MTU = 1280 in [Interface] fits almost any network, mobile data included. It costs a little speed, and the drops on big pages go away.

  7. 7

    Keep one VPN

    Turn off or remove other VPN apps and proxy extensions in the browser.

Find the moment and the cause

Keep a ping to the VPN server's address running with times on it. If pings stop at the same moments the VPN drops, it is your network or the path to the server. If they carry on while the VPN drops, the network is cutting the protocol, or the app is being stopped.

Windows: PowerShell
ping.exe -t vpn.example.com | ForEach-Object { "{0:HH:mm:ss} {1}" -f (Get-Date), $_ }

Every line gets a time. Request timed out in a row means the path to the server went away. Ctrl+C stops it.

Windows: PowerShell
Get-WinEvent -LogName 'Microsoft-Windows-NetworkProfile/Operational' -MaxEvents 10 | Format-List TimeCreated, Id, Message

When Windows lost and found the network: 10001 is disconnected, 10000 is connected. If these times match the VPN's drops, the cause is the network.

Windows: PowerShell or cmd as administrator
netsh wlan show wlanreport

A report on Wi-Fi drops over the last days; the path to the HTML file is in the answer.

macOS or Linux: Terminal
ping vpn.example.com | while read l; do echo "$(date +%T) $l"; done

The same ping with times. Gaps in the times are the moments the path went away. Ctrl+C stops it.

Linux: Terminal
journalctl -u NetworkManager --since "1 hour ago" | grep -E "state change|disconnected"

When NetworkManager dropped and brought back Wi-Fi or a cable in the last hour.

Which protocols hold up on a shaky network

WireGuard and AmneziaWG keep no connection open: after a short gap or a new address they carry on with the next handshake, so a drop of a second costs about a second. Hysteria2 and TUIC also run over UDP and get back quickly, but some mobile networks and offices squeeze UDP, and there they drop more often. Protocols over TCP (VLESS, Trojan, VMess, Shadowsocks) get through where UDP is squeezed, but every drop takes the open connections with them, and apps open them again. On a network that switches a lot, UDP protocols with keepalive hold up better. On a network that squeezes UDP, TCP ones do.

In Veli

Veli reconnects and writes down why it dropped

On a computer, Settings → Connection → Drops has two switches 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). “Fallback servers” is off: turn it on, and after 3 failed attempts the app moves to the fastest of the other profiles. Every drop is a record in Diagnostics → Log with its reason, and on a drop the app checks whose fault it is: your network, the server or something on the way.

If Veli turns off by itself, check two settings that do it on purpose: “Turn the VPN off in a trusted network” in Settings → Wi-Fi networks and “Disconnect the VPN when the limit is reached” in Settings → Traffic. On Android the app brings the tunnel back 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.

FAQ

Why does my VPN keep disconnecting when the internet is fine?

The internet works, but the path to the server or the protocol doesn't: the router forgets idle UDP, the network cuts the protocol, or two devices share one key. Look at when it drops: the moment tells the cause.

Why does the VPN on my phone turn off when the screen is off?

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

Does PersistentKeepalive stop the drops?

It stops the ones that come from the router forgetting an idle UDP path. It doesn't help when the network cuts the protocol or the phone stops the app.

Can two devices use the same WireGuard config?

Not at the same time. The server knows one key at one address, so the devices keep pushing each other off. Give each device its own key.

Why does the VPN drop on mobile data but not on Wi-Fi?

Mobile networks change addresses more often, keep UDP paths shorter and filter some protocols. Keepalive, a lower MTU and another protocol usually help.

Drops with the reason written down

Veli is a free client for Windows, macOS, Linux and Android. It reconnects by itself, restarts a tunnel that carries nothing, and every drop is a Log record with its reason.