// Fast. Simple. Secure. The future of VPNs.
WIREGUARD IS THE VPN REVOLUTION.
Traditional VPNs are bloated, complex, and slow. WireGuard strips away the complexityβusing modern cryptography that's actually been reviewed and proven, in under 4,000 lines of code. It's faster, simpler, and more secure than anything else.
TAKE CONTROL OF YOUR NETWORK.
With WireGuard, you own your VPN. No subscription services, no corporate surveillance, no slow servers halfway across the world. Build your own private network that connects your home, office, and devicesβall encrypted, all fast.
SIMPLE IS SECURE.
Less code means fewer bugs. Fewer bugs means fewer vulnerabilities. WireGuard's minimal attack surface makes it the smart choice for anyone who takes security seriously.
12 lessons. Complete WireGuard control.
What is WireGuard? Installing WireGuard and understanding the architecture.
BeginnerGenerating key pairs. Public/private key cryptography in WireGuard.
BeginnerConfiguring the WireGuard server. Setting up the server configuration file.
BeginnerConfiguring WireGuard clients. Windows, macOS, Linux, mobile clients.
BeginnerFull tunnel vs split tunnel. Routing all traffic through VPN.
IntermediateSecuring WireGuard with iptables/nftables. NAT and forwarding.
IntermediateManaging multiple clients. Server with many peers.
IntermediateWireGuard on iOS and Android. Mobile client setup.
IntermediateMesh VPN configuration. Connecting networks without central server.
AdvancedMTU optimization, persistent keepalive, connection monitoring.
AdvancedHandling dynamic public IPs. DDNS configuration for server.
AdvancedCommon issues, debugging, wg show, and diagnostic commands.
AdvancedWireGuard is a modern, high-performance VPN protocol designed to be simpler and faster than existing solutions. It uses state-of-the-art cryptography (Curve25519, ChaCha20, Poly1305, BLAKE2) and aims to be "fast, modern, and secure."
# Ubuntu/Debian sudo apt install wireguard # Fedora sudo dnf install wireguard-tools # Arch sudo pacman -S wireguard-tools
# Via Homebrew brew install wireguard-tools # Or App Store: WireGuard
# Download from https://www.wireguard.com/install/
WireGuard uses a simple concept:
WireGuard uses Curve25519 for key exchange. Each peer needs a key pair:
# Generate private key wg genkey > privatekey # Generate public key from private key wg pubkey < privatekey > publickey
This creates two files:
For extra security, add a pre-shared key for post-quantum resistance:
# Generate pre-shared key wg genpsk > presharedkey
This is optional but recommended for high-security scenarios.
# Store keys securely chmod 600 privatekey chmod 600 presharedkey # Keep in /etc/wireguard/ on server sudo mv privatekey /etc/wireguard/wg0.conf sudo chmod 600 /etc/wireguard/wg0.conf
# Create server config: /etc/wireguard/wg0.conf [Interface] # Server's private key (generated in lesson 2) PrivateKey = SERVER_PRIVATE_KEY # Listen port (default 51820) ListenPort = 51820 # Server's IP address in VPN network Address = 10.0.0.1/24 # DNS server to use for clients DNS = 1.1.1.1, 8.8.8.8 # NAT configuration (optional, for IP forwarding) PostUp = iptables -A FORWARD -i %i -j ACCEPT PostUp = iptables -A FORWARD -o %i -j ACCEPT PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i %i -j ACCEPT PostDown = iptables -D FORWARD -o %i -j ACCEPT PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
# Add to /etc/wireguard/wg0.conf after [Interface]: [Peer] # Client's public key (from client) PublicKey = CLIENT_PUBLIC_KEY # Allowed IPs - what can this client access through VPN # For full tunnel (all traffic): AllowedIPs = 0.0.0.0/0, ::/0 # For split tunnel (only VPN network): # AllowedIPs = 10.0.0.2/32 # Optional: persistent keepalive (for NAT traversal) PersistentKeepalive = 25
# Enable and start sudo systemctl enable wg-quick@wg0 sudo systemctl start wg-quick@wg0 # Check status sudo wg show # View interface ip addr show wg0
# Create client config: /etc/wireguard/wg0.conf [Interface] # Client's private key PrivateKey = CLIENT_PRIVATE_KEY # Client's IP in VPN network Address = 10.0.0.2/24 # DNS while on VPN DNS = 1.1.1.1 [Peer] # Server's public key PublicKey = SERVER_PUBLIC_KEY # Server endpoint Endpoint = your-server-ip-or-domain.com:51820 # What traffic to route through VPN # Full tunnel: AllowedIPs = 0.0.0.0/0, ::/0 # Split tunnel: # AllowedIPs = 10.0.0.0/24 # Optional: keep connection alive through NAT PersistentKeepalive = 25
# Connect sudo wg-quick up wg0 # Disconnect sudo wg-quick down wg0
All traffic goes through VPN:
AllowedIPs = 0.0.0.0/0, ::/0
Use when: Public WiFi, hiding all traffic, accessing home network resources.
Only VPN network traffic goes through:
AllowedIPs = 10.0.0.0/24
Use when: Speed matters, only need access to home network.
# Access home network (192.168.1.0/24) through VPN AllowedIPs = 10.0.0.0/24, 192.168.1.0/24
This routes both VPN network and home LAN through the tunnel.
# Enable IP forwarding (persistently) echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-wireguard.conf sudo sysctl -p /etc/sysctl.d/99-wireguard.conf
# Allow WireGuard port sudo ufw allow 51820/udp # Or iptables directly sudo iptables -A INPUT -p udp --dport 51820 -j ACCEPT # Allow forwarding from VPN to internet sudo iptables -A FORWARD -i wg0 -o eth0 -j ACCEPT sudo iptables -A FORWARD -i eth0 -o wg0 -j ACCEPT # NAT sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Install iptables-persistent sudo apt install iptables-persistent # Save rules sudo netfilter-persistent save # Or add to WireGuard config PostUp = iptables -A FORWARD -i %i -j ACCEPT PostUp = iptables -A FORWARD -o %i -j ACCEPT PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i %i -j ACCEPT PostDown = iptables -D FORWARD -o %i -j ACCEPT PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
Server configuration can have multiple [Peer] sections:
[Interface] PrivateKey = SERVER_PRIVATE_KEY ListenPort = 51820 Address = 10.0.0.1/24 DNS = 1.1.1.1 # Peer 1 - Alice [Peer] PublicKey = ALICE_PUBLIC_KEY AllowedIPs = 10.0.0.2/32 # Peer 2 - Bob [Peer] PublicKey = BOB_PUBLIC_KEY AllowedIPs = 10.0.0.3/32 # Peer 3 - Charlie (with pre-shared key) [Peer] PublicKey = CHARLIE_PUBLIC_KEY PresharedKey = CHARLIE_PSK AllowedIPs = 10.0.0.4/32
# View connected peers sudo wg show # Add peer dynamically (not persistent) sudo wg set wg0 peer PUBLIC_KEY allowed-ips 10.0.0.5/32 # Remove peer sudo wg set wg0 peer PUBLIC_KEY remove
Generate config on computer and transfer via:
# On mobile, recommended settings: [Interface] PrivateKey = MOBILE_PRIVATE_KEY Address = 10.0.0.5/24 DNS = 1.1.1.1 # Keepalive important for mobile networks PersistentKeepalive = 25
WireGuard can create mesh networks where peers connect directly to each other without a central server.
# Peer A config [Interface] PrivateKey = A_PRIVATE Address = 10.0.0.1/24 [Peer] PublicKey = B_PUBLIC Endpoint = B_HOSTNAME_OR_IP:51820 AllowedIPs = 10.0.0.2/32 PersistentKeepalive = 25 [Peer] PublicKey = C_PUBLIC Endpoint = C_HOSTNAME_OR_IP:51820 AllowedIPs = 10.0.0.3/32 PersistentKeepalive = 25
For larger meshes, use helper tools:
WireGuard adds overhead. Setting proper MTU prevents fragmentation:
# If experiencing issues, try lower MTU [Interface] MTU = 1420 # Common settings: # 1420 - Safe for most (prevents fragmentation) # 1500 - Maximum, may fragment on some networks
# Required for NAT traversal # Default: off PersistentKeepalive = 25 # For mobile: keepalive is essential # For always-on server: can be higher or off
# Test speed through VPN iperf3 -s # On server iperf3 -c 10.0.0.1 # On client # Check current settings sudo wg show
If your server has dynamic IP, use DDNS:
# Example: DuckDNS # Register at duckdns.org # Your domain: myvpn.duckdns.org # Install ddclient sudo apt install ddclient # Configure /etc/ddclient.conf protocol=dyndns2 server=www.duckdns.org login=your-duckdns-token password='your-password' myvpn.duckdns.org
Clients will automatically use updated IP:
# In client config, use domain instead of IP [Peer] PublicKey = SERVER_PUBLIC_KEY Endpoint = myvpn.duckdns.org:51820 AllowedIPs = 0.0.0.0/0
# Check interface status sudo wg show # View detailed interface info sudo wg show wg0 dump # Check interface exists ip addr show wg0 # Check routing ip route # Check firewall sudo iptables -L -n -v
# Journal logs sudo journalctl -u wg-quick@wg0 -f # System logs sudo dmesg | grep wireguard
You've completed the WireGuard mastery guide. You now know how to: