Skip to content

Create your own private self-hosted VPN in 1 hour

Notifications You must be signed in to change notification settings

coffeeboost/vpn-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🌐 WireGuard VPN Server on Google Cloud

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.


πŸ”‘ Generate Server Keys

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.

πŸ“ Create WireGuard Config File

sudo nano /etc/wireguard/wg0.conf
  • πŸ“ Add your [Interface] and [Peer] sections manually.
  • πŸ“ %i is replaced by wg0 when using wg-quick.
  • πŸ“ Replace eth0 with your VM’s external interface (check with ip a).
  • πŸ“ Add additional [Peer] blocks for each client.

🚦 Start and Stop WireGuard

sudo wg-quick up wg0      # Start the VPN interface
sudo wg-quick down wg0    # Stop the VPN interface

πŸ” Restart WireGuard

sudo wg-quick down wg0 && sudo wg-quick up wg0

βš™οΈ Enable/Disable Auto-Start on Boot

sudo systemctl enable wg-quick@wg0    # Enable auto-start
sudo systemctl disable wg-quick@wg0   # Disable auto-start

πŸ” Monitor VPN Status

sudo 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.

🌐 Enable IP Forwarding

echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

πŸ”₯ Create GCP Firewall Rule

gcloud 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.

About

Create your own private self-hosted VPN in 1 hour

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors