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

How to Set Up WireGuard on Your VPS: Your Own Private VPN in 15 Minutes (2026)

A commercial VPN costs $5–12 a month, caps how many devices you can connect, and asks you to trust a company you have never met with all of your traffic. If you already rent a VPS, you can skip all of that. This WireGuard VPS setup turns a cheap server into your own private VPN in about 15 minutes — no subscription, no device limits, no logging policy to take on faith. You hold both ends of the tunnel.

WireGuard is the tool that makes this practical. It is a modern VPN protocol that lives inside the Linux kernel, configures itself from one short text file per side, and authenticates with public keys instead of passwords or certificates. This guide builds a full-tunnel VPN on Ubuntu 24.04: every packet from your laptop and phone routes through your VPS. All commands and config verified 15 November 2026.

Why WireGuard (and why your own VPS)

WireGuard is not the first VPN protocol, but it is the first one that feels designed rather than accumulated. OpenVPN and IPsec grew over decades into large codebases with certificate authorities, daemons, and state machines. WireGuard is roughly 4,000 lines of code, speaks a single UDP port, and treats keys the way SSH does: you exchange public keys with a peer, and then you can talk. There is no login system, no certificate expiry to babysit, and no daemon to nurse.

Three properties matter for this job. First, it lives in the Linux kernel (since version 5.6), so encryption happens at kernel speed instead of in a userspace process. Second, it roams: if your laptop switches from home Wi-Fi to a coffee-shop network, the tunnel survives because peers are identified by key, not by IP address. Third, it stays silent — WireGuard does not answer packets that are not signed with a known key, so to a port scanner your UDP port looks closed.

Running it on your own VPS has a different kind of appeal. A small 1 GB VPS is plenty — WireGuard’s overhead is tiny — and the server you already pay for becomes a fixed exit address in a country you chose, encrypted traffic on hotel and café networks, and private access to your own services. No per-device seat limits, no bandwidth cap imposed by a VPN app.

What you need before you start

  • A VPS running Ubuntu 24.04 or Debian 13, with a public IPv4 address and sudo access.
  • A KVM VPS, not a container. WireGuard lives in the kernel, so on a KVM guest with a current distribution it is already there; on a container VPS it only works if the provider’s host kernel includes it and allows it.
  • A client device — a laptop and, optionally, a phone.
  • About 15 minutes and a terminal.

Check your kernel first. Anything 5.6 or newer has WireGuard built in:

uname -r

Step 1: Install WireGuard on the server

On Ubuntu, the official install is a single package. The wireguard package pulls in the tools you need (wg and wg-quick):

sudo apt update && sudo apt install -y wireguard

That is the whole install. There is no service to configure and no daemon to enable yet — wg-quick handles bringing the interface up and down from a config file, which you write next.

Step 2: Generate the server keys

WireGuard has no login system. Every peer is identified by a Curve25519 keypair, exactly like SSH keys. Generate one on the server:

umask 077
wg genkey | tee /etc/wireguard/privatekey | wg pubkey > /etc/wireguard/publickey

The umask 077 matters: it makes the private key file readable only by root. Display the public key — you will paste it into every client config:

cat /etc/wireguard/publickey

The private key never leaves the server. The public key is safe to share; on its own it cannot decrypt anything, it only identifies this server to its peers.

Step 3: Write the server config

Create /etc/wireguard/wg0.conf. The interface name comes from the filename: wg0.conf becomes interface wg0. Replace the placeholder with your server’s private key from step 2:

[Interface]
PrivateKey = PASTE_SERVER_PRIVATE_KEY_HERE
Address = 10.8.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

[Peer]
PublicKey = PASTE_LAPTOP_PUBLIC_KEY_HERE
AllowedIPs = 10.8.0.2/32

