This article may contain affiliate links. We may earn a commission if you sign up through our links, at no extra cost to you. See our Disclosure Policy.
VPS Guide — Security

How to Install WireGuard VPN on a VPS — Complete Guide [2026]

By CloudPicked Review Team · Updated September 2026
Install WireGuard VPN on VPS

Table of Contents

  1. What Is WireGuard?
  2. WireGuard vs OpenVPN vs IPsec
  3. Prerequisites
  4. Install WireGuard on Server (Ubuntu 24.04)
  5. Generate Key Pairs
  6. Write the Server Configuration
  7. Enable IP Forwarding and Firewall
  8. Configure Client: Windows
  9. Configure Client: macOS
  10. Configure Client: iOS / Android
  11. Test the Connection
  12. Auto-Start on Boot (systemd)
  13. Troubleshooting Common Issues
  14. Frequently Asked Questions

If you already have a VPS and want a private VPN that is fast, secure, and easy to set up, WireGuard is the best answer in 2026. Whether you need to protect traffic on public Wi-Fi, bypass geo-restrictions, or connect multiple private servers securely, this guide takes you through the entire process from zero to a working VPN on every device you own.

What Is WireGuard?

WireGuard is a modern VPN protocol designed to be faster, simpler, and more secure than older protocols like OpenVPN and IPsec. Key characteristics:

WireGuard was merged into the Linux kernel in version 5.6 (April 2020). Any modern Linux VPS supports it out of the box — no extra kernel module required.

Bottom Line: Why Choose WireGuard?

Ideal for anyone with a VPS who wants a private VPN that is quick to deploy, fast in practice, and security-audited. Your only recurring cost is the VPS itself — no monthly VPN subscription fee.

WireGuard vs OpenVPN vs IPsec/IKEv2

