WireGuard VPN Setup for Remote Access to a Home Server
You want to reach your home server from a laptop on hotel Wi-Fi, but opening SSH, a dashboard and a file share to the whole internet feels like asking for trouble.

You want to reach your home server from a laptop on hotel Wi-Fi, but opening SSH, a dashboard and a file share to the whole internet feels like asking for trouble. A WireGuard VPN setup solves that with one UDP port, a few short config files and a tunnel that only your own devices can use.
This guide walks through a working WireGuard VPN setup on a Debian or Ubuntu server, adds a phone and a laptop as clients, and covers the mistakes that cost people an evening. Budget about 40 minutes the first time and under 10 minutes for every device after that.
Why WireGuard VPN setup beats exposing services one by one
Every service you forward through your router is another login page bots will find within hours. On a fresh public IP, scanners usually hit port 22 inside the first day. A VPN flips the model: the server answers on one port, and WireGuard silently drops any packet that is not signed with a known key. To a scanner, the port looks closed.
WireGuard is also small. The kernel module is roughly 4,000 lines of code, compared with hundreds of thousands for older VPN stacks, which makes it easier to audit and quicker to set up. It has shipped in the mainline Linux kernel since version 5.6, so on any current distribution there is nothing to compile.
If you have not yet worked through what to check before exposing a home server online, read that first. A VPN reduces your attack surface, but it does not fix weak passwords or unpatched software inside the tunnel.
What you need before you start
- A Linux server at home with a static LAN address, for example 192.168.1.20.
- Access to your router to forward one UDP port. The default is 51820.
- Either a static public IP or a dynamic DNS name that tracks your home address.
- The WireGuard app on each client. It is free on Android, iOS, Windows, macOS and Linux.
Pick a tunnel subnet that will never clash with networks you visit. Avoid 192.168.0.0/24 and 192.168.1.0/24, because half the cafes in the world use them. Something like 10.66.66.0/24 is a safe choice.
Step by step WireGuard VPN setup on the server
Install and generate keys
Run sudo apt install wireguard. Then create a key pair in /etc/wireguard with wg genkey | tee server.key | wg pubkey and save the printed public key as server.pub, and set the private key file to mode 600 so only root can read it. Repeat the same command on each client, or generate client keys on the server and move them over carefully.
Write the server config
Create /etc/wireguard/wg0.conf with an Interface section containing the server private key, Address = 10.66.66.1/24 and ListenPort = 51820. Then add one Peer section per device, each with that device's public key and a single AllowedIPs entry, such as 10.66.66.2/32 for the laptop and 10.66.66.3/32 for the phone.
That /32 matters. AllowedIPs on the server is both a routing table and an access list. If you give a peer a whole /24 by mistake, it can claim any address in the tunnel.
Turn on forwarding and start the tunnel
If clients should reach other machines on your LAN, enable IP forwarding by setting net.ipv4.ip_forward=1 in /etc/sysctl.d/99-wireguard.conf and running sudo sysctl -p /etc/sysctl.d/99-wireguard.conf. Add PostUp and PostDown lines with a masquerade rule for your LAN interface. Then run sudo systemctl enable wg-quick@wg0 followed by sudo systemctl start wg-quick@wg0 so the tunnel starts now and survives reboots.
Finally, forward UDP 51820 on your router to 192.168.1.20. Nothing else needs to be open.
Adding a laptop and a phone as clients
A client config has its own Interface section with its private key and Address = 10.66.66.2/24, plus one Peer section for the server. That peer entry holds the server public key, an Endpoint line with your dynamic DNS hostname and port 51820, and an AllowedIPs line that decides what goes through the tunnel.
You have two choices for AllowedIPs on the client:
| Mode | AllowedIPs value | What happens |
|---|---|---|
| Split tunnel | 10.66.66.0/24, 192.168.1.0/24 | Only home traffic uses the VPN; browsing stays local and fast. |
| Full tunnel | 0.0.0.0/0 | All traffic goes through your home connection, useful on untrusted Wi-Fi. |
For phones, install qrencode on the server and run qrencode -t ansiutf8 -r phone.conf. Scan the code in the WireGuard app and you are done in about 30 seconds. Delete the phone config file from the server afterwards, since it contains a private key.
Add PersistentKeepalive = 25 on mobile clients. Phones sit behind carrier NAT that forgets idle mappings after roughly 30 to 60 seconds, and a keepalive every 25 seconds stops the tunnel going quiet.
The common advice to skip: running a VPN on your router
Plenty of guides tell you to run WireGuard on your consumer router because it is "always on." In practice, that is often the worse option. Many stock router firmwares ship a WireGuard build that lags years behind on updates, cap throughput at 100 to 200 Mbps because of weak CPUs, and hide the config behind a web page that makes key rotation painful.
A small Linux box at home, even an old mini PC drawing 8 watts, will push close to line speed on a gigabit connection and gets security patches with your normal apt upgrades. Router-based VPNs make sense if you run OpenWrt or a proper firewall distribution. On a typical ISP router, keep the VPN on the server. If power draw worries you, our breakdown of home server power cost per year puts that mini PC at well under the price of a monthly VPN subscription.
Testing and troubleshooting the tunnel
Run sudo wg show on the server. A healthy peer shows a "latest handshake" within the last two minutes and growing transfer counters. If there is no handshake at all, the problem is almost always one of these:
- The router forward points at the wrong LAN IP or uses TCP instead of UDP.
- Public and private keys were swapped when copying them between files.
- Your ISP uses CGNAT, so your router never sees inbound traffic. Check by comparing the WAN IP on the router with what a "what is my IP" page shows. If they differ, you need a small VPS relay or an IPv6 endpoint.
- A firewall such as ufw on the server is blocking 51820. Allow it with sudo ufw allow 51820/udp.
If the handshake works but you cannot reach LAN devices, forwarding or the masquerade rule is missing. Once everything works, put services like your dashboard behind the tunnel only, and use a reverse proxy on the home server for the few things that genuinely need to be public.
Frequently asked questions
Is WireGuard safe to expose to the internet?
Yes, it is one of the safer things you can expose. WireGuard does not respond to packets that are not authenticated with a known key, so scanners get no reply at all. Keep the server patched and protect the private keys, because anyone holding a client key has access.
Does WireGuard work behind CGNAT?
Not directly for inbound connections, because your router has no public IPv4 address to receive them. The usual fixes are using IPv6 if your ISP provides it, asking the ISP for a public IP, or relaying through a small VPS that costs around 4 to 5 dollars a month.
How many devices can connect to one WireGuard server?
Practically, hundreds, since each peer is just a public key and an IP entry. For a home setup with 5 to 10 devices, CPU use is tiny. The real limit is your home upload speed when several clients use a full tunnel at once.
More in Self Hosting
Self Hosting
Dynamic DNS Setup to Reach Your Home Server by Name
The server at home is fine. The router is fine. What broke is the sentence you memorised two months ago, the one with four...
Self Hosting
Minecraft Server on a Mini PC: RAM, Flags and Backups
The server my friends play on is a fanless Intel N100 mini PC that cost $155, sits on a shelf behind the router, and has been...
Self Hosting
Updating Self Hosted Containers Without Breaking Them
Nothing on the server is broken, which is exactly why the Nextcloud container on mine spent fourteen months running an image I...