WireGuard PersistentKeepalive = 25: When You Need It, Client or Server (2026)

Put PersistentKeepalive = 25 in the client's [Peer] block when it sits behind NAT; a server with a public IP needs none, and 0 turns it off. Why 25 s, battery cost, range errors.

By Eric GerardFounder · VPNSmith - Self-host VPN & GDPR VPS specialist

Updated 12 min read12 min

Affiliate links: we may earn a commission, at no extra cost to you. Method

Generate my configRead the guide

fig. 01 / self-host-vpnencrypted tunnelUDP 51820DEVICE10.8.0.2SERVER10.8.0.1INTERNETNATAllowedIPs = 0.0.0.0/0, ::/0ListenPort = 51820 (server)
fig. 01 / self-host-vpn

Your WireGuard client connects, works for a minute, then goes quiet: you can reach the server from the client, but the server can no longer push anything back to you. SSH from the server side hangs, a LAN device behind the client becomes unreachable, the handshake silently goes stale. The fix is almost always one line on the client: PersistentKeepalive = 25. This guide explains exactly what that option does, why 25 seconds is the magic number, and which side of the tunnel it belongs on.

Black Friday 2026VPN prices read on 16 Nov: Proton VPN Plus $59.76 for 24 months, Surfshark €67.23 for 27 months, next to a self-hosted VPS. See the dated comparison

fig. 01 / self-host-vpnencrypted tunnelUDP 51820DEVICE10.8.0.2SERVER10.8.0.1INTERNETNATAllowedIPs = 0.0.0.0/0, ::/0ListenPort = 51820 (server)
fig. 01 / self-host-vpn

Not sure your config has it right? Paste your .conf into the WireGuard config checker: it flags every peer that has an Endpoint but no PersistentKeepalive, along with keys in the wrong section and malformed values. Nothing leaves your browser.

One case no keepalive value can fix: when the server itself sits behind CGNAT, nothing from outside can reach it at all. The way out is to run the server on a machine with a public IPv4, such as a HostPapa Unmanaged VPS Lite (affiliate link, 2.95 $ a month on a 3-year term, then the regular rate) or a Contabo Cloud VPS (affiliate link), from €5.50/month over 24 months (price checked 17 October 2026). If you would rather have a US host with a 30-day money-back guarantee, Ultahost VPS Basic is 5.52 $ a month on a 24-month term (1 GB RAM, dedicated IPv4, read on 21 October 2026), enough for a WireGuard server for a few devices. Not sure whether your home line is behind CGNAT? The free WireGuard port checker compares the WAN address shown by your router with your public IP and tells you whether a port forward can work at all. Choosing a host? Compare the best VPS for a VPN and Contabo vs Hetzner vs OVH on the price actually billed. HostPapa's Lite plan is the smallest one here: 1 core, 1 GB RAM, 25 GB NVMe and 4 TB transfer, unmanaged (root SSH on Ubuntu or Debian, no control panel, you install WireGuard yourself), enough for a WireGuard server for a few devices, 30-day money-back guarantee, read on 28 October 2026.

Still choosing the server? Our cheapest-VPS ranking for WireGuard compares what each provider really bills for a usable endpoint.

The short answer

If a peer sits behind NAT and needs to stay reachable, add this to the [Peer] block on that peer's config:

[Peer]
PublicKey =...
Endpoint = server.example.com:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

Restart the tunnel and the silent-tunnel-after-idle problem disappears. Everything below is the why.

What PersistentKeepalive does

By design, WireGuard is silent: when there is no traffic to send, it sends nothing. No keepalives, no heartbeats, no chatter. That makes it efficient and hard to fingerprint - but it breaks one specific scenario.

When a client is behind NAT (a home router, mobile carrier, office firewall), the NAT device creates a temporary mapping the first time the client sends a packet out. That mapping is what lets the server send replies back to the right internal address - think of it as a punched hole in the NAT. Crucially, that hole expires after a period of inactivity, often anywhere from 30 seconds to a couple of minutes for UDP. Once it closes, the server's packets have nowhere to go, and the peer becomes unreachable until the client speaks first again.

PersistentKeepalive solves this by sending a small, empty keepalive packet to the peer every N seconds. That tiny bit of traffic keeps the NAT mapping refreshed, so the hole never closes and the peer stays reachable even when idle.

Data-centre cabling and network equipment in a rack - the public-IP side of a self-hosted WireGuard tunnel
Data-centre cabling and network equipment in a rack - the public-IP side of a self-hosted WireGuard tunnel

Why 25 seconds

The official WireGuard recommendation is 25 seconds, and the reasoning is simple. Common UDP NAT timeouts cluster between 30 seconds and a few minutes, and the shortest value you regularly hit in the wild is around 30 seconds. Sending a keepalive every 25 seconds refreshes the mapping with a small margin before that 30-second floor - frequent enough to never let the hole close, infrequent enough to cost almost nothing.

