Install WireGuard VPN Server on VPS Ubuntu

Table of Contents

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+:

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

FactorWireGuardOpenVPNIPsec/IKEv2
Codebase size~4,000 lines~70,000 linesVery complex
Performance⭐⭐⭐⭐⭐ (Kernel)⭐⭐⭐ (User-space)⭐⭐⭐⭐
Setup complexitySimpleModerateComplex
Roaming supportExcellentFairGood
ProtocolUDP onlyUDP/TCPUDP/ESP
Linux Kernel support5.6+ (built-in)Requires installBuilt-in

Prerequisites

💡 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
PlatformImport MethodApp
iOS (iPhone/iPad)Scan QR Code or Import FileWireGuard (App Store)
AndroidScan QR Code or Import FileWireGuard (Play Store)
WindowsAdd Tunnel → Import from fileWireGuard for Windows
macOSAdd Tunnel → Import from fileWireGuard (App Store)
Linuxwg-quick up client1wireguard-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

❓ Frequently Asked Questions
What is the difference between WireGuard and OpenVPN?
WireGuard uses only ~4,000 lines of code versus OpenVPN's ~70,000, making it faster, easier to audit, and more stable when switching networks.
What port does WireGuard use?
UDP port 51820 by default. You can change it with the ListenPort directive in the server config.
How much RAM does a WireGuard VPN server require?
Very little. A 1 GB RAM VPS handles dozens of concurrent clients since WireGuard runs as a kernel module.
Can I add multiple clients to one WireGuard server?
Yes. Add a separate [Peer] block with a unique public key and AllowedIPs for each client.
Will WireGuard survive a VPS reboot?
Yes, after running systemctl enable wg-quick@wg0 it starts automatically on every reboot.
Does WireGuard hide my real IP address?
Yes. When connected, all traffic exits from the VPS IP so websites see the VPS IP, not your real IP.

🎯 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:

  1. Install: apt install wireguard
  2. Generate server and client keypairs
  3. Create /etc/wireguard/wg0.conf
  4. Enable IP forwarding and configure UFW/iptables
  5. Run systemctl enable --now wg-quick@wg0
  6. 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.