Setting Up WireGuard VPN Server on Raspberry Pi
Setting Up WireGuard VPN Server on Raspberry Pi WireGuard is a fast, modern VPN. A Pi-hosted server lets you securely connect to your home network from anywhere. Prerequisites Pi with static local IP (set in router DHCP) Dynamic DNS (DuckDNS) or static public IP Port forwarding: UDP 51820 on your router to the Pi Install bash sudo apt install wireguard -y Generate Server Keys bash cd /etc/wireguard wg genkey | tee serverprivate.key | wg pubkey > serverpublic.key chmod 600 serverprivate.key Server Config /etc/wireguard/wg0.conf ini [Interface] Address = 10.0.0.1/24 ListenPort = 51820 PrivateKey = [serverprivate.key contents] 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 = [clientpublic.key] AllowedIPs = 10.0.0.2/32 Enable IP forwarding: bash echo "net.ipv4.ipforward=1" | sudo tee -a /etc/sysctl.conf sudo sysctl -p Client Config ini [Interface] Address = 10.0.0.2/32 PrivateKey = [clientprivate.key] DNS = 1.1.1.1 [Peer] PublicKey = [serverpublic.key] Endpoint = yourdomain.duckdns.org:51820 AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 25 Start bash sudo systemctl enable wg-quick@wg0 sudo systemctl start wg-quick@wg0 Import client config to WireGuard app on phone/laptop.
Related Guides
- Pi as a VPN Server (WireGuard/PiVPN)
- Build a WireGuard VPN Server on a Raspberry Pi: Secure Remote Access to Your Home Network
- Running a Minecraft Server on Raspberry Pi 5
- Setting Up Tailscale VPN on a Raspberry Pi for Remote Access
- Home Assistant on Raspberry Pi: Complete Server Setup
- Build a Raspberry Pi Travel Router
- How to Install Klipper on Any 3D Printer: Complete Setup Guide
- How to Analyze EMV Payment Cards with the Flipper Zero: NFC, APDU Commands, and Security Architecture