I scanned the QR code, flipped the switch in the WireGuard app, and the toggle turned green. Then I opened a web page and it sat there loading. The tunnel was up and nothing was going through it.
That’s the usual failure on a fresh VPS, and almost every guide that leaves you here skips the same few things. The handshake only proves the keys match. Whether your packets actually reach the internet depends on the host: kernel forwarding, NAT, and a firewall that doesn’t eat them. That’s all plain Linux networking, and none of it is WireGuard’s job.
A quick word on what you’re building. A personal VPN gives you an encrypted tunnel from your phone to a server you control, with a stable IP on the far end. That protects you on café Wi-Fi and hostile networks. It isn’t anonymity. Your VPS provider can see traffic leaving the server, and websites see a datacenter address. You’re moving trust from the network you’re on to one host you picked, and that’s the whole trade.
One caveat before you pay for anything. Some container-based VPS plans don’t let you load kernel modules or change sysctl settings. Confirm with your host, or pick a KVM plan.
Install what Debian doesn’t give you #
Debian 13 ships WireGuard in its default repositories, and the module is already in the kernel. The wireguard package only pulls in the userland tools, wg and wg-quick.
sudo apt update && sudo apt install -y wireguard iptables qrencodeName iptables explicitly. On Debian 13 it’s marked optional, and wireguard-tools only recommends nftables or iptables, so a slim install can end up with nftables and no iptables. Without it the PostUp rules below fail when the tunnel comes up. qrencode is for the phone setup at the end.
Turn on forwarding #
Linux won’t pass packets between interfaces by default. Without forwarding, every packet from your phone ends at the server and goes nowhere. Put the setting in a drop-in file so it survives reboots and package changes:
echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-wireguard.conf
sudo sysctl --system
sysctl net.ipv4.ip_forwardThe last line should print net.ipv4.ip_forward = 1. I’m using sysctl --system because the plain sysctl -p form only reads /etc/sysctl.conf, not the drop-in directory.
Generate the keys #
/etc/wireguard ships with mode 0700, so a normal user can’t even cd into it. Become root for the key step. Also watch umask: it only applies to the shell session where you set it, so wrap each command in a subshell and the setting doesn’t leak into everything you run afterward.
sudo -i
cd /etc/wireguard
(umask 077; wg genkey | tee server_private.key | wg pubkey > server_public.key)
(umask 077; wg genkey | tee phone_private.key | wg pubkey > phone_public.key)The server needs its own private key and the phone’s public key. The phone’s private key is only here so we can build a QR code in a minute, and we’ll delete it afterward. If you’d rather it never exist on the server, create the tunnel from scratch in the WireGuard app, which generates the keypair on the phone, and paste the phone’s public key into the server config instead.
Write the server config #
Find the interface your server uses to reach the internet:
ip route show defaultThe name after dev is what you want, often eth0 or enp1s0. Then create /etc/wireguard/wg0.conf:
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of server_private.key>
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
[Peer]
# phone
PublicKey = <contents of phone_public.key>
AllowedIPs = 10.8.0.2/32Replace eth0 with your interface name, then lock the file down with chmod 600 /etc/wireguard/wg0.conf.
Each rule is there for a reason. %i expands to the interface name, so the rules follow the config file. The first FORWARD rule lets packets from the tunnel go out. The second lets replies come back in, which matters if your forward policy is stricter than the default. The MASQUERADE rule rewrites the phone’s private 10.8.0.2 source address to the server’s public one, so the internet can answer and the reply finds its way back. Limiting it to -s 10.8.0.0/24 means only VPN clients get NAT’d.
Open the port and mind the other firewalls #
WireGuard listens on UDP 51820. Open it in your provider’s firewall or security group, and in the host firewall if you run one. With ufw that’s sudo ufw allow 51820/udp.
Two things to check if you run other firewall software. ufw blocks forwarding by default even when ip_forward is on, but you don’t have to flip its global forward policy to ACCEPT. The FORWARD rules in PostUp already cover wg0, and that’s narrower than opening everything.
Docker is the other one. When Docker turns on IP forwarding, it sets the default policy of the iptables FORWARD chain to DROP. Rules added by other tools get evaluated after Docker’s own chains. If this VPS runs Docker too, check sudo iptables -L FORWARD -n -v when things don’t flow. Docker’s docs give two ways out: ACCEPT rules in the DOCKER-USER chain, or "ip-forward-no-drop": true in /etc/docker/daemon.json.
Start the tunnel #
systemctl enable --now wg-quick@wg0
wg showYou should see wg0 listening on port 51820 with the phone listed as a peer. There’s no handshake yet, because the phone hasn’t connected.
The phone config, and the IPv6 leak #
Create /root/phone.conf with the phone’s side of the tunnel:
[Interface]
PrivateKey = <contents of phone_private.key>
Address = 10.8.0.2/32
DNS = <a resolver you trust>
[Peer]
PublicKey = <contents of server_public.key>
Endpoint = <YOUR_VPS_PUBLIC_IP>:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25Three lines in there matter more than they look.
AllowedIPs = 0.0.0.0/0, ::/0 sends everything through the tunnel, and the ::/0 half is the one people leave out. If only IPv4 is listed, IPv6 traffic bypasses the tunnel and uses your native connection, exposing your real IPv6 address. Phones on carrier networks often have IPv6, so your “all traffic” VPN would leak a chunk of it. Adding ::/0 fixes the leak: with no IPv6 set up on the server, that traffic has nowhere to go, and apps fall back to IPv4. If you want working IPv6 through the VPS, the tunnel needs IPv6 addresses of its own, and with no routable prefix to hand out, the usual route is ULA addresses plus IPv6 masquerade on the server.
DNS decides who sees every site you look up. Pointing it at a big public resolver just moves your lookups to a company that isn’t your VPS host, which is fine if you choose it deliberately and not so fine if you copied it from a tutorial. Pick a resolver you trust, or run your own on the VPS and use 10.8.0.1.
PersistentKeepalive = 25 matters because your phone sits behind a carrier NAT. It’s recommended for clients behind NAT to prevent session drops, because the periodic packet keeps the NAT mapping alive so the server can reach you.
Get the config onto the phone #
chmod 600 /root/phone.conf
qrencode -t ansiutf8 < /root/phone.confOn Android, open the WireGuard app, tap the plus icon, and choose the QR scan option. On an iPhone, tap “Add a tunnel” and choose “Create from QR code.”
Treat that QR code like a password, because it contains the phone’s private key. Don’t screenshot it. When the scan is done, clear the terminal and delete the key and config files from the server (rm /etc/wireguard/phone_private.key /root/phone.conf). The server only ever needs the phone’s public key.
Check that traffic actually flows #
Turn the tunnel on in the app, then run wg show on the server. A working connection shows a recent latest handshake line and transfer counters that increase as you browse. Same signal in the app: data received and a latest handshake mean the connection is established.
Then test what matters. Visit any “what is my IP” page on the phone and confirm it shows your VPS address. Test an IPv6 page too, and a DNS leak test, since those are the two places a full tunnel quietly isn’t.
Add a second device #
Every device gets its own keypair and its own tunnel address. Don’t copy the phone’s config onto a laptop. Two devices sharing one key and one address fight over the same peer slot on the server, and each one keeps knocking the other off.
Generate a new keypair, give it the next address in the range, and add another block to wg0.conf on the server:
[Peer]
# laptop
PublicKey = <laptop public key>
AllowedIPs = 10.8.0.3/32The laptop’s own config is the phone config with its own private key and Address = 10.8.0.3/32. To load the new peer without dropping the phone, sync the running interface instead of restarting it:
wg syncconf wg0 <(wg-quick strip wg0)wg-quick strip removes the lines only wg-quick understands, like Address and PostUp, so plain wg accepts the file. syncconf applies just the difference, and peers that haven’t changed stay connected.
When it doesn’t work #
Start with what the server sees. No handshake at all usually means the UDP port is blocked somewhere, the endpoint IP is wrong, or the keys got swapped between files. Run sudo apt install -y tcpdump and then sudo tcpdump -ni any udp port 51820 while you toggle the tunnel on. If nothing arrives, the problem is upstream of WireGuard, meaning the firewall, security group, or address, not your config.
A handshake with no internet is the case from the top of this guide. Check sysctl net.ipv4.ip_forward, then sudo iptables -t nat -L POSTROUTING -n -v to see whether the masquerade rule exists and counts packets, then sudo iptables -L FORWARD -n -v for a DROP policy. A wrong interface name in PostUp is a classic: the rule loads fine and matches nothing.
If some sites load and others hang, suspect MTU. Lowering the MTU value in the phone’s [Interface] section is the usual fix, though I haven’t tested what number suits your network, so adjust it in steps.
A green toggle means the cryptography worked. Whether anything goes anywhere is a different question, and it’s answered in iptables, not in WireGuard.