Docs / Networking / How to Set Up a VPN Server with WireGuard

How to Set Up a VPN Server with WireGuard

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 223 views · 1 min read

WireGuard is a modern, fast VPN protocol that's simpler than OpenVPN.

Install

apt install wireguard -y

Generate Keys

wg genkey | tee /etc/wireguard/private.key | wg pubkey > /etc/wireguard/public.key\nchmod 600 /etc/wireguard/private.key

Server Config

Create /etc/wireguard/wg0.conf:

[Interface]\nAddress = 10.0.0.1/24\nListenPort = 51820\nPrivateKey = SERVER_PRIVATE_KEY\nPostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\nPostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE\n\n[Peer]\nPublicKey = CLIENT_PUBLIC_KEY\nAllowedIPs = 10.0.0.2/32

Start

systemctl enable --now wg-quick@wg0

Firewall

ufw allow 51820/udp

Enable Forwarding

echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf\nsysctl -p

Was this article helpful?