How to set up WireGuard VPN on Ubuntu
Step 1: Install WireGuard
sudo apt update
sudo apt install wireguard -yStep 2: Generate server keys
cd /etc/wireguard
umask 077
wg genkey | tee server-private.key | wg pubkey > server-public.keyStep 3: Create the server configuration
sudo nano /etc/wireguard/wg0.conf[Interface]
PrivateKey = <paste-server-private-key-here>
Address = 10.0.0.1/24
ListenPort = 51820
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
[Peer]
PublicKey = <client-public-key>
AllowedIPs = 10.0.0.2/32Step 4: Enable IP forwarding
Step 5: Configure the firewall
Step 6: Start WireGuard
Step 7: Set up a client (Linux desktop or laptop)
Step 8: Add the client's public key to the server
Step 9: Connect the client
Step 10: Set up a mobile client (iOS/Android)
Managing WireGuard
Common issues
Performance notes
Conclusion
Last updated