You can go lower if your NAT is unusually aggressive (15 is a reasonable next step), or higher to save battery on mobile, but 25 is the documented recommendation for a reason (the default itself is 0, meaning off). Don't over-think it.

What the official WireGuard quickstart says (section "NAT and Firewall Traversal Persistence", wireguard.com/quickstart, read on 2026-10-24): "A sensible interval that works with a wide variety of firewalls is 25 seconds. Setting it to 0 turns the feature off, which is the default, since most users will not need this, and it makes WireGuard slightly more chatty."

Where to put it: client vs server

This is the part people get wrong. The keepalive goes on the peer that needs to stay reachable through a NAT:

SetupKeepalive on client?Keepalive on server?
Roadwarrior client behind NAT → server on public IPYes (= 25)No
Server on a clean public IP(n/a)Not needed
Both ends behind NAT (peer-to-peer)YesYes

In the normal case - a laptop or phone behind a router talking to a VPS with a real public IP - only the client needs PersistentKeepalive = 25, in the [Peer] block that describes the server. The server doesn't need one toward its clients: the client always initiates, and the server just replies to whatever source address the last packet came from. A clean public-IP server is exactly the setup where you avoid the server-side NAT problem entirely.

Example [Peer] config

Here is a complete client-side peer block with the keepalive in place:

[Interface]
PrivateKey = <client-private-key>
Address = 10.66.66.2/32
DNS = 10.66.66.1

[Peer]
PublicKey = <server-public-key>
Endpoint = vpn.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

Apply it with a tunnel restart:

sudo wg-quick down wg0 && sudo wg-quick up wg0

Confirm it took effect - wg show lists the interval under the peer:

sudo wg show
# persistent keepalive: every 25 seconds

If you are assembling configs from scratch, the ready-to-use WireGuard config templates already include the keepalive line in the right block for each platform.

If the tunnel stays up but large transfers stall after the keepalive fix, the next suspect is packet size: the free WireGuard MTU calculator gives the right MTU from a ping test and adds the PersistentKeepalive = 25 line to the same config excerpt.

These values are in our free WireGuard Cheat Sheet (5-page PDF, direct download, no sign-up), keepalive by situation included. The paid WireGuard Self-Hosting Kit (9 USD) adds client templates with PersistentKeepalive = 25 already set and a server template that leaves it out.

The "interval must be in range" error

PersistentKeepalive expects a plain whole number of seconds, validated against the range 0 to 65535. If you see interval must be in range or must be in range 0 to 65535, you passed something that isn't a valid integer in that window:

  • A unit suffix - write 25, not 25s.
  • A decimal - 25, not 25.0.
  • A negative number, or a value above 65535.
  • A stray space or invisible character pasted from a web page.

A value of 0 is legal and means disabled - the same as leaving the line out entirely. So PersistentKeepalive = 0 does nothing useful; use a real interval like 25.

Keepalive set but still not working

If you added the line and the tunnel still goes silent after idle, work through these honest causes in order:

  • Set on the wrong side. The peer that's behind NAT is the one that needs it. A keepalive on the public-IP server alone won't keep a client's NAT hole open.
  • NAT timeout shorter than your interval. Some carrier-grade NAT closes UDP mappings faster than 30 seconds. Drop the interval to 15 and re-test.
  • A firewall is blocking the path. If the underlying UDP port is filtered, no keepalive will get through - confirm the WireGuard port is actually open on both ends.
  • The endpoint changed (roaming). If the client moved networks and its public address changed, the server may still be aiming at the old Endpoint. The keepalive helps the server track the new source, but a stale client-side Endpoint can still misfire.

No server, just a blocked network? If you are trying to get your own laptop through hotel, office or campus Wi-Fi that drops WireGuard, a VPN app with a built-in obfuscation mode does the wrapping for you: Proton VPN has Stealth, an obfuscated TLS tunnel available on every plan including Free, and NordVPN has NordWhisper, which makes VPN traffic resemble regular web traffic and now runs its Obfuscated Servers (affiliate links). Against state-level DPI, a private server wrapped with Xray REALITY holds better; our anti-DPI guide compares both routes.

Paid plan, Black Friday 2026: Proton's partner offer, checked on 28 October 2026, is VPN Plus at $2.49/month over 2 years ($59.76 for the first 24 months, then $83.88 per year), with a 30-day money-back guarantee and 10 devices. The order page shows the price for your country, and Proton does not publish an end date.

Keepalive vs the WireGuard handshake

These are two different timers, and it helps to separate them. WireGuard renews its cryptographic handshake roughly every two minutes - but only when there is actual traffic to protect. On an idle link with no keepalive, no traffic means no handshake renewal, and meanwhile the NAT hole quietly closes.

PersistentKeepalive fills exactly that gap: it keeps a trickle of traffic flowing on an otherwise idle link, holding the NAT mapping open between handshakes so the tunnel is ready the instant real data needs to move. The keepalive doesn't replace the handshake; it keeps the path alive so the handshake can happen when needed.

A public-IP server removes half the problem

