FL1GHT5 Lab • Networking

WireGuard VPN on Linux

Why WireGuard?

WireGuard is simple, fast, and highly secure. Its minimalist codebase means fewer bugs and vulnerabilities compared to legacy VPNs like OpenVPN or IPsec. This guide shows how to stand up a lean VPN with strong defaults.

Think of it like a private tunnel under a busy street. Instead of crossing out in the open where anyone can watch you, you go underground and come out exactly where you meant to, unseen the whole way.

Server prerequisites

1) Choose a Linux server

Pick a VPS with a public IPv4 (and optionally IPv6). Options to consider:

2) Install WireGuard

$sudo apt update
$sudo apt install wireguard

For other distros, use the native package manager (e.g., dnf on Fedora/RHEL, pacman on Arch).

3) Generate server keys

$sudo mkdir -p /etc/wireguard/keys
$sudo chmod 700 /etc/wireguard/keys
$cd /etc/wireguard/keys
$sudo wg genkey | sudo tee privatekey | sudo wg pubkey > publickey

4) Configure wg0.conf

$sudo nano /etc/wireguard/wg0.conf
[Interface] PrivateKey = <contents of /etc/wireguard/keys/privatekey> Address = 10.0.0.1/24 ListenPort = 51820 # Enable IP forwarding (runtime) + NAT for egress traffic # NOTE: replace eth0 with your actual NIC (e.g., ens3) PostUp = sysctl -w net.ipv4.ip_forward=1 PostUp = iptables -A FORWARD -i %i -j ACCEPT PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i %i -j ACCEPT PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

Persist forwarding:

$echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-wireguard.conf
$sudo sysctl --system

5) Open firewall

$sudo ufw allow 51820/udp
$sudo ufw allow OpenSSH
$sudo ufw enable

6) Start the service

$sudo systemctl enable wg-quick@wg0
$sudo systemctl start wg-quick@wg0
$sudo systemctl status wg-quick@wg0 --no-pager

Client configuration

1) Install client software

2) Generate client keys

$wg genkey | tee client_privatekey | wg pubkey > client_publickey

3) Create client.conf

[Interface] PrivateKey = <CLIENT_PRIVATE_KEY> Address = 10.0.0.2/32 DNS = 1.1.1.1 [Peer] PublicKey = <SERVER_PUBLIC_KEY> # Optional extra PSK: # PresharedKey = <PSK> Endpoint = <SERVER_PUBLIC_IP>:51820 AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 25

4) Add the client on the server

[Peer] PublicKey = <CLIENT_PUBLIC_KEY> AllowedIPs = 10.0.0.2/32
$sudo systemctl restart wg-quick@wg0

Verify & connect

Extras & best practices

Final thought

Building your own VPN isn’t just about privacy, it’s about control and learning. Verify each step, iterate safely, and you’ll have a fast, reliable tunnel you understand end-to-end.