What each line does:

  • Address = 10.8.0.1/24 — the server’s address inside the tunnel. 10.8.0.0/24 is a private range that should not collide with your home or office LAN; pick another if it does.
  • ListenPort = 51820 — the conventional default UDP port. Any free UDP port works, but keep the client config in sync if you change it.
  • PostUp / PostDown — firewall rules that run when the tunnel comes up or down. The MASQUERADE rule rewrites VPN clients’ source addresses to the server’s public IP, so return traffic from the internet finds its way back.
  • [Peer] / AllowedIPs — this is WireGuard’s cryptokey routing: the public key is tied to the tunnel IPs that peer may use. 10.8.0.2/32 means this peer may only ever send traffic as 10.8.0.2. Anything else gets dropped.

Two details people get wrong here. First, eth0 must be your server’s actual public interface — find it with ip route | grep default and substitute if yours is called something else. Second, lock the config file down:

sudo chmod 600 /etc/wireguard/wg0.conf

On Ubuntu 24.04 the iptables command maps to the nftables backend, but the commands above work unchanged.

Step 4: Enable forwarding and open the firewall

Your VPS now needs to act as a router: packets arriving on wg0 must be forwarded out to the internet, and their replies sent back. That takes two switches — kernel forwarding, and the firewall allowing forwarded traffic.

Enable kernel forwarding permanently:

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

Then the UFW gotcha, which is the single most common reason a tunnel comes up and nothing flows through it. UFW drops forwarded traffic by default, and ufw allow only opens traffic addressed to the machine itself — it never touches the FORWARD chain. If you use UFW, you need one of these:

# Option A: targeted route rule (keeps the default DROP policy)
sudo ufw route allow in on wg0 out on eth0

# Option B: allow all forwarding (simpler, less precise)
# in /etc/default/ufw, set:
DEFAULT_FORWARD_POLICY="ACCEPT"

Also note that UFW loads its own sysctl file at startup, which can silently overwrite the setting above. If you use UFW, set forwarding in /etc/ufw/sysctl.conf too by uncommenting net/ipv4/ip_forward=1 there.

Finally, open the WireGuard port itself. WireGuard speaks only UDP:

sudo ufw allow 51820/udp
sudo ufw reload

If your provider has a separate cloud firewall or security group (Hetzner, DigitalOcean, Linode and most others do), open UDP 51820 there as well — a closed provider firewall looks exactly like a broken tunnel.

Step 5: Add your first client

Generate a keypair on your laptop the same way as step 2 — or use the key generator built into the official WireGuard app:

umask 077
wg genkey | tee privatekey | wg pubkey > publickey

Then fill in the [Peer] block in the server’s wg0.conf with your laptop’s public key, and write the client config (call it laptop.conf):

[Interface]
PrivateKey = PASTE_LAPTOP_PRIVATE_KEY_HERE
Address = 10.8.0.2/32
DNS = 1.1.1.1

[Peer]
PublicKey = PASTE_SERVER_PUBLIC_KEY_HERE
Endpoint = YOUR_VPS_PUBLIC_IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

The client side mirrors the server. AllowedIPs = 0.0.0.0/0 is the wildcard that makes this a full tunnel: every destination goes through the VPN. PersistentKeepalive = 25 sends a keepalive packet every 25 seconds — the interval the official quick start recommends — so NAT and stateful firewalls between you and the server keep the mapping alive while the tunnel is idle.

Step 6: Bring the tunnel up and verify it works

On the server:

sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0

The second command makes the tunnel start on boot, so a VPS reboot does not silently kill your VPN. On the laptop, import laptop.conf into the WireGuard app or bring it up from the terminal with sudo wg-quick up laptop.

Verify from the server first:

sudo wg show

You should see the interface, the listening port, your peer’s public key, a latest handshake timestamp from the last couple of minutes, and transfer counters that grow as traffic flows. No handshake means the client never reached the server — go straight to the troubleshooting section below.

Then verify from the laptop that your traffic actually exits through the VPS:

curl https://ifconfig.me

It should print your VPS’s public IP, not your home IP. If it does, the tunnel works end to end.

Add your phone with a QR code