Most keepalive headaches come from NAT on the server side - a VPN box behind a home router, double NAT, a provider firewall. Put the server on a clean public IPv4 and the only NAT left in the picture is the client's, where a single PersistentKeepalive = 25 is all you need. A Contabo Cloud VPS 4 at €5.50/month gives you full root and a real public IP with no provider firewall to fight - the exact conditions where the client-side keepalive is the only thing you have to set. To understand the NAT mechanics this option works around, see the plain-English explainer on what NAT is.

Our free WireGuard config generator writes PersistentKeepalive = 25 into the client configs it builds, along with matching keys, AllowedIPs and Endpoint. The generator is free with no account, up to 250 devices, and its ZIP export holds every client .conf and its QR code as a PNG, handy to set up a whole office or family in one go.

Generate your WireGuard configs here

Type your server address, choose the number of devices, then scan each QR code from the app.

All keys are generated in your browser (Curve25519 / X25519). Nothing is sent to our servers - your config stays 100% private.

Public IPv4 or domain of the machine that will run WireGuard. No server yet? Leave it empty and add it later.

Free, no account: up to 250 clients, each .conf with its QR code, and one ZIP with every file.

Everything the device sends to the internet goes through your server.

Advanced settingsTunnel subnet, DNS, site-to-site LANs. The defaults work for most setups.

Optional. Enter the LAN subnet behind the server and/or behind a client that acts as a site gateway (a router, a Raspberry Pi, a NAS). The generator adds each LAN to the server's AllowedIPs, gives every peer the routes to the other LANs, and writes the forwarding rules on the gateways. Leave a field empty for a normal client.

What you download

  • wg0.conf

    for the server

  • client1.conf

    one per device

  • QR (sample)

    for the phone app

Illustration only: the lines and the QR code are fictional, no real key. Your real files are generated in your browser when you click.

A VPN changes your IP. It does not change your browser.

A tunnel replaces the address a service sees. It changes nothing about what your browser announces on its own - fonts, screen, time zone, graphics stack - and that combination is often stable enough to recognise you across sessions, tunnel or no tunnel.

Measure your own browser fingerprint - passive, no questions, no account, no email.

Going further

Sources and references:


Published 2026-06-29. The 25-second recommendation and the behaviour of PersistentKeepalive are from official WireGuard documentation; NAT timeout ranges vary by device, so confirm against your own router or carrier if a shorter interval is needed.

Reminder: running WireGuard and self-hosting a VPN is legal in the EU, US, Canada. VPNSmith publishes this content for educational purposes.

Affiliate link

Price checked 17 Oct 2026, 24-month term

Frequently asked questions

What does PersistentKeepalive do in WireGuard?
PersistentKeepalive is an option in the [Peer] section of a WireGuard config that makes the interface send a small empty keepalive packet to that peer every N seconds, even when there is no real traffic. By default WireGuard is silent: it sends nothing on an idle link. That silence is a problem when a client sits behind NAT, because the NAT mapping - the hole that lets the server reach back to the client - expires after a short idle period. The periodic keepalive keeps that mapping open, so the peer stays reachable. You enable it with one line: PersistentKeepalive = 25.
Why is the recommended PersistentKeepalive value 25 seconds?
The official WireGuard recommendation is 25 seconds. UDP NAT mappings on home routers and carrier-grade NAT typically time out somewhere between 30 seconds and a couple of minutes, and the shortest common timeout is around 30 seconds. Sending a keepalive every 25 seconds keeps the mapping refreshed with a small safety margin before that 30-second floor. Lower values work too but waste a little bandwidth and battery; 25 is the documented sweet spot. If your specific NAT is more aggressive, dropping to 15 can help.
Should PersistentKeepalive go on the client or the server?
Put it on the peer that needs to stay reachable through a NAT - almost always the roadwarrior client (your laptop, phone or home box behind a router). The client adds PersistentKeepalive = 25 in the [Peer] block that describes the server. A server with a real public IP does not need a keepalive toward its clients, because the client always initiates and the server simply replies to wherever the last packet came from. If both ends are behind NAT, set it on both.
Why am I getting 'interval must be in range 0 to 65535'?
PersistentKeepalive takes a whole number of seconds, and WireGuard validates it against the range 0 to 65535. The error 'interval must be in range' or 'must be in range 0 to 65535' means you passed something outside that - a negative number, a decimal, a unit suffix like '25s', or a stray character. Use a plain integer: PersistentKeepalive = 25. A value of 0 (or leaving the line out) disables the feature entirely.
Does PersistentKeepalive drain my battery or data?
Bandwidth-wise it is negligible: a keepalive is a small empty packet of roughly 32 bytes sent every 25 seconds, a few kilobytes per hour. The real cost is on mobile, where every keepalive wakes the radio out of its low-power sleep, and frequent wakeups can shorten battery life. That is why some people raise the interval on phones to save energy, accepting that the tunnel may go briefly unreachable while idle. On a always-on desktop or server the cost is effectively zero.