WireGuard is a free, open-source VPN that has been built into the Linux kernel since 2020. A WireGuard VPN on a Linux server of your own takes a handful of commands and two short configuration files to give your laptop and phone an encrypted tunnel to that server. Beyond protecting you on public Wi-Fi, the tunnel lets you keep private services, such as a mail server's administration pages, reachable only by your own devices.
In short
A VPN (virtual private network) creates an encrypted connection between two machines over the internet. Everything sent through it is unreadable to the networks in between.
WireGuard does this with a small, modern design:
Each device is identified by a public key, much like an SSH key. Each side lists the other's public key and the addresses it may use, a setting called AllowedIPs, which acts as both the route and the access list.
You need three things:
The job has five steps. This is the shape of the job, so you know what is involved. Test each step before relying on it.
On Debian and Ubuntu:
sudo apt install wireguard
wg genkey | tee privatekey | wg pubkey > publickey
The private key never leaves the machine it was made on. Only public keys are exchanged. The phone and desktop apps generate their own keys for you.
The server's file, /etc/wireguard/wg0.conf, names its own private key, its address inside the VPN and the port it listens on, then one [Peer] section per device:
[Interface]
PrivateKey = <server private key>
Address = 10.8.0.1/24
ListenPort = 51820
[Peer]
PublicKey = <laptop public key>
AllowedIPs = 10.8.0.2/32
Port 51820 is the usual choice, not a built-in default; WireGuard picks a random port if you do not set one.
The device's file mirrors the server's: its own private key and address, then the server's public key, the server's public address and port as the endpoint, and the addresses to send through the tunnel. The AllowedIPs setting decides how much goes through:
| AllowedIPs | What goes through the tunnel |
|---|---|
| The VPN range | Only VPN traffic |
0.0.0.0/0 |
Everything, which is what you want on public Wi-Fi |
Allow the chosen UDP port in the server's firewall, then start WireGuard and enable it at boot:
sudo ufw allow 51820/udp
sudo systemctl enable --now wg-quick@wg0
If devices are to send all their traffic through the server, the server also needs IP forwarding switched on, in a file under /etc/sysctl.d/, and a NAT rule. On Debian 13 the old /etc/sysctl.conf file is no longer read.
A VPN runs both ways. A device on the VPN can reach the server, and the server can reach the device. Firewall the WireGuard interface as carefully as the public one.
Use the VPN to close doors. A mail server has to keep port 25 open to receive mail from the rest of the world, but its administration pages, and even webmail and IMAP if your users are all on the VPN, need not be open to everyone.
Mailcow documents the building blocks. Mailcow, the open-source mail server, runs in Docker. Its documentation warns that ordinary host firewall rules on the INPUT chain do not restrict it, because Docker manages its own rules, and that restrictions belong in the DOCKER-USER chain. Mailcow can also bind its services to a chosen IP address. Combined with WireGuard, that lets you make the administration interface answer only on the VPN. Mailcow documents these building blocks rather than a ready recipe, so plan and test the result.
Other tools suit other situations:
| Your situation | Option | What it offers |
|---|---|---|
| An office that wants the VPN at the edge of its network | A firewall appliance such as OPNsense | An open-source firewall that has included WireGuard since version 24.1 |
| Many devices, changing often | headscale | An open-source, self-hosted coordination server for Tailscale clients, which manages keys and addresses across many devices for you |
| An enterprise policy | IPsec | The UK National Cyber Security Centre prefers IPsec for enterprise VPNs and says WireGuard has yet to be proven in enterprise settings |
| No server to run | The Noiz VPN add-on | An encrypted tunnel from each device, set up and supported by Noiz, with nothing for you to configure |
For a small business or a single server, WireGuard's simplicity is a strength.
A Noiz Cloud server gives you the root access and Linux system WireGuard needs. If you would rather Noiz did the Linux side, Linux administration is quoted by the hour, once off or maintained monthly.
Read next:
If you run a mail server and want its private pages reachable only from your own devices, get in touch.
Note: while some of this content was produced with the help of AI, the final editing has been done by a real human being.