Typing a 44-character key into a phone is nobody’s idea of fun. Generate the config file for the phone (tunnel address 10.8.0.3/32, its own keypair), add its [Peer] block to the server config, then render it as a QR code the official app can scan:

sudo apt install -y qrencode
qrencode -t ansiutf8 < phone.conf

Scan it from the WireGuard app on iOS or Android and the tunnel is configured. One thing to remember: editing wg0.conf does not apply live. Restart the interface after adding a peer:

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

Or add the peer without dropping the tunnel using wg set wg0 peer <PUBLIC_KEY> allowed-ips 10.8.0.3/32 — handy when other clients are connected.

Full tunnel vs split tunnel

The only difference between the two is one line in the client config: AllowedIPs. On the client it acts as a routing table; on the server it acts as an access list.

Mode Client AllowedIPs Use it when
Full tunnel 0.0.0.0/0 Public Wi-Fi, untrusted networks, or you want all traffic to exit from the VPS.
Split tunnel 10.8.0.0/24 You only need private access — an admin panel, a database, a monitoring dashboard — and everything else should go direct.

One leak to watch for: if the client has IPv6 and your tunnel is IPv4-only, IPv6 traffic bypasses the tunnel entirely. Either add ::/0 to the client’s AllowedIPs with an IPv6 tunnel address, or disable IPv6 on the client while the tunnel is up.

WireGuard vs OpenVPN: the honest comparison

WireGuard OpenVPN
Setup One short config file per side Certificate authority, certs, revocation lists
Codebase ~4,000 lines, easily auditable Large, plus OpenSSL
Transport UDP only, one port TCP or UDP
Authentication Public keys, like SSH Certificates
Roaming Built in — IP changes don’t break the tunnel Reconnects on network change
Speed In-kernel encryption Userspace encryption

OpenVPN still wins in two situations: networks that block UDP outright (OpenVPN can run over TCP 443, which looks like HTTPS), and enterprise setups that need its mature access-control tooling. For a personal VPN on your own VPS, WireGuard is the simpler, faster choice.

Troubleshooting: the four failures everyone hits

1. The handshake never completes. wg show shows the peer but no latest handshake. The client never reached the server. Check, in order: the Endpoint IP and port in the client config, the server’s public key pasted into the client config, ufw allow 51820/udp, and your provider’s cloud firewall. A typo in any one of these produces exactly this symptom.

2. Handshake works, but nothing loads. The tunnel is up and the crypto works, but packets die on the server. Check forwarding with sysctl net.ipv4.ip_forward (it must print 1), the UFW forward policy from step 4, and that the MASQUERADE rule exists with sudo iptables -t nat -L POSTROUTING -n -v.

3. Sites load by IP but names don’t resolve. The DNS line is missing or wrong in the client config. Add DNS = 1.1.1.1 to the client’s [Interface] section.

4. The tunnel drops when you switch networks or after idle time. Your NAT mapping expired. Set PersistentKeepalive = 25 in the client’s [Peer] section, as in step 5.

One more: if pings work but web pages hang halfway, suspect MTU. wg-quick sets the tunnel MTU to 1420 on a standard 1500-byte link; if your path is smaller, add MTU = 1280 to the client’s [Interface] section.

What a personal VPN does (and doesn’t) do

A personal VPN encrypts traffic between your device and your VPS. On public Wi-Fi, that is the whole game: nobody on the network can read or tamper with your traffic. It also hides your browsing from your local network and ISP, and your traffic exits the internet from your VPS’s IP address.

What it does not do is make you anonymous. Your VPS provider can see the traffic leaving the server, exactly as a commercial VPN provider could. The difference is that you chose the operator — yourself — and you can read the config to confirm what is logged (nothing, by default; WireGuard keeps no logs of its own). It also does nothing against malware, phishing, or tracking cookies. A VPN is a tunnel, not a force field.

That is the honest trade: for the price of a VPS you already rent, you get a private VPN with no subscription, no device limit, and no trust-me brochure. Fifteen minutes, one config file, and the tunnel is yours.

Further Reading & References

Leave a Comment