WireGuard in 15 minutes
This guide turns an Ubuntu 24.04 VPS into a working WireGuard VPN server, with a first mobile client. No prior networking knowledge required.
Step 1 — Installation
apt update && apt install -y wireguard qrencodeStep 2 — Server keys
cd /etc/wireguard
wg genkey | tee server.key | wg pubkey > server.pub
chmod 600 server.keyStep 3 — Server configuration
Create /etc/wireguard/wg0.conf:
[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = <server.key contents>
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(Check the network interface name with ip route | grep default — replace eth0 if needed.)
Step 4 — IP forwarding
Uncomment net.ipv4.ip_forward=1 in /etc/sysctl.conf, then sysctl -p.
Step 5 — Start and enable at boot
systemctl enable --now wg-quick@wg0Step 6 — Add a client
wg genkey | tee client1.key | wg pubkey > client1.pubAdd the peer on the server:
[Peer]
PublicKey = <client1.pub>
AllowedIPs = 10.0.0.2/32On the client (file or mobile app):
[Interface]
PrivateKey = <client1.key>
Address = 10.0.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = <server.pub>
Endpoint = <VPS-IP>:51820
AllowedIPs = 0.0.0.0/0Generate the QR code: qrencode -t ansiutf8 < client1.conf — scan from the WireGuard app, connected.
Verification
On the client: curl ifconfig.me should show the VPS IP. wg show on the server displays the handshake.