← All posts

WireGuard VPN Setup in 10 Minutes

Introduction

Let's cut to the chase: VPNs don't have to be complicated. If you've ever wrestled with OpenVPN's 4,000-line config files or spent an afternoon debugging IPsec handshakes, WireGuard is going to feel like a breath of fresh air.

Created by Jason Donenfeld and merged into the Linux kernel in 2020, WireGuard is a modern VPN protocol that prioritizes simplicity, performance, and cryptography done right. Its codebase is roughly 4,000 lines of C — compared to OpenVPN's 600,000+ lines — which means it's easier to audit, faster to set up, and significantly more performant.

Here's why you should care:

  • Speed: WireGuard uses state-of-the-art cryptography (Curve25519, ChaCha20, Poly1305) that's optimized for modern CPUs
  • Simplicity: A basic setup involves generating a keypair and writing a ~10-line config file
  • Battery life: On mobile devices, WireGuard's lean approach means less CPU usage and better battery life
  • Seamless roaming: Switch from Wi-Fi to cellular? WireGuard handles it gracefully without dropping the connection

Whether you want to secure your traffic on public Wi-Fi, access your home network remotely, or set up a mesh network between your devices, WireGuard has you covered. And yes — you can go from zero to fully configured in about 10 minutes.


WireGuard vs. The Old Guard

Feature WireGuard OpenVPN IPsec
Codebase ~4,000 lines 600,000+ lines 400,000+ lines
Protocol UDP only (lean) UDP/TCP (heavy) Multiple protocols
Encryption ChaCha20, Curve25519 AES, RSA (configurable) IKE, AES
Setup time 10 minutes 1-2 hours Often days
Performance 3-5x faster Slower Moderate
Roaming Seamless Reconnects Varies
Auditability Easy (small code) Difficult Difficult
Kernel support Native (Linux 5.6+) Userspace Native

The takeaway? WireGuard isn't just marginally better — it's a fundamentally different approach that strips away decades of VPN complexity while actually improving security and performance.


Architecture Overview

WireGuard supports two main topologies:

Client-Server (Star Topology)

This is the most common setup. A central server listens for connections, and clients connect to it. All traffic routes through the server.

  • Use case: Protecting internet traffic, accessing geo-restricted content
  • Pros: Simple to manage, good for "secure my browsing" scenarios
  • Cons: Single point of failure, server bandwidth bottleneck

Mesh Topology

Every peer connects directly to every other peer. No central server needed.

  • Use case: Connecting a small group of devices (home lab, team servers)
  • Pros: Direct device-to-device communication, no central bottleneck
  • Cons: More complex key management, doesn't route internet traffic

For this guide, we'll focus on the client-server model since it's the most common starting point. But WireGuard makes it trivial to add mesh networking later — just add another [Peer] block.


Prerequisites

You'll need:

  1. A server with a public IP address. This can be:

    • A cheap VPS (DigitalOcean, Linode, Hetzner, Vultr — $3-5/month)
    • A home server with port forwarding enabled
    • A Raspberry Pi behind your router (with port forwarding)
  2. Root or sudo access on that server

  3. One or more client devices (phone, laptop, tablet)

  4. About 10 minutes of uninterrupted time


Server Setup (Ubuntu/Debian)

Step 1: Installation

# Update your package list
sudo apt update

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

# Verify installation
wg --version

If you're on a different distro:

  • Fedora/RHEL: sudo dnf install wireguard-tools
  • Arch: sudo pacman -S wireguard-tools
  • macOS: brew install wireguard-tools (for server use, though less common)

Step 2: Generate Key Pairs

WireGuard uses private/public key pairs for authentication — no certificates, no Certificate Authority, no hassle.

# Generate the server's private key
genkey | sudo tee /etc/wireguard/privatekey

# Derive the public key from the private key
cat /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey

# Set proper permissions
sudo chmod 600 /etc/wireguard/privatekey

