Installing WG on Ubuntu - lmkelly/Autoguard GitHub Wiki

Install wireguard

sudo apt install wireguard

Generate keypair

wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey

Create config file

nano /etc/wireguard/wg0.conf

Sample config

[Interface]
Address = 192.168.10.1/24
SaveConfig = true
ListenPort = 45376
PrivateKey = [pvt key]
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

Lock down the files

chmod 600 /etc/wireguard/privatekey
chmod 600 /etc/wireguard/wg0.conf

Enable the interface at startup

systemctl enable wg-quick@wg0

Start the interface

wg-quick up wg0

Check status

wg show wg0