Welcome to HowToShipIt — practical how-to guides for developers: code, AI tools, and servers, explained step by step.

WireGuard VPN Setup: Run Your Own VPN Server on a VPS (2026)

A WireGuard VPN setup on your own VPS takes about fifteen minutes, costs a few pounds a month, and gives you something no commercial VPN can: a server you fully control, with no logging policy to trust and no shared IP address to share with strangers. This guide walks you through it two ways — the manual route with wg-quick, and the one-command Docker shortcut with wg-easy — then shows you how to add phones and laptops, check the tunnel actually works, and fix the five problems everyone hits first.

Commands assume Ubuntu 24.04, with notes where Debian or AlmaLinux differ; everything below was verified against guides tested in November 2026 and the official wg-easy project docs for version 15.

Why run your own WireGuard VPN server?

Three reasons keep coming up, and they are all practical rather than ideological:

  • Public Wi-Fi stops being a gamble. On a café, hotel, or airport network, all your traffic travels encrypted to your VPS. The network operator cannot see which sites you open or tamper with the traffic, and websites see your VPS address instead of the local network’s.
  • Nothing is logged unless you log it. WireGuard itself keeps no logs. Your server records nothing by default, and no company can be sold to a private equity firm that quietly changes the logging policy — a real risk with commercial VPNs in 2026.
  • Your own private network. An admin panel, a database, or a monitoring page can listen on the VPN address only (10.8.0.1 in this guide), so it is unreachable from the internet but reachable from your own devices. Your laptop, phone, and servers join one encrypted internal network.

One honest caveat: WireGuard traffic is identifiable by deep packet inspection, so if you are in a country that actively filters VPN traffic, you need an obfuscation layer such as Shadowsocks instead.

What you need

  • A Linux VPS with root or sudo access and SSH access. A 1 GB instance is enough — WireGuard runs in the kernel, with no separate background process, so the only real cost is CPU time for encryption under heavy traffic.
  • The VPS’s public IP address (the examples use 203.0.113.25 — replace it with yours).
  • UDP port 51820 open inbound, in both your provider’s firewall and the server’s own firewall.
  • A private address range for the VPN that does not clash with your home or office network. This guide uses 10.8.0.0/24: the server gets 10.8.0.1, the laptop 10.8.0.2, the phone 10.8.0.3.

How WireGuard works, in sixty seconds

WireGuard has been part of the Linux kernel since version 5.6, released in March 2020, so on current distributions you install the userspace tools and nothing else. The protocol is roughly 4,000 lines of code — against OpenVPN’s 70,000-plus — which is a large part of why it is fast and why audits find so little in it.

Peers authenticate each other with Curve25519 key pairs, much like logging in with an SSH key. There is no username, password, or certificate. Each machine has a secret private key, and the others identify it by its public key. Traffic travels as encrypted IP packets over UDP, conventionally on port 51820 — a convention, not a requirement; the port is whatever your ListenPort line says.

The wg-quick command only sets the interface up and then exits. There is no daemon to babysit, and the kernel module moves the packets, so throughput is the same whether you configure it by hand or through a web UI.

Route A: the manual setup (15 minutes, full control)

Step 1 — Install wireguard-tools

On Ubuntu and Debian, you also need nftables for the address translation later (it ships on Ubuntu 24.04 but not on the Debian 13 cloud image):

sudo apt update
sudo apt install wireguard-tools nftables

On AlmaLinux 9 and 10, and Rocky Linux:

sudo dnf install wireguard-tools

You do not need to load the kernel module separately — wg-quick loads it on first start.

Step 2 — Generate the server’s key pair

The keys live in /etc/wireguard, which only root can read. The umask 077 makes sure the files created are readable only by root as well:

sudo sh -c 'umask 077; wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub'
sudo cat /etc/wireguard/server.pub

wg genkey creates the private key, and wg pubkey derives the public key from it. The public key printed — a 44-character string ending in = — goes into your clients’ configuration. Never share the contents of server.key or copy it anywhere public.

Step 3 — Write the server configuration

First, find out which interface your server uses to reach the internet:

ip route show default
default via 203.0.113.1 dev eth0 proto static

The name after dev — eth0 here, often enp0s1 on Ubuntu and Debian cloud images — is needed for the address translation rule. Now create /etc/wireguard/wg0.conf, again readable only by root:

