How do you set up WireGuard on a VPS?
Straight answer
To set up WireGuard on a VPS, install the wireguard package, generate a key pair for the server and one per device, write /etc/wireguard/wg0.conf with a private subnet and UDP port 51820, enable IP forwarding and NAT, then start wg-quick@wg0. On a BuyMoneroVPS Ring 1 server it takes about 20 minutes.
In brief
- WireGuard needs one key pair per side: the server knows each device's public key, and each device knows the server's.
AllowedIPs = 0.0.0.0/0on the device sends all its IPv4 traffic through the VPS.- The VPS must forward packets (
net.ipv4.ip_forward = 1) and masquerade them behind its public IP. systemctl enable wg-quick@wg0brings the tunnel up at every boot.
What will this setup do?
It turns the VPS into a private gateway: your laptop or phone sends its traffic through an encrypted tunnel and leaves the internet from the server's IP. The server listens on one UDP port, 51820 here, and gives each device an address in a private subnet, 10.8.0.0/24. Nothing else is exposed.
This is a personal VPN for your own devices, not a service sold to others. Ubuntu's WireGuard pages call this layout "using the VPN as the default gateway". Its main cost is traffic: everything you browse counts against the plan, so Ring 1's 2 TB a month or Ring 2's 4 TB matter more than the CPU. The WireGuard VPN use case compares the plans and cities for this job; this guide is the setup.
What are the steps on the server and the device?
Prepare the server
Order a Debian or Ubuntu VPS, update it and log in with a key. Note the name of the public interface with ip route; it is often eth0 or ens3.
Install WireGuard and make the server keys
Install the wireguard package. Under umask 077, run wg genkey and wg pubkey to create the server's private and public keys.
Make a key pair for each device
Generate one pair per laptop or phone, on the device or on the server. Each device's public key goes into the server file; its private key stays on the device.
Write the server configuration
Create /etc/wireguard/wg0.conf with the server's private key, the address 10.8.0.1/24, ListenPort 51820, NAT rules in PostUp and PostDown, and one [Peer] block per device.
Turn on IP forwarding
Write net.ipv4.ip_forward = 1 to a file in /etc/sysctl.d/ and load it, so the server routes packets between the tunnel and the internet.
Open the port and start the tunnel
Allow 51820/udp in the firewall, then run systemctl enable --now wg-quick@wg0. Check the result with wg show.
Configure the device and connect
Import the client file into the WireGuard app, or bring it up with wg-quick on Linux. Open a website that shows your IP: it should show the VPS address.
apt update && apt install -y wireguard iptables
cd /etc/wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee laptop.key | wg pubkey > laptop.pub
ip route show default # note the interface name after "dev"[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of server.key>
PostUp = iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
[Peer]
# laptop
PublicKey = <contents of laptop.pub>
AllowedIPs = 10.8.0.2/32echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/70-wireguard-routing.conf
sysctl -p /etc/sysctl.d/70-wireguard-routing.conf
ufw allow 51820/udp
systemctl enable --now wg-quick@wg0
wg show[Interface]
PrivateKey = <contents of laptop.key>
Address = 10.8.0.2/24
DNS = 9.9.9.9
[Peer]
PublicKey = <contents of server.pub>
Endpoint = 203.0.113.10:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25What does each setting in the files do?
| Setting | Where | Role |
|---|---|---|
| Address | Both sides | Tunnel IP of that side, with its subnet |
| ListenPort | Server | UDP port the server listens on (51820 here) |
| PostUp / PostDown | Server | Commands run when the tunnel goes up or down, here the NAT rule |
| AllowedIPs | Server peer block | The single tunnel IP that device may use |
| AllowedIPs = 0.0.0.0/0 | Client | Send all IPv4 traffic through the tunnel |
| Endpoint | Client | Public IP and port of the VPS |
| PersistentKeepalive | Client | Keeps the tunnel open behind home routers |
What if traffic does not flow through the tunnel?
Check, in order: the handshake, forwarding, NAT and the firewall's forward policy. Run wg show on the server. If the peer has no "latest handshake", the device cannot reach UDP 51820: the port is closed, the endpoint IP is wrong, or the keys are swapped. A handshake with no internet access points to routing: confirm that sysctl net.ipv4.ip_forward prints 1 and that the MASQUERADE rule names the real interface.
Ufw adds one trap. When it is active, its default forward policy drops routed packets. Ubuntu's firewall page shows the fix used for masquerading: set DEFAULT_FORWARD_POLICY="ACCEPT" in /etc/default/ufw, then reload ufw. The ufw firewall guide explains the rules around it.
To add a phone later, generate a new pair, give it 10.8.0.3, add a [Peer] block and run systemctl reload wg-quick@wg0; Ubuntu's common-tasks page notes that the reload keeps existing tunnels up.
Which plan and city should you pick?
Ring 1 is enough for one or two people; pick the city closest to you, or the jurisdiction you prefer. For a personal tunnel, monthly traffic usually runs out before CPU does: 2 TB on Ring 1, 4 TB on Ring 2, 8 TB on Ring 4.
According to BuyMoneroVPS's survey of 30 November 2026, Ring 1 costs $3.78 where the nearest comparable Monero-friendly offer, Kyun, asks €3.70 ($4.05). Ring plans run in Amsterdam, Reykjavik, Zurich and Bucharest; for a US exit, Hub 2 in New York, Dallas or Los Angeles starts at $6.04. The pricing page lists every size, and securing a new Linux VPS should come before this guide.
Frequently asked questions
Can I use another port than 51820?
Yes. Any free UDP port works; Ubuntu's own examples use 51000. Change ListenPort on the server, the Endpoint on each device and the firewall rule together.
Does the VPN hide everything I do?
No. It hides your traffic from your local network and your internet provider, but websites see the VPS address, and BuyMoneroVPS knows which account rents that IP. Use it for privacy on public Wi-Fi and for a stable exit address.
How do I add IPv6?
Each BuyMoneroVPS server has a /64 of IPv6. Give the tunnel an IPv6 range in Address, add ::/0 to the client's AllowedIPs and enable IPv6 forwarding. Test IPv4 first, then add IPv6.
Can several people share one VPS?
Yes, each with their own key pair and [Peer] block. Keep it to people you know: the account holder answers for all traffic under the acceptable use policy.
Verdict
- WireGuard on a Ring 1 VPS is a 20-minute job with five commands and two small files.
- Forwarding and NAT are the two lines people forget; check them first when traffic stalls.
- Pick the plan by monthly traffic, not by CPU.
Sources (5)
- Quick Start — WireGuard (read 2026-11-30)
- wg-quick(8) manual — wireguard-tools (read 2026-11-30)
- Using the VPN as the default gateway — Ubuntu Server documentation (read 2026-11-30)
- Common tasks in WireGuard VPN — Ubuntu Server documentation (read 2026-11-30)
- Firewall — Ubuntu Server documentation (read 2026-11-30)
Run your own WireGuard gateway
Ring 1: 1 vCPU · 1 GB memory · 20 GB NVMe disk · 2 TB monthly transfer, one IPv4 and a /64 of IPv6, paid in Monero.