Simple WireGuard config used on an Ubuntu 22.04 VPS
- Install necessary tools
sudo apt-get update
sudo apt-get install wireguard-tools
- Generate key pairs
wg genkey | sudo tee /etc/wireguard/private.key
sudo chmod go= /etc/wireguard/private.key
sudo cat /etc/wireguard/private.key | wg pubkey | sudo tee /etc/wireguard/public.key
- Enable
ipv4
andipv6
port forwarding
;/etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
- Apply changes
sudo sysctl -p
- Allow WireGuard on INPUT chain
sudo ufw allow 51820/udp
sudo ufw allow OpenSSH
-
Copy across
wg0.conf
to/etc/wireguard/wg0.conf
-
Start server
sudo wg-quick up wg0
- Add a peer to the server
sudo wg set wg0 peer peer_pub_key allowed-ips 10.8.0.2,fd0d:86fa:c3bc::2
[Interface]
PrivateKey = <>
Address = 10.8.0.2/24, fd24:609a:6c18::2/64
DNS = 2606:4700:4700::1111
[Peer]
PublicKey = <>
AllowedIPs = 0.0.0.0/0, ::/0