How to Set Up a Personal VPN WireGuard VPS in 15 Minutes
Public Wi-Fi is a bad place to send your traffic in the clear. A personal vpn wireguard vps setup fixes that: your phone or laptop connects to a server you control, and everything between the two is encrypted. WireGuard is the simplest tool for the job: it has a small codebase, it is fast to configure, and it is already in the Linux kernel. This guide walks you through the whole vpn server setup on Ubuntu, from installing the package to connecting your first client, in about fifteen minutes.
Why Run Your Own VPN on a VPS
A commercial VPN rents you a shared server and asks you to trust its no-logs claim. When you run your own VPN, there is no third party to trust: the server is yours, the keys are yours, and the logs are whatever you decide to keep, which should be nothing. You also get a stable IP address that belongs to your VPS, and the cost is the VPS you already pay for, so the VPN adds no monthly bill.
WireGuard fits this job better than older tools like OpenVPN because the config is short and the crypto is modern by default. There is no certificate authority to run, and the tunnel comes up in seconds. If you can edit a text file and run a few commands, you can run WireGuard.
Personal VPN WireGuard VPS: What You Need Before You Start
You need a VPS running Ubuntu 22.04 or newer, a user account with sudo access, and SSH access to the server. You also need a client device, such as a laptop or a phone, with the WireGuard app installed. Pick a UDP port for the tunnel; 51820 is the default and works fine.
Before you start, open that UDP port in your server firewall. With UFW:
sudo ufw allow 51820/udp
If you have not hardened your server yet, read our first 10 things to do after buying a VPS first. A VPN server is a public service, so it should sit on a server that is already locked down.
Step 1: Install WireGuard on Ubuntu
A wireguard install ubuntu setup takes one command:
sudo apt update && sudo apt install -y wireguard
That is the whole install. The package brings the kernel module and the wg and wg-quick tools. Check that the module loaded:
sudo wg --version
If it prints a version number, WireGuard is ready. No third-party repository is needed on Ubuntu 22.04 and newer.
Step 2: Generate Keys and Write the Server Config
WireGuard identifies each peer by a public key, so generate a key pair for the server first:
umask 077
wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub
The umask makes sure the private key file is readable only by root. Never share the private key; the public key is safe to copy anywhere, and you will need it in the client config later.
Generate a key pair for your first client device the same way, on the VPS:
wg genkey | tee /etc/wireguard/client.key | wg pubkey > /etc/wireguard/client.pub
Read both public keys so you can paste them into the configs:
cat /etc/wireguard/server.pub
cat /etc/wireguard/client.pub
Next, write the server config. This file is the wg0 interface definition, so it lives at /etc/wireguard/wg0.conf. Open it with your editor:
sudo nano /etc/wireguard/wg0.conf
Paste the following, replacing the placeholders with your real keys. The server takes 10.6.0.1 inside the tunnel, and the client gets 10.6.0.2:
[Interface]
Address = 10.6.0.1/24
ListenPort = 51820
PrivateKey = <server-private-key>
SaveConfig = true
[Peer]
PublicKey = <client-public-key>
AllowedIPs = 10.6.0.2/32
The AllowedIPs line says which tunnel addresses this peer may use. Keeping it to a single /32 address per peer means one client cannot claim another client’s address.
Step 3: Turn On Forwarding and Add the Client Config
The tunnel alone only connects the client to the server. To reach the internet through the VPS, the server must forward traffic and hide it behind its own public IP with NAT. First, turn on IPv4 forwarding:
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Then add a NAT rule so traffic leaving the tunnel gets the server’s public IP. Find your server’s main interface name first, usually eth0 or ens3, with ip route | grep default, then add the rule:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Make the rule survive a reboot:
sudo apt install -y iptables-persistent
sudo netfilter-persistent save
Now write the wireguard client config on your laptop or phone, in a file named client.conf, replacing the placeholders with your real keys and your server’s public IP or domain:
[Interface]
Address = 10.6.0.2/24
PrivateKey = <client-private-key>
DNS = 1.1.1.1
[Peer]
PublicKey = <server-public-key>
Endpoint = your-server-ip:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
The AllowedIPs = 0.0.0.0/0 line on the client sends all traffic through the tunnel. If you only want to reach your home network through the VPN and keep the rest of your traffic direct, use a smaller range such as 10.6.0.0/24 instead. PersistentKeepalive = 25 sends a small packet every 25 seconds so the connection stays alive behind NAT, which matters most on phones that switch between Wi-Fi and mobile data. If your goal is to reach a home lab rather than the whole internet, our guide on how to set up WireGuard to access your homelab remotely covers that exact setup, and if you are weighing WireGuard against a mesh tool, read Tailscale vs WireGuard for remote homelab access first.
Step 4: Start the Tunnel and Test It
Start the server side with wg-quick:
sudo wg-quick up wg0
Once your personal vpn wireguard vps tunnel is running, check that the wg0 interface is up and the peer is listed:
sudo wg show
The output should show the interface, the listening port, and your peer. If the peer shows no handshake yet, that is normal: the handshake happens when the client connects.
Make the tunnel start on boot so a reboot does not leave you without a VPN:
sudo systemctl enable wg-quick@wg0
Now import the client config. On a laptop, run sudo wg-quick up ./client.conf from the folder holding the file, or import it into the WireGuard desktop app. On a phone, open the WireGuard app, tap the plus button, and import the file or scan a QR code. Then check your public IP from the client: it should now match your VPS IP. You can also ping the server through the tunnel:
ping 10.6.0.1
If the ping answers and your public IP is the server’s IP, the VPN works. Browse to a site that shows your IP address and confirm it lists your VPS, not your home or mobile connection.
Common Problems and Fixes
If the client never handshakes, the usual cause is the firewall. Confirm UDP port 51820 is open on the VPS and in your hosting provider’s firewall panel, if it has one. A wrong endpoint IP or a typo in a public key gives the same symptom, so compare the keys and check the endpoint.
If the tunnel connects but no websites load, the NAT rule is the first suspect. Run sudo iptables -t nat -L POSTROUTING -n and check that the MASQUERADE rule is there and names the right interface. Also confirm IP forwarding is on: sysctl net.ipv4.ip_forward should print 1.
If the connection drops whenever your phone changes networks, the keepalive is probably missing. Add PersistentKeepalive = 25 to the [Peer] section of the client config and reconnect. If you locked yourself out of SSH while changing firewall rules, log in through your provider’s web console, fix the rule, and test again. For the key-only login setup that keeps SSH safe, see our guide to disable password login and use SSH keys only.
What to Do Next After Your VPN Is Up
A personal vpn wireguard vps setup is a small piece of infrastructure that pays for itself every time you join a public network. Add a second peer for your phone by generating another key pair and appending another [Peer] section to wg0.conf, with a new address such as 10.6.0.3. Restart the interface with sudo wg-quick down wg0 && sudo wg-quick up wg0 after editing.
Keep the server updated with regular apt update && apt upgrade runs, and keep a backup of /etc/wireguard/ somewhere safe, since losing the private keys means rebuilding every client config from scratch. Check the peer list with sudo wg show now and then: a peer with no recent handshake is a device you can remove. Fifteen minutes of setup gives you a private tunnel you control, on hardware you already pay for, with no subscription and no one else holding the keys.