This guide walks you through setting up and managing a WireGuard VPN server on a Google Cloud VM. It includes key generation, firewall setup, service control, monitoring, and maintenance.
wg genkey | tee server_private.key | wg pubkey > server_public.key
chmod 600 server_private.keyπ Use server_private.key in your server config. Share server_public.key with clients.
sudo nano /etc/wireguard/wg0.conf- π Add your
[Interface]and[Peer]sections manually. - π
%iis replaced bywg0when usingwg-quick. - π Replace
eth0with your VMβs external interface (check withip a). - π Add additional
[Peer]blocks for each client.
sudo wg-quick up wg0 # Start the VPN interface
sudo wg-quick down wg0 # Stop the VPN interfacesudo wg-quick down wg0 && sudo wg-quick up wg0sudo systemctl enable wg-quick@wg0 # Enable auto-start
sudo systemctl disable wg-quick@wg0 # Disable auto-startsudo wg show # Show interface and peer status
sudo journalctl -u wg-quick@wg0 # View logs
sudo journalctl -f -u wg-quick@wg0 # Live log streamπ Look for βlatest handshakeβ to confirm active connections.
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -pgcloud compute firewall-rules create allow-wireguard \
--direction=INGRESS \
--priority=1000 \
--network=default \
--action=ALLOW \
--rules=udp:51820 \
--source-ranges=0.0.0.0/0π Adjust source-ranges to restrict access if needed.