RBRunbook
Networking

How to Set Up a Personal VPN Server Instead of Paying for One

A self-hosted VPN gives you the core benefit — encrypted traffic on public Wi-Fi — without a monthly subscription, using a $5/month VPS.

DifficultyIntermediate
Time20–30 min
PlatformLinux VPS
CategoryNetworking

Commercial VPN services bundle two different things: encrypting your traffic on untrusted networks, and masking your location behind a shared pool of IPs to get around geographic restrictions. A self-hosted VPN gives you the first, fully and for a few dollars a month in server costs — but not the second, since the traffic still exits from a server that's identifiably yours, not a shared pool. If your goal is "encrypt my traffic on coffee shop Wi-Fi," this is a complete solution.

01Get a cheap VPS

Any provider works — DigitalOcean, Linode, Hetzner, Vultr all offer VPS instances for around $4-6/month, which is more than enough for personal VPN traffic. Choose a location close to where you'll actually be using it, for lower latency.

02Install WireGuard

WireGuard is the modern standard for this — simpler to configure and faster than older options like OpenVPN.

sudo apt update && sudo apt install wireguard

03Generate server keys

wg genkey | sudo tee /etc/wireguard/server_private.key | wg pubkey | sudo tee /etc/wireguard/server_public.key

04Create the server config

sudo nano /etc/wireguard/wg0.conf
[Interface]
PrivateKey = [contents of server_private.key]
Address = 10.0.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

Enable IP forwarding so the server can route your traffic onward to the internet:

echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

05Add a client (your phone or laptop)

Generate a key pair for the client the same way as Step 3, then add a peer block to wg0.conf:

[Peer]
PublicKey = [client's public key]
AllowedIPs = 10.0.0.2/32

On the client side, use the official WireGuard app (available for iOS, Android, Windows, macOS) and create a matching config pointing at your server's public IP and port 51820.

06Start it and open the firewall port

sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0
sudo ufw allow 51820/udp

07Test it

Connect from your client device and check your IP at any "what's my IP" site — it should show your VPS's IP address, confirming traffic is routing through the server.

Honest tradeoff versus a commercial VPN Your self-hosted VPN's IP is uniquely yours and unchanging, which is actually worse for privacy from the destination site's perspective than a commercial VPN's shared IP pool — sites can still identify and track "your" IP over time, they just can't see your ISP or physical location as easily. For the specific goal of securing traffic on untrusted networks, this setup is complete; for anonymity from the sites you visit, it isn't equivalent to a commercial service.
JM
Written by Jordan Malik Senior Editor, Systems & Networking — guide tested on a live Linux VPS setup before publishing
Last verified: July 2026