Table of Contents
- What Is WireGuard and Why Use It on a VPS
- WireGuard vs OpenVPN vs IPsec Comparison
- Prerequisites
- Install WireGuard on Ubuntu
- Configure the WireGuard Server Interface
- Configure UFW Firewall and IP Forwarding
- Start and Enable the Service
- Add a Client Peer
- Set Up Clients on iOS, Android, and PC
- Troubleshooting Common Issues
- FAQ
- Summary
WireGuard is a modern VPN protocol that has become the standard in 2026. With performance superior to OpenVPN and IPsec, a minimal codebase, and straightforward configuration, it is the ideal choice for running a private VPN server on your own VPS. This guide walks you through every step from installation to a working client connection.
What Is WireGuard and Why Use It on a VPS
WireGuard was developed by Jason Donenfeld and merged into the Linux Kernel 5.6 in 2020. Its key advantages come from its minimal design — roughly 4,000 lines of code versus OpenVPN's 70,000+:
- Faster — runs as a kernel module, not a user-space daemon
- More secure — small codebase is much easier to audit
- Better roaming — seamlessly switches between WiFi and mobile networks without disconnecting
- Easier to configure — a few lines of config are all you need
Running WireGuard on your own VPS gives you full control over your traffic without paying ongoing fees to commercial VPN providers.
WireGuard vs OpenVPN vs IPsec Comparison
| Factor | WireGuard | OpenVPN | IPsec/IKEv2 |
|---|---|---|---|
| Codebase size | ~4,000 lines | ~70,000 lines | Very complex |
| Performance | ⭐⭐⭐⭐⭐ (Kernel) | ⭐⭐⭐ (User-space) | ⭐⭐⭐⭐ |
| Setup complexity | Simple | Moderate | Complex |
| Roaming support | Excellent | Fair | Good |
| Protocol | UDP only | UDP/TCP | UDP/ESP |
| Linux Kernel support | 5.6+ (built-in) | Requires install | Built-in |
Prerequisites
- VPS running Ubuntu 20.04, 22.04, or 24.04 (22.04 recommended)
- Root or sudo access
- A public IP address assigned to the VPS
- UDP port 51820 available
- Basic Linux command-line familiarity
💡 Note: All AsiaGB VPS plans include a public IP and run Kernel 5.15+ with WireGuard built in — no extra kernel module installation needed.
Install WireGuard on Ubuntu
Update your package list and install WireGuard:
sudo apt update && sudo apt upgrade -y sudo apt install wireguard -y
Verify the installation:
wg --version # Output: wireguard-tools v1.0.20210914 - https://git.zx2c4.com/wireguard-tools/
Generate the server keypair:
wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key chmod 600 /etc/wireguard/server_private.key cat /etc/wireguard/server_private.key # save this — your server private key cat /etc/wireguard/server_public.key # share this with clients
⚠️ Important: Never share your private key with anyone. Only the public key is shared with clients.
Configure the WireGuard Server Interface
Create the server interface configuration file for wg0:
sudo nano /etc/wireguard/wg0.conf
Add the following content (replace SERVER_PRIVATE_KEY with your actual key):
[Interface] Address = 10.0.0.1/24 ListenPort = 51820 PrivateKey = SERVER_PRIVATE_KEY 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
💡 Note: Replace eth0 with your actual network interface name. Check it with: ip route | grep default
Configure UFW Firewall and IP Forwarding
Enable IP Forwarding
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf sudo sysctl -p
Open the WireGuard Port
sudo ufw allow 51820/udp sudo ufw allow OpenSSH sudo ufw enable sudo ufw status
Start and Enable the Service
sudo systemctl enable wg-quick@wg0 sudo systemctl start wg-quick@wg0 sudo systemctl status wg-quick@wg0
Verify the interface is up:
sudo wg show # Shows: interface wg0, public key, listening port: 51820
Add a Client Peer
Generate a keypair for each client separately:
wg genkey | tee client1_private.key | wg pubkey > client1_public.key
Add the peer to your server config (/etc/wireguard/wg0.conf):
[Peer] # Client1 PublicKey = CLIENT1_PUBLIC_KEY AllowedIPs = 10.0.0.2/32
Apply the change without restarting:
sudo wg syncconf wg0 <(sudo wg-quick strip wg0)
Set Up Clients on iOS, Android, and PC
Client Configuration File
[Interface] PrivateKey = CLIENT1_PRIVATE_KEY Address = 10.0.0.2/32 DNS = 1.1.1.1 [Peer] PublicKey = SERVER_PUBLIC_KEY Endpoint = YOUR_VPS_IP:51820 AllowedIPs = 0.0.0.0/0, ::/0 PersistentKeepalive = 25
| Platform | Import Method | App |
|---|---|---|
| iOS (iPhone/iPad) | Scan QR Code or Import File | WireGuard (App Store) |
| Android | Scan QR Code or Import File | WireGuard (Play Store) |
| Windows | Add Tunnel → Import from file | WireGuard for Windows |
| macOS | Add Tunnel → Import from file | WireGuard (App Store) |
| Linux | wg-quick up client1 | wireguard-tools |
Generate a QR Code for Mobile Devices
sudo apt install qrencode -y qrencode -t ansiutf8 < client1.conf
Troubleshooting Common Issues
Connected but No Internet Access
Verify IP forwarding is enabled and PostUp/PostDown use the correct interface name:
sysctl net.ipv4.ip_forward # Must return: net.ipv4.ip_forward = 1
Client Cannot Connect at All
- Confirm UFW allows UDP 51820:
sudo ufw status - Verify the Endpoint IP and port in the client config
- Check the interface is running:
sudo wg show - Check service logs:
journalctl -u wg-quick@wg0 -f
systemctl enable wg-quick@wg0 it starts automatically on every reboot.🎯 Summary: Install WireGuard VPN Server on VPS Ubuntu
WireGuard is the top VPN protocol choice in 2026 for self-hosted VPN servers. The key steps are:
- Install:
apt install wireguard - Generate server and client keypairs
- Create
/etc/wireguard/wg0.conf - Enable IP forwarding and configure UFW/iptables
- Run
systemctl enable --now wg-quick@wg0 - Distribute client config or QR code to users
Need a VPS for WireGuard? See AsiaGB VPS plans starting from 500 THB/month with SSD storage and 99% uptime.