How to Set Up WireGuard VPN
Self-host a WireGuard VPN to reach your homelab securely from anywhere: wg-easy in Docker, a manual wg-quick setup, split vs full tunnel, DNS, CGNAT and troubleshooting.
Why WireGuard
The safest way to reach your home server from outside is not to expose each service to the internet, but to connect into your network through a VPN. WireGuard is the modern choice: it's extremely fast, uses state-of-the-art cryptography, and has tiny, readable configs. Once connected, you use your services exactly as if you were at home. Read the secure remote access guide for how a VPN fits next to reverse proxies and tunnels.
This tutorial shows two routes: wg-easy, a container that gives WireGuard a simple web UI and QR codes for clients, and a manual setup with the standard tools so you understand what is happening.
How WireGuard works (30-second version)
Each device has a key pair. The server lists the public keys of the clients allowed to connect and assigns each an address inside a private VPN subnet (for example 10.8.0.0/24). A client sends encrypted UDP packets to the server's public address and port. If a packet doesn't come from a known key, the server stays silent — a port scan sees nothing, which is part of WireGuard's appeal.
Prerequisites
- A server reachable from the internet — either a public IP with port forwarding, or a small cloud VPS as an entry point. If your ISP uses CGNAT you cannot port-forward; use Tailscale or a VPS relay instead (see Tailscale vs WireGuard).
- A dynamic DNS hostname if your home IP changes (see Dynamic DNS).
- Docker for the wg-easy route.
- A static address or DHCP reservation for the server (see the networking guide).
Step 1: Forward the WireGuard port
On your router, forward UDP port 51820 to your server. WireGuard uses UDP only. Don't forward anything else for the VPN, and especially not the web UI.
Route A: wg-easy in Docker
Deploy wg-easy
The wg-easy project changed its configuration style between major versions. This example uses version 14, which is configured with environment variables, and pins it so a future major update doesn't surprise you. If you use version 15 or later, follow that version's setup wizard and documentation instead.
services:
wg-easy:
image: ghcr.io/wg-easy/wg-easy:14
container_name: wg-easy
restart: unless-stopped
environment:
- WG_HOST=vpn.example.com # your public hostname or IP
- PASSWORD_HASH=${WG_PASSWORD_HASH}
- WG_DEFAULT_DNS=192.168.1.10 # your Pi-hole/AdGuard, optional
ports:
- "51820:51820/udp"
- "127.0.0.1:51821:51821/tcp" # web UI, local only
volumes:
- ./config:/etc/wireguard
cap_add:
- NET_ADMIN
- SYS_MODULE
sysctls:
- net.ipv4.ip_forward=1
- net.ipv4.conf.all.src_valid_mark=1Set WG_HOST to how clients reach you. Generate a bcrypt hash for the web UI password and put it in a .env file as WG_PASSWORD_HASH. In a .env file you must double every $ in the hash ($$). Start it:
docker compose up -dCreate clients
Open the web UI. Because it's bound to localhost here, reach it through an SSH tunnel (ssh -L 51821:localhost:51821 user@server) or temporarily bind it to your LAN address. Create a client for each device. wg-easy shows a QR code:
- Phone: install the WireGuard app and scan the QR code.
- Laptop: download the config file and import it into the WireGuard client.
Route B: manual setup with wg-quick
On Debian or Ubuntu, you can run WireGuard natively without Docker.
sudo apt install wireguard
umask 077
wg genkey | tee server.key | wg pubkey > server.pub
wg genkey | tee phone.key | wg pubkey > phone.pubCreate /etc/wireguard/wg0.conf on the server (replace eth0 with your network interface, and the keys with the contents of the files):
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of server.key>
PostUp = sysctl -w net.ipv4.ip_forward=1; 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
[Peer]
# phone
PublicKey = <contents of phone.pub>
AllowedIPs = 10.8.0.2/32And the matching client config:
[Interface]
Address = 10.8.0.2/32
PrivateKey = <contents of phone.key>
DNS = 192.168.1.10
[Peer]
PublicKey = <contents of server.pub>
Endpoint = vpn.example.com:51820
AllowedIPs = 192.168.1.0/24, 10.8.0.0/24
PersistentKeepalive = 25Start and enable the tunnel on the server:
sudo systemctl enable --now wg-quick@wg0
sudo wg showKeep private keys secret and give every device its own key pair.
Choose split vs. full tunnel
Each client's AllowedIPs decides what goes through the VPN:
- Split tunnel (
AllowedIPs = 192.168.1.0/24) — only home-network traffic uses the VPN; your normal browsing goes out directly. Best for everyday remote access and saves your home upload bandwidth. - Full tunnel (
AllowedIPs = 0.0.0.0/0, ::/0) — all traffic routes through home. Useful on untrusted Wi-Fi and to use your Pi-hole everywhere. Your home upload speed becomes your phone's bandwidth.
Test it
Turn off Wi-Fi on your phone (use mobile data), enable the WireGuard tunnel, and try reaching an internal service by its LAN IP or internal hostname. If it loads, you're done — your homelab is now reachable securely from anywhere. On the server, sudo wg show lists each peer's latest handshake; a recent handshake means the tunnel is up.
WireGuard vs. Tailscale
wg-easy and manual WireGuard are self-hosted with full control. If you want automatic NAT traversal without port forwarding and near-zero setup, Tailscale (which is built on WireGuard) is worth considering — see Tailscale vs WireGuard.
Security notes
- Keep the wg-easy web UI off the internet — only 51820/udp should be forwarded.
- Give each device its own client config so you can revoke one without disrupting others. Remove the peer when a phone is lost.
- Consider routing clients' DNS through your Pi-hole for ad blocking on the go.
- Keep the host updated, and restrict what VPN clients can reach with firewall rules if some devices shouldn't see everything. See the security checklist.
- Monitor that the VPN is reachable with Uptime Kuma.
Troubleshooting
- Handshake but no traffic — check
AllowedIPson both sides and that IP forwarding is enabled. Check the firewall FORWARD rules. - No handshake at all — the UDP port isn't forwarded, a firewall blocks it, you're behind CGNAT, or
WG_HOST/Endpointis wrong. Test from outside your network. - Works on Wi-Fi, not mobile — confirm the public hostname/IP resolves from outside your network.
- Can reach the server but not other LAN devices — enable forwarding and NAT (the
PostUprules above), or add a route on your router for the VPN subnet. - Websites slow or break with full tunnel — lower the MTU (for example
MTU = 1280) on the client. - Home IP changed — use dynamic DNS, and keep the endpoint as a hostname.
Next steps
With a VPN in place, you can safely keep dashboards like Portainer and Proxmox internal-only, exposing nothing to the public internet.
Artículos relacionados
How to Install Nginx Proxy Manager
Install Nginx Proxy Manager with Docker, add proxy hosts and free Let's Encrypt certificates, use DNS challenges for internal names, add access lists and avoid common mistakes.
How to Set Up Caddy as a Reverse Proxy
Set up Caddy in Docker for automatic HTTPS in front of your homelab: Caddyfile examples, shared Docker networks, DNS-challenge certificates for internal names, auth, headers and troubleshooting.
Secure Remote Access to Your Home Server
Reach your homelab from anywhere without exposing risky ports: compare VPNs, Tailscale, reverse proxies and tunnels, handle CGNAT, and follow a safe blueprint.