A WireGuard VPN on VPS hardware you run yourself gives you a private tunnel to the internet without trusting a third-party VPN company with your traffic. You control the server, the keys, and the logs, which in practice means you can choose to keep no logs at all. Setup takes under an hour once you know the steps, and the result is a fast, quiet tunnel that works on phones, laptops, and desktops.
WireGuard is a modern VPN protocol built into the Linux kernel. It is simpler than older protocols such as OpenVPN and IPsec, with far less code to audit and fewer settings to get wrong. That simplicity is the main reason it has become the default choice for self-hosted VPNs. This guide covers a single-server setup on Ubuntu, with one or more client devices connecting through it.
Before you start, you need a VPS with a public IP address, root or sudo access, and a domain name only if you want a memorable address for the server (an IP address works fine). Prices for small VPS plans vary by provider, so check official pricing for a plan with enough bandwidth for your use. A small plan is usually enough for personal browsing, since VPN traffic is light compared with hosting a public site.
WireGuard VPN on VPS: What You Need First
Pick a server location that fits your purpose. If you want to reach services in a certain country, pick a server there. If you only want encryption on public Wi-Fi, pick a location near you for lower latency. Install a fresh Ubuntu server, update it, and make sure you can reach it over SSH. If you have not secured a fresh server before, read a hardening guide for a fresh Ubuntu server first, since a VPN server that is itself insecure helps no one.
You also need to decide how clients will reach the internet through the tunnel. The common setup routes all client traffic through the server, so websites see the server’s IP address. An alternative routes only traffic for a private network, such as a home lab, through the tunnel. This guide uses the full-tunnel setup, and notes where the split-tunnel version differs.
Step 1: Install WireGuard on the Server
On Ubuntu, install WireGuard with the package manager, then confirm the kernel module loads. The commands are short, and the package includes the tools for generating keys and managing interfaces. After installation, enable IP forwarding so the server can pass traffic between the VPN interface and the internet. This is a one-line change in the system configuration, and it takes effect after a reboot or a reload of the network settings.
Forwarding is the step beginners miss most often. Without it, clients connect to the VPN but cannot reach any website, which looks like a broken tunnel. If your tunnel connects but nothing loads, check forwarding before you rebuild keys or configs.
Step 2: Create Server Keys and the Server Config
WireGuard identifies peers by public keys, not passwords. Generate a private key on the server and derive its public key from it. Keep the private key on the server only, with strict file permissions. The server config names the interface (usually wg0), sets the server’s VPN address (for example 10.8.0.1), lists the listening UDP port (51820 by default), and points at the private key.
Each client gets its own section in the server config, with the client’s public key and the VPN address allowed for that client. Adding a client later means adding one small section and reloading the interface. There is no need to restart the whole server, and existing clients stay connected while you reload.
Step 3: WireGuard Server Setup and Firewall Rules
This is the core WireGuard server setup step, so take it slowly. Open UDP port 51820 in your firewall, and add NAT rules so VPN traffic can leave through the server’s public interface. On Ubuntu with UFW, the firewall rules live in the VPN interface config itself, so they apply when the interface starts and remove themselves when it stops. That keeps the rules tied to the VPN instead of floating in a separate firewall config you might forget.
Start the interface and check its status. The status output shows the interface, its listening port, and any peers. A peer with no recent handshake has not connected yet, which usually means a wrong key, a wrong endpoint address, or a blocked port. Work through those three causes in order before changing anything else.
Step 4: Create a Client Config
Generate a key pair on each client device, or generate it on the server and transfer the private key securely to the device. The client config needs its own private key, its VPN address, the server’s public key, the server’s public IP and port as the endpoint, and an AllowedIPs setting. For a full tunnel, AllowedIPs is 0.0.0.0/0, which sends all traffic through the VPN. For a split tunnel, list only the private network range.
Many people use a QR code to move the config to a phone. WireGuard’s tools can print a QR code from a config file, and the phone app scans it in seconds. For a laptop, copy the config file directly. Either way, treat the client private key like a password: anyone with it can use your VPN.
Step 5: Connect and Test the Tunnel
Start the client and check three things. First, the handshake: the client status should show a recent handshake with the server. Second, the IP address: an IP check site should show the server’s location, not your real location. Third, DNS: queries should go through a resolver you trust, not leak to your local network. A DNS leak test site will show which resolvers answer your queries.
If the handshake works but websites do not load, check the server’s forwarding and NAT rules again. If the handshake never happens, check the endpoint address, the port, and the keys. If DNS leaks, set an explicit DNS server in the client config, such as your own resolver or a public resolver you trust.
WireGuard Client Config Tips for Phones and Laptops
On phones, enable the tunnel on demand or leave it always on, depending on your battery and data needs. On laptops, a simple toggle in the app is enough, and you can keep separate configs for home, travel, and work if you run more than one server.
How WireGuard Compares with Mesh VPN Tools
WireGuard is a protocol, while tools such as Tailscale build a mesh network on top of it. A mesh VPN comparison shows the trade-off: mesh tools handle key exchange and NAT traversal for you, but they add a coordination service you do not control. A plain WireGuard setup has no such service, which means more manual key handling but full control. For a single server and a few devices, manual handling is simple. For dozens of devices that change often, a mesh tool saves time.
Commercial VPN services solve a different problem: hiding your IP from websites without running a server. A comparison of commercial VPN providers is useful if you do not want to maintain a server at all. The trade-off is trust: you hand your traffic to a company instead of a server you control. Many people run both, using their own server for private access and a commercial service for general browsing.
Keeping Your VPN Server Safe Over Time
A VPN server needs the same care as any public server. Good vpn tunnel security means applying security updates regularly, keeping SSH key-only and firewall rules tight, and watching the logs for failed connection attempts. WireGuard itself does not respond to unauthenticated packets, so port scans reveal little, but the server’s other services still need protection.
Review peers every few months. Remove devices you no longer use, rotate keys if a device was lost, and check that the server’s disk has room for logs. Monitoring helps here: a simple VPS monitoring setup will warn you before disk space or load becomes a problem. A VPN that goes down while you travel is annoying, and a monitoring alert turns that into a five-minute fix.
Common WireGuard Problems and Fixes
| Symptom | Most likely cause | Fix |
|---|---|---|
| Connects, nothing loads | IP forwarding or NAT off | Enable forwarding, check NAT rules |
| No handshake | Wrong key, endpoint, or port | Recheck keys, IP, and firewall port |
| DNS leaks | No DNS set in client config | Set an explicit DNS server |
| Works on Wi-Fi, not mobile data | Carrier blocks UDP port | Try UDP port 53 or 443 |
Most WireGuard problems fit in that table. Work through it in order, change one thing at a time, and test after each change. Guessing at several settings at once makes it hard to tell which change fixed the problem, and it can introduce a new one.