Factual comparison based on official documentation (data as of September 2026 — verify latest specs at each project's website):

FeatureWireGuardOpenVPNIPsec/IKEv2
TransportUDP onlyUDP or TCPUDP / ESP
Default PortUDP 51820UDP/TCP 1194UDP 500 / 4500
Codebase Size~4,000 lines~100,000+ linesVery complex
PerformanceVery fast (kernel)Moderate (userspace)Fast
ConfigurationVery simpleModerateComplex
Kernel IntegrationYes (Linux ≥5.6)No (userspace)Partial
Encryption CipherChaCha20AES-256 / ChaCha20AES-256
CostFree (OSS)Free (OSS)Free (OSS)

WireGuard's main limitation is UDP-only transport. If a network strictly blocks all UDP traffic, WireGuard will not connect. In that edge case, OpenVPN over TCP 443 is the fallback.

Prerequisites

Server Side (VPS)

Client Side (Devices to Connect)

Need a VPS? For a Thai-server option consider Bangmod Cloud. For international VPS, DigitalOcean starts at $6/month with datacenters in Singapore and other Asia regions.

Step 1: Install WireGuard on the Server

SSH into your VPS and run:

# Update package lists
sudo apt update && sudo apt upgrade -y

# Install WireGuard
sudo apt install -y wireguard wireguard-tools

# Verify installation
wg --version

A response like wireguard-tools v1.0.xx confirms a successful install. On Ubuntu 22.04/24.04, WireGuard is built into the kernel — no additional module is needed.

Step 2: Generate Server Key Pair

WireGuard uses public/private key cryptography, similar to SSH. Each peer (server and every client) needs its own key pair.

# Generate server private key
sudo wg genkey | sudo tee /etc/wireguard/server_private.key

# Derive the public key from the private key
sudo cat /etc/wireguard/server_private.key | sudo wg pubkey | sudo tee /etc/wireguard/server_public.key

# Restrict permissions
sudo chmod 600 /etc/wireguard/server_private.key

# Display keys (save the public key — you will need it in every client config)
echo "=== Server Private Key ===" && sudo cat /etc/wireguard/server_private.key
echo "=== Server Public Key ===" && sudo cat /etc/wireguard/server_public.key

Save the Server Public Key somewhere safe. It goes into every client configuration.

Step 3: Generate Client Key Pairs

Repeat for each device that will connect. Below creates keys for Client 1 (e.g., your laptop):

sudo wg genkey | sudo tee /etc/wireguard/client1_private.key
sudo cat /etc/wireguard/client1_private.key | sudo wg pubkey | sudo tee /etc/wireguard/client1_public.key
sudo chmod 600 /etc/wireguard/client1_private.key

echo "=== Client1 Private Key ===" && sudo cat /etc/wireguard/client1_private.key
echo "=== Client1 Public Key ===" && sudo cat /etc/wireguard/client1_public.key

Step 4: Write the Server Configuration

sudo nano /etc/wireguard/wg0.conf

Paste the following, replacing the placeholder values with your own keys:

[Interface]
# WireGuard network IP for the server
Address = 10.0.0.1/24

# Port WireGuard will listen on
ListenPort = 51820

# Paste your Server Private Key here
PrivateKey = <SERVER_PRIVATE_KEY>

# Full-tunnel NAT rules — routes all client traffic through this VPS
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

# ===== Peer: Client 1 =====
[Peer]
# Paste Client1 Public Key here
PublicKey = <CLIENT1_PUBLIC_KEY>

# VPN IP assigned to this client
AllowedIPs = 10.0.0.2/32

Note: eth0 is the primary network interface name on most VPS providers. Some use ens3, ens18, or another name. Verify with ip link show and replace eth0 accordingly in the PostUp/PostDown lines.

Step 5: Enable IP Forwarding and Configure Firewall

Enable IP Forwarding

# Enable immediately
sudo sysctl -w net.ipv4.ip_forward=1

# Persist across reboots
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sudo sysctl -p

Open the Firewall (UFW)

# Allow SSH — critical! Do this FIRST or you will lock yourself out
sudo ufw allow OpenSSH

# Allow the WireGuard UDP port
sudo ufw allow 51820/udp

# Enable UFW
sudo ufw --force enable

# Verify
sudo ufw status verbose

Start WireGuard

sudo wg-quick up wg0
sudo wg show

Step 6: Configure Client on Windows

  1. Download the WireGuard Windows installer from wireguard.com/install and run it.
  2. Open WireGuard → click "Add Tunnel" → "Add empty tunnel".
  3. The app generates a key pair automatically — copy the Public Key shown, you need to add it to the server's [Peer] section.
  4. Enter the following configuration:
[Interface]
# Auto-generated by the app
PrivateKey = <CLIENT_PRIVATE_KEY_FROM_APP>

# Client VPN IP
Address = 10.0.0.2/32

# DNS while connected
DNS = 1.1.1.1, 8.8.8.8

[Peer]
# Server Public Key from Step 2
PublicKey = <SERVER_PUBLIC_KEY>

# VPS public IP and WireGuard port
Endpoint = YOUR_VPS_IP:51820

# Full tunnel — all traffic routed through VPN
AllowedIPs = 0.0.0.0/0, ::/0

# Keepalive to maintain connection through NAT
PersistentKeepalive = 25

Click Save, then toggle Activate to connect.

Step 7: Configure Client on macOS

Option A — Mac App Store (recommended):

  1. Open App Store → search "WireGuard" → install the official app.
  2. Click "+" → "Add Empty Tunnel".
  3. Use the same config structure as Windows, assigning a unique IP (e.g., 10.0.0.3/32).
  4. Save and toggle to connect.

Option B — Homebrew (command line):

brew install wireguard-tools
sudo mkdir -p /etc/wireguard
sudo nano /etc/wireguard/wg0.conf
# Paste client config, then:
sudo wg-quick up wg0

Step 8: Configure Client on iOS and Android

iOS

  1. Install "WireGuard" from the App Store.
  2. Tap "+" → choose "Create from scratch" or "Create from QR code".
  3. Assign IP 10.0.0.4/32 (or the next available address).

Android

  1. Install "WireGuard" from Google Play.
  2. Tap "+" → "Create from scratch".
  3. Fill in the config with IP 10.0.0.4/32.

QR Code Method (Faster for Mobile)

# Install qrencode on the server
sudo apt install -y qrencode

# Create the mobile client config file
cat > /tmp/mobile_client.conf << EOF
[Interface]
PrivateKey = <MOBILE_CLIENT_PRIVATE_KEY>
Address = 10.0.0.4/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
EOF

# Display as QR code in terminal
qrencode -t ansiutf8 < /tmp/mobile_client.conf

Scan the QR code from the WireGuard app on your phone to import the tunnel instantly.

Step 9: Test the Connection

Check Your IP Address

With the VPN connected, visit whatismyipaddress.com — the displayed IP should be your VPS public IP, not your local network IP.

Verify on the Server

sudo wg show
# Look for "latest handshake: X seconds ago" under each peer
# That confirms the client connected and exchanged keys

Ping Test

# From client, ping the server WireGuard IP
ping 10.0.0.1

# From server, ping the client
ping 10.0.0.2

Step 10: Auto-Start WireGuard on Boot

# Enable the systemd service
sudo systemctl enable wg-quick@wg0

# Start it now
sudo systemctl start wg-quick@wg0

# Check status
sudo systemctl status wg-quick@wg0

WireGuard will now start automatically every time the VPS reboots — no manual intervention needed.

Troubleshooting Common Issues

Connection Timeout / No Handshake

VPN Connects But No Internet (Full Tunnel)

DNS Leak

Add a New Peer Without Restarting

# Add live — existing connections are not dropped
sudo wg set wg0 peer <NEW_CLIENT_PUBLIC_KEY> allowed-ips 10.0.0.5/32

# Save to config file
sudo wg-quick save wg0

Need a VPS to run WireGuard? These providers work great:

DigitalOcean VPS   Bangmod Cloud (Thailand)

Frequently Asked Questions

What port does WireGuard use?
WireGuard uses UDP port 51820 by default. You can change this to any other port by modifying the ListenPort value in the server configuration. Only UDP is required — no TCP port is needed.
What VPS specs does WireGuard need?
WireGuard is extremely resource-efficient. A VPS with 1 vCPU and 512MB RAM handles a WireGuard server comfortably, even with several connected clients simultaneously.
Is WireGuard safer than OpenVPN?
WireGuard uses modern cryptographic primitives (ChaCha20, Poly1305, Curve25519, BLAKE2) and has roughly 4,000 lines of code versus OpenVPN's 100,000+. The dramatically smaller attack surface and the fact that it runs in kernel space are why many security researchers now recommend WireGuard for general-purpose VPN use.
Does WireGuard work on iOS and Android?
Yes. Official WireGuard apps are available for both iOS (App Store) and Android (Google Play). Setup works via manual configuration or by scanning a QR code generated on the server.
Is WireGuard free?
WireGuard is completely free and open source. The only cost is the VPS you use as the server, which can be as low as $3–6/month depending on the provider and region.
How do I do split tunneling with WireGuard?
In the client config, change AllowedIPs = 0.0.0.0/0 (full tunnel) to only the subnet(s) you want to route through the VPN. For example, AllowedIPs = 10.0.0.0/24 routes only WireGuard network traffic through the VPN and lets everything else go directly to the internet.