Hostxpeed
Login Get Started →
Security

How to Set Up VPN on VPS (WireGuard)

8 min read
26 views
Jun 10, 2026

Step 1: Install WireGuard

sudo apt update && sudo apt install wireguard -y

Step 2: Generate Server Keys

cd /etc/wireguard
umask 077
wg genkey | tee server_private_key | wg pubkey > server_public_key

Step 3: Create Server Config

sudo nano /etc/wireguard/wg0.conf

Add:

[Interface]
PrivateKey =
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 =
AllowedIPs = 10.0.0.2/32

Step 4: Enable IP Forwarding

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

Step 5: Start WireGuard

sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0

Was this article helpful?