Get started

Security

How to set up your own WireGuard VPN on a VPS

Build a private VPN on a small VPS: server and client keys, routing, firewall rules and a phone profile.

By LowCostServ · Updated November 12, 2026 · 3 min read

Val walks out of a glowing tunnel whose mouth is shaped like a shield, between two server racks.

A personal VPN is one of the best uses of a small VPS: your own exit point, no shared IP reputation, no provider reading your traffic. WireGuard is fast, modern and small enough to configure by hand. This guide uses Ubuntu or Debian on the server, the network 10.8.0.0/24 inside the tunnel, and 203.0.113.10 as the server’s public address.

1. Install WireGuard

sudo apt update
sudo apt install -y wireguard iptables qrencode

2. Create the keys

Each side has a private key, which never leaves it, and a public key, which the other side needs. Create both pairs on the server for now:

sudo -i
cd /etc/wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee phone.key | wg pubkey > phone.pub

3. Let the server route traffic

echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/99-wireguard.conf
sysctl --system

Find the name of the public network interface. It is the word after dev:

ip route show default

The examples below assume eth0. Replace it if yours is different, for instance ens3.

4. Write the server configuration

Create /etc/wireguard/wg0.conf. Paste the contents of server.key and phone.pub where indicated:

[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
PostUp = iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostUp = iptables -A FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
PostDown = iptables -D FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

[Peer]
# phone
PublicKey = PHONE_PUBLIC_KEY
AllowedIPs = 10.8.0.2/32

If you use ufw, open the port:

ufw allow 51820/udp

5. Start the tunnel

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

wg show lists the interface and its peer. The tunnel now starts at every boot.

6. Configure the first device

Still on the server, create /etc/wireguard/phone.conf with the contents of phone.key and server.pub:

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

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = 203.0.113.10:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

AllowedIPs = 0.0.0.0/0, ::/0 sends all traffic through the tunnel. For a phone, show the file as a QR code and scan it with the WireGuard app:

qrencode -t ansiutf8 < phone.conf

On a computer, copy the file over a secure channel and import it in the WireGuard application, or place it in /etc/wireguard/ on Linux and run wg-quick up phone.

7. Check that it works

  • Connect from the device, then run wg show on the server: a “latest handshake” line a few seconds old means the tunnel is up.
  • Open a “what is my IP” page on the device. It should show the server’s address.

Adding more devices

Each device gets its own key pair and its own address: 10.8.0.3, 10.8.0.4 and so on. Add a [Peer] block for it in wg0.conf, then apply the change without dropping existing connections:

wg syncconf wg0 <(wg-quick strip wg0)

When it does not work

SymptomLook at
No handshake at allUDP port 51820 closed by a firewall, a wrong Endpoint, or keys pasted in the wrong place
Handshake, but no internetIP forwarding not enabled, or the wrong interface name in the PostUp lines
Websites by IP work, names do notThe DNS line in the client configuration
It worked until the server rebootedsystemctl enable wg-quick@wg0 was skipped

Tidy up

Once the device is configured, delete its private key from the server: rm /etc/wireguard/phone.key /etc/wireguard/phone.conf. A private key belongs on one device only. And keep the server itself in shape: Secure a new Linux server in 15 minutes.

Sources and further reading

Your own server, in a few minutes.

Cloud VPS from $3.99 a month: no email, no ID, crypto payment, root access in minutes.

  • No KYCNo email, no ID
  • No DMCANotices not acted on
  • Crypto friendlyBTC, ETH, XMR, USDT, SOL
  • UnmeteredOn every plan

Client area

One key for your servers, your payments and your balance.

  • Nothing about you. No email, no name, no phone number, no ID.
  • Pay in crypto. BTC, ETH, XMR, USDT and SOL.
  • Up to +30% on top-ups. The bonus starts at $100.
  • Yours alone. We keep a fingerprint of your key, never the key itself.
How the access key works

Your account

No email, no password, no name. One access key.

New here? Create your access key