Save both keys somewhere safe — you'll need the public key for client configs, and the private key stays on the server.

Step 3: Create the Server Configuration

Create the main config file at /etc/wireguard/wg0.conf:

sudo nano /etc/wireguard/wg0.conf

Here's a complete, production-ready configuration:

[Interface]
# The server's private key (contents of /etc/wireguard/privatekey)
PrivateKey = YOUR_SERVER_PRIVATE_KEY_HERE

# The port WireGuard will listen on
ListenPort = 51820

# The VPN subnet. wg0 will be assigned 10.8.0.1
Address = 10.8.0.1/24

# Enable IP forwarding and NAT (required for internet access through VPN)
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

# Optional: DNS server for connected clients
DNS = 1.1.1.1, 1.0.0.1

# KeepAlive to prevent NAT timeouts (recommended)
# PersistentKeepalive = 25

Important notes:

  • Replace YOUR_SERVER_PRIVATE_KEY_HERE with the actual key from /etc/wireguard/privatekey
  • Replace eth0 with your server's actual network interface (check with ip a)
  • 10.8.0.0/24 gives you 253 usable IPs for clients — plenty for most setups

Step 4: Enable IP Forwarding

Your server needs to forward traffic between the VPN interface and the internet:

# Enable IP forwarding temporarily
sudo sysctl -w net.ipv4.ip_forward=1

# Make it permanent
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sudo sysctl -p

Step 5: Configure the Firewall

# Allow WireGuard's UDP port
sudo ufw allow 51820/udp

# Allow SSH (don't lock yourself out!)
sudo ufw allow ssh

# Enable the firewall
sudo ufw enable

# Check status
sudo ufw status

If you're using iptables directly instead of UFW:

sudo iptables -A INPUT -p udp --dport 51820 -j ACCEPT
sudo iptables-save | sudo tee /etc/iptables/rules.v4

Step 6: Start WireGuard

# Start the WireGuard interface
sudo wg-quick up wg0

# Enable auto-start on boot
sudo systemctl enable wg-quick@wg0

# Check it's running
sudo wg show

You should see output showing the interface with your public key, listening port, and peers (empty for now).


Client Setup

The beauty of WireGuard is that the client setup is nearly identical across platforms — same config format, same concepts.

Generating Client Keys

For each client, generate a key pair:

# Generate client keys (do this on your server for convenience)
wg genkey | tee client1-privatekey | wg pubkey > client1-publickey

macOS

  1. Install from the Mac App Store or brew install --cask wireguard
  2. Click the WireGuard icon → "Manage Tunnels" → "Add Empty Tunnel"
  3. Name it, paste your client config (see template below), save
  4. Click "Activate"

iOS

  1. Install from the App Store
  2. Tap "+" → "Create from scratch"
  3. Name it, paste your client config, save
  4. Toggle the switch to connect

Pro tip: Use the "Add from QR code" option. On your server:

# Install qrencode
sudo apt install qrencode

# Generate QR code from a client config
qrencode -t ansiutf8 < client1.conf

Windows

  1. Download from wireguard.com/install
  2. Click "Add Tunnel" → "Add empty tunnel"
  3. Name it, paste your client config, save
  4. Click "Activate"

Android

  1. Install from Google Play or F-Droid
  2. Tap the "+" button → "Create from scratch"
  3. Fill in the config (or scan a QR code)
  4. Toggle to connect

Linux

# Install
sudo apt install wireguard-tools

# Create config
sudo nano /etc/wireguard/wg0.conf
# Paste your client config

# Start
sudo wg-quick up wg0

Adding Peers (Clients)

For each client, you need to:

  1. Add the client as a peer on the server
  2. Create a client config with the server as a peer

Client Config Template

Here's a typical client configuration. Save this as client1.conf:

[Interface]
# Client's private key
PrivateKey = CLIENT_PRIVATE_KEY_HERE

# Client's VPN IP address
Address = 10.8.0.2/32

# Optional: specify DNS server (your server's, or a public one)
DNS = 10.8.0.1

# Keep connection alive through NAT
PersistentKeepalive = 25

[Peer]
# Server's public key
PublicKey = SERVER_PUBLIC_KEY_HERE

# Server's endpoint (your server's public IP or domain)
Endpoint = your-server.com:51820

# Route ALL traffic through VPN (0.0.0.0/0 = everything)
AllowedIPs = 0.0.0.0/0

# Or route only VPN subnet traffic (split tunnel)
# AllowedIPs = 10.8.0.0/24

Update Server Config

Add each client to /etc/wireguard/wg0.conf under a new [Peer] section:

[Peer]
# Client's public key
PublicKey = CLIENT_PUBLIC_KEY_HERE

# IP address this client will use (must be unique!)
AllowedIPs = 10.8.0.2/32

After editing, reload the config:

sudo wg syncconf wg0 <(sudo wg-quick strip wg0)

# Or simply restart
sudo wg-quick down wg0 && sudo wg-quick up wg0

DNS and Routing Configuration

Full Tunnel (All Traffic Through VPN)

This routes all internet traffic through your VPN:

# In client config
AllowedIPs = 0.0.0.0/0

Use case: Securing all traffic on public Wi-Fi, bypassing censorship, hiding your IP.

Split Tunnel (Only VPN Subnet)

This only routes traffic to the VPN subnet:

# In client config
AllowedIPs = 10.8.0.0/24

Use case: Accessing home services remotely while using your normal internet connection for everything else.

Custom Routes

You can get granular with routing:

# Route VPN subnet + specific internal networks
AllowedIPs = 10.8.0.0/24, 192.168.1.0/24

# Route everything except one subnet (split tunnel inverse)
# Not directly supported — use multiple AllowedIPs entries

Reverse Tunnel Use Case: Access Home Services

One of WireGuard's killer features is the reverse tunnel — accessing your home services from anywhere without opening ports to the internet.

Scenario

You have a home server at 192.168.1.100 running:

  • Plex on port 32400
  • Home Assistant on port 8123
  • A file server on port 5000

You want to access these from your phone at a coffee shop.

Solution

  1. Set up WireGuard server on any device with a public IP (or use a cheap VPS as a relay)
  2. Connect your home router/device as a WireGuard client with AllowedIPs = 10.8.0.0/24
  3. Connect your phone as another WireGuard client
  4. Access services at http://192.168.1.100:32400 as if you were home

Home Server as Client (Always-On)

On your home server, create /etc/wireguard/wg0-client.conf:

[Interface]
PrivateKey = HOME_SERVER_PRIVATE_KEY
Address = 10.8.0.3/32

[Peer]
PublicKey = VPS_PUBLIC_KEY
Endpoint = your-vps.com:51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25

Now from anywhere, connect your phone to the same WireGuard server and access 10.8.0.3:32400 to reach Plex.


WireGuard + Pi-hole Combo

Want ad-blocking across all your devices, even on mobile data? Combine WireGuard with Pi-hole.

Setup

  1. Install Pi-hole on your WireGuard server:
curl -sSL https://install.pi-hole.net | bash
  1. Update your server config to use Pi-hole as DNS:
[Interface]
PrivateKey = ...
Address = 10.8.0.1/24
ListenPort = 51820
DNS = 10.8.0.1  # Pi-hole listens here
  1. Update client configs to use the VPN's DNS:
[Interface]
PrivateKey = ...
Address = 10.8.0.2/32
DNS = 10.8.0.1
  1. In Pi-hole admin, add your favorite blocklists (like StevenBlack's hosts).

Now every device connected to your WireGuard VPN gets network-wide ad and tracker blocking — even on cellular.


WireGuard + AdGuard Home

Prefer AdGuard Home over Pi-hole? The setup is nearly identical:

  1. Install AdGuard Home:
wget https://static.adguard.com/adguardhome/release/AdGuardHome_linux_arm64.tar.gz
tar xzf AdGuardHome_linux_arm64.tar.gz
sudo ./AdGuardHome/AdGuardHome -s install
  1. Complete the web setup at http://your-server:3000

  2. Point WireGuard DNS to your server IP (AdGuard Home typically listens on :53)

  3. Update WireGuard configs:

[Interface]
DNS = 10.8.0.1

AdGuard Home offers a more modern UI, parental controls, and per-client statistics out of the box.


Troubleshooting Common Issues

Can't Connect at All

# Check if WireGuard is running
sudo wg show

# Verify the interface is up
ip a show wg0

# Check firewall rules
sudo iptables -L -n -v

No Internet Access Through VPN

  1. Verify IP forwarding is enabled:

    sysctl net.ipv4.ip_forward
    # Should return 1
    
  2. Check your PostUp/PostDown rules — make sure eth0 matches your actual interface

  3. Verify NAT is working:

    sudo iptables -t nat -L -n -v
    

Slow Speeds

  • Try a different UDP port (some ISPs throttle 51820)
  • Use PersistentKeepalive = 25 to keep NAT mappings fresh
  • Check CPU usage — older devices may struggle with encryption at high speeds
  • Try a different server location closer to you

DNS Not Working

  • Ensure DNS is set in the [Interface] section of client configs
  • Verify the DNS server is reachable from the VPN subnet
  • Check if Pi-hole/AdGuard is blocking the queries

Handshake Never Completes

  • Double-check public keys (they're easy to mix up)
  • Verify the Endpoint is correct and reachable: nc -vu your-server.com 51820
  • Check server firewall: sudo ufw status
  • Ensure client and server times are in sync (use NTP)

Connection Drops After a While

Add to both configs:

PersistentKeepalive = 25

This sends a keepalive every 25 seconds, keeping NAT mappings alive.


Automation with wg-easy

Want a web UI to manage clients without editing config files? Meet wg-easy.

Quick Deploy (Docker)

docker run -d \
  --name=wg-easy \
  -e WG_HOST=your-server.com \
  -e PASSWORD=your-admin-password \
  -v ~/.wg-easy:/etc/wireguard \
  -p 51820:51820/udp \
  -p 51821:51821/tcp \
  --cap-add=NET_ADMIN \
  --cap-add=SYS_MODULE \
  --sysctl="net.ipv4.conf.all.src_valid_mark=1" \
  --sysctl="net.ipv4.ip_forward=1" \
  --restart unless-stopped \
  ghcr.io/wg-easy/wg-easy

Now visit http://your-server:51821, log in, and manage peers with a slick web UI. Generate QR codes, download configs, and monitor connections — no command line required.

PiVPN

For Raspberry Pi users, PiVPN is a bash script that automates the entire WireGuard (or OpenVPN) installation:

curl -L https://install.pivpn.io | bash

Follow the interactive prompts. It handles installation, configuration, firewall rules, and even generates client configs. Perfect for beginners.


Conclusion

You now have a fully functional, modern VPN running in — hopefully — under 10 minutes. WireGuard's brilliance is in its simplicity: what used to require a day of configuration and debugging now takes a handful of commands and a 10-line config file.

From here, you can:

  • Add more clients (just generate keys and add [Peer] blocks)
  • Set up split tunneling for specific routes
  • Combine with Pi-hole or AdGuard for network-wide ad blocking
  • Create a mesh network between your devices
  • Automate management with wg-easy

The era of wrestling with OpenVPN config generators and certificate chains is over. WireGuard is the future of VPNs, and that future is refreshingly simple.

Next steps: Check out WireGuard's official docs for advanced topics like roaming, pre-shared keys, and multi-hop configurations.


Happy tunneling! 🔒