brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wg show latest-handshakes tells you if a WireGuard VPN peer is really connected

Network and access
~/tips/tip-wireguard-wg-show-handshake

sudo wg show wg0

Check when each WireGuard peer last completed a handshake to see if the tunnel works.

A WireGuard interface comes up even when the other side is unreachable. There is no connected state like other VPNs show. The handshake time is the closest thing, so that is what I’d look at.

sudo wg show wg0

For every peer you get the endpoint, the allowed IPs, the latest handshake and how much data went each way. If the handshake line is missing, the peers have never talked. If it says a few minutes ago, the tunnel is up; WireGuard renews it about every two minutes while there is traffic.

For a script, ask for just that field. It prints the peer’s public key and a Unix timestamp, with 0 for never:

sudo wg show wg0 latest-handshakes

transfer gives the byte counters the same way, and dump prints everything tab separated for parsing.

If there is no handshake, I’d check in this order: is the endpoint address and port right, is the UDP port open on the other side’s firewall and router, and do the keys match. A swapped public key fails silently, so compare the public key in one config with wg pubkey output from the other side’s private key.

A handshake that is hours old is not always a problem. Without traffic, WireGuard stays quiet.

Further reading: wg(8) man page, WireGuard quick start

Going deeper: Why a Tailscale device vanishes after 180 days, and how to stop it

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link