Introduction
WireGuard is a modern VPN protocol designed to be fast, simple, and secure.
Prerequisites
- A Linux server (Ubuntu LTS or Debian stable)
- Root or sudo access
- Basic networking knowledge
Installation
bash
1sudo apt update && sudo apt upgrade -y2sudo apt install wireguard wireguard-tools -yKey Generation
bash
1wg genkey | sudo tee /etc/wireguard/private.key2sudo chmod 600 /etc/wireguard/private.key3sudo cat /etc/wireguard/private.key | wg pubkey | sudo tee /etc/wireguard/public.keySecurity note
Never share your private key.
Server Configuration
ini
1# /etc/wireguard/wg0.conf2[Interface]3PrivateKey = <server_private_key>4Address = 10.0.0.1/245ListenPort = 518206PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE7PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE8 9[Peer]10PublicKey = <client_public_key>11AllowedIPs = 10.0.0.2/32Enable IP forwarding:
bash
1echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-wireguard.conf2sudo sysctl --systemFirewall
bash
1sudo ufw allow 51820/udp2sudo ufw enableStart the VPN
bash
1sudo systemctl enable wg-quick@wg02sudo systemctl start wg-quick@wg03sudo wg showConclusion
WireGuard provides a clean, auditable VPN setup with excellent performance.
WireGuard
Linux
UFW
iptables