sudo sh -c 'umask 077; nano /etc/wireguard/wg0.conf'
[Interface]
# the server's address in the VPN
Address = 10.8.0.1/24
ListenPort = 51820
# the contents of /etc/wireguard/server.key
PrivateKey = <the server's private key>

# NAT: traffic from the VPN leaves with the server's IP address
# (replace eth0 with the name of your own interface)
PostUp = nft add table ip wgnat; nft add chain ip wgnat postrouting '{ type nat hook postrouting priority srcnat; }'; nft add rule ip wgnat postrouting ip saddr 10.8.0.0/24 oifname "eth0" masquerade
PostDown = nft delete table ip wgnat

When the tunnel starts, the PostUp line creates a separate wgnat nftables table with a single masquerade rule, and PostDown deletes it when the tunnel stops. On AlmaLinux and Rocky Linux, firewalld does the address translation instead, so the config is shorter — just the [Interface] section — and you add masquerading with firewall-cmd --permanent --add-masquerade.

Step 4 — Enable IP forwarding and open the firewall

The server has to forward packets arriving from the VPN towards the internet. Put it in a sysctl file of its own so it survives a reboot:

echo 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/99-wireguard.conf
sudo sysctl --system

With ufw on Ubuntu, allow the WireGuard UDP port and forwarding from the VPN towards the internet:

sudo ufw allow 51820/udp
sudo ufw route allow in on wg0 out on eth0

If you are enabling ufw for the first time now, allow SSH first (sudo ufw allow OpenSSH), or you will lock yourself out. With firewalld on AlmaLinux:

sudo firewall-cmd --permanent --add-port=51820/udp
sudo firewall-cmd --permanent --add-masquerade
sudo firewall-cmd --reload

Step 5 — Start WireGuard

sudo systemctl enable --now wg-quick@wg0
sudo wg show

The wg-quick@wg0 service uses /etc/wireguard/wg0.conf to create the wg0 interface, and it starts at boot. At this point wg show shows only the server:

interface: wg0
  public key: L/UC2CKSjsekZbOeHuiMS07rEo8ugu2uYzcvKU1Yc1U=
  private key: (hidden)
  listening port: 51820

Confirm it is really listening with sudo ss -lunp | grep 51820.

Step 6 — Add your laptop

Every device gets its own key pair and its own VPN address, so you can lock out a lost phone without touching the other devices. Generate the laptop’s keys on the laptop itself, so the private key never leaves the machine:

sudo sh -c 'umask 077; wg genkey | tee /etc/wireguard/laptop.key | wg pubkey > /etc/wireguard/laptop.pub'
sudo cat /etc/wireguard/laptop.pub

Then add a [Peer] section to the server’s wg0.conf:

# laptop
[Peer]
PublicKey = <the laptop's public key>
AllowedIPs = 10.8.0.2/32

On the server side, AllowedIPs means the server accepts only packets with source address 10.8.0.2 from this client, and sends packets addressed to 10.8.0.2 to this client. That is why each client gets its own /32 address.

Apply the change without restarting the tunnel — connected clients stay connected:

sudo systemctl reload wg-quick@wg0

Now the laptop’s own /etc/wireguard/wg0.conf:

[Interface]
# the contents of /etc/wireguard/laptop.key
PrivateKey = <the laptop's private key>
Address = 10.8.0.2/24
# DNS resolver through the tunnel (any resolver you trust will do)
DNS = 9.9.9.9

[Peer]
# the server's public key (server.pub)
PublicKey = <the server's public key>
# the VPS's public IP address and the WireGuard port
Endpoint = 203.0.113.25:51820
# full tunnel: all IPv4 and IPv6 traffic goes through the VPN
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

Start it with sudo wg-quick up wg0, and make it permanent with sudo systemctl enable --now wg-quick@wg0 if the laptop should always be connected.

Step 7 — Add your phone with a QR code

On a phone, the official WireGuard app (Android and iOS) can read the configuration from a QR code, and on Windows and macOS the official app imports the .conf file. Install qrencode on the server (sudo apt install qrencode on Ubuntu/Debian), generate the phone’s key pair on the server, add it as a [Peer] with AllowedIPs = 10.8.0.3/32, reload, then write the phone’s config to /etc/wireguard/telefon.conf and display it:

sudo qrencode -t ansiutf8 -r /etc/wireguard/telefon.conf

Scan it with the WireGuard app and the phone is in. Two warnings: the QR code contains the private key, so do not photograph it or display it where others can see it — and after scanning, delete the phone’s key and config from the server. Only its public key remains in the server’s wg0.conf:

sudo rm /etc/wireguard/telefon.key /etc/wireguard/telefon.conf

Route B: wg-easy — the same VPN with a web UI

If you would rather click than edit config files, wg-easy packages a WireGuard server with a web management UI in one Docker container. The tunnel itself is ordinary WireGuard — the kernel module moves the packets, so throughput is identical to the manual setup. What you gain is the client lifecycle: adding, disabling, and deleting peers without editing a config file over SSH, with a QR code for every client.

One thing to know first: version 15 is a rewrite. Most guides you will find were written for v14, where you set WG_HOST and PASSWORD_HASH as environment variables. In v15 those variables do nothing — configuration moved to a setup wizard in the browser on first boot. You cannot upgrade from v14 in place; back up wg0.json from the v14 UI first, start v15 fresh, and upload it when the wizard asks. Pin the major tag 15 (latest release v15.5.0); v15 also adds two-factor authentication, per-client firewall filtering, Prometheus metrics, client expiry dates, and one-time sharing links.

Deploy with the official Compose file — download it rather than retyping it, so you get the exact version the maintainers test:

sudo mkdir -p /etc/docker/containers/wg-easy
sudo curl -o /etc/docker/containers/wg-easy/docker-compose.yml \
  https://raw.githubusercontent.com/wg-easy/wg-easy/master/docker-compose.yml
cd /etc/docker/containers/wg-easy
docker compose up -d

The Compose file maps two ports with two very different jobs:

Port Protocol What it does
51820 UDP The actual WireGuard tunnel. Must be reachable from the internet.
51821 TCP The admin web UI. Should not be reachable from the internet.

Open http://YOUR_VPS_IP:51821 through an SSH tunnel (ssh -L 51821:127.0.0.1:51821 root@YOUR_VPS_IP), complete the wizard, and adding a client becomes one button: wg-easy generates the key pair, assigns an IP from the pool, and renders a QR code. On a phone you scan it; on a laptop you download the .conf and import it.

Pick the manual route if you want to understand every line and keep zero moving parts; pick wg-easy if you add and remove devices often, or you want someone non-technical in the household to manage their own client. The security properties of the tunnel are the same either way.

Full tunnel vs split tunnel

The AllowedIPs line on the client decides what goes into the tunnel:

  • Full tunnel — AllowedIPs = 0.0.0.0/0, ::/0. All traffic leaves through the VPS. This is what you want on public Wi-Fi. Include ::/0: without it, on an IPv6-capable network your IPv6 traffic bypasses the tunnel and leaves over the local connection.
  • Split tunnel — AllowedIPs = 10.8.0.0/24. Only traffic addressed to the VPN’s internal network goes through the tunnel; your browsing stays on your own connection. Use this when you only want to reach a service on the VPS or another client, and you do not want the latency or bandwidth cost of routing everything through the server.

The DNS line matters just as much. In a full tunnel, name resolution should go through the tunnel too — otherwise queries go to the local network’s resolver, outside the VPN. The examples here use Quad9 (9.9.9.9); any resolver you trust works.

Check the tunnel actually works

On the client, sudo wg show confirms a successful connection with the latest handshake line:

interface: wg0
  public key: 509FXrsngphGeLkubh6MsZDTkwa3Y2md9Jj8CRBMekU=
  private key: (hidden)
  listening port: 44606
  peer: L/UC2CKSjsekZbOeHuiMS07rEo8ugu2uYzcvKU1Yc1U=
  endpoint: 203.0.113.25:51820
  allowed ips: 0.0.0.0/0, ::/0
  latest handshake: 3 seconds ago
  transfer: 52.78 KiB received, 4.95 KiB sent
  persistent keepalive: every 25 seconds

Then prove the traffic really leaves through the VPS:

ping -c 2 10.8.0.1
ip route get 1.1.1.1
curl -4 ifconfig.me

ip route get should show dev wg0, and curl -4 ifconfig.me should print the VPS’s IP address, not your own. On the server, sudo wg show shows each client, where it connected from, when the last handshake took place, and how much data has passed.

Troubleshooting: the five problems everyone hits

Symptom Most likely cause Fix
No handshake; transfer says 0 B received The server’s firewall is not allowing the UDP port, or the keys are swapped Check ufw status / the firewall log for [UFW BLOCK] ... DPT=51820; confirm the Endpoint matches ListenPort; remember the client’s config takes the server’s public key and vice versa. WireGuard silently ignores packets with a wrong key and logs nothing.
Handshake works, ping 10.8.0.1 works, but no internet The server is not forwarding or not translating the traffic Check cat /proc/sys/net/ipv4/ip_forward returns 1; check the NAT rule exists (sudo nft list table ip wgnat); check the interface name in the rule matches the real one (eth0 vs enp0s1); with ufw, a missing route allow rule shows [UFW BLOCK] IN=wg0 OUT=eth0 in the log.
DNS queries bypass the VPN No DNS line in the client config Add DNS = 9.9.9.9 (or your resolver) to the client’s [Interface]. If wg-quick up then fails because resolvconf is missing, install systemd-resolved on Ubuntu/Debian, or drop the DNS line.
Some pages do not load, larger downloads stall MTU too large for the path wg-quick defaults to 1420 bytes, which is fine on most connections; some mobile or PPPoE connections need less. Try MTU = 1380 in the client’s [Interface] section.
No connection for a while after the server restarts Clients reconnect on their own, but not instantly Wait — in testing it took about 17 seconds. Use systemctl reload wg-quick@wg0 to add or remove clients; unlike restart, reload does not drop connections.

Two more diagnostics worth knowing: wg-quick prints every command it runs, so a failed start usually tells you exactly which step broke; and sudo journalctl -u wg-quick@wg0 shows the service log. If a client disappears after a server restart, you probably added it with wg set instead of writing it into wg0.conf — wg set changes only the running tunnel.

Security checklist

  • Protect the private keys. /etc/wireguard and everything in it should be readable only by root — that is what umask 077 is for. Anyone who obtains a private key can connect as that device. Never send config files by email or chat, and never put them in version control.
  • Know how to lock out a device. If a phone is lost, delete its [Peer] section from the server’s wg0.conf and run sudo systemctl reload wg-quick@wg0. The key on the device becomes useless immediately, and the other devices need no new keys.
  • The WireGuard port does not talk. The server does not respond to unauthenticated packets at all, so a port scanner cannot tell whether anything is running on 51820. Your other services — above all SSH — still need protecting, so harden SSH first if you have not already.
  • Keep the kernel updated. WireGuard is part of the kernel, so its security fixes arrive with the system’s usual kernel updates. Run them.
  • Keep the admin panel off the internet. If you use wg-easy, never expose port 51821 publicly. Reach it through an SSH tunnel, or put it behind a reverse proxy with authentication.

WireGuard vs a commercial VPN: an honest verdict

Self-hosting wins on trust and control — no logging policy to read, no shared IP, and a private network for your own services on top. It loses on location choice (your traffic exits from one country, your VPS’s country) and on convenience (you are the support desk when something breaks at 2 a.m.). For a developer who already rents a VPS, the maths is simple: the server is already paid for, the setup is fifteen minutes, and the tunnel is the same cryptography either way. If you do not have a VPS yet, a small instance from a budget provider costs a few pounds a month — roughly what a commercial VPN costs, except the server is yours to use for other things too.

5 mistakes to avoid

  1. Opening 51820/TCP instead of UDP. WireGuard only speaks UDP. A TCP rule does nothing, and the “no handshake” symptom will eat an afternoon.
  2. Forgetting IP forwarding. The handshake succeeds, the tunnel comes up, and nothing loads. net.ipv4.ip_forward = 1 is the step people skip.
  3. Using the wrong interface name in the NAT rule. eth0 in the guide, enp0s1 on your server — check ip route show default first.
  4. Adding clients with wg set and never writing them to the file. They vanish on the next restart. Always edit wg0.conf and reload.
  5. Copying a v14 wg-easy compose file into a v15 world. WG_HOST and PASSWORD_HASH are ignored in v15 — the wizard in the browser is where those settings live now.

Further Reading & References

Verified 25 November 2026 against the sources above. WireGuard versions and the wg-easy v15 behaviour described here are current as of that date.

Leave a Comment