Installing WireGuard
sudo apt-get install wireguard -y
Configuring WireGuard
Create WireGuard private key
# Create private key (generate)
wg genkey | sudo tee /etc/wireguard/private.key
# Remove group/other permissions from private.key
sudo chmod go= /etc/wireguard/private.key
# Derive public key from private
sudo cat /etc/wireguard/private.key | wg pubkey | sudo tee /etc/wireguard/public.key
Create WireGuard configuration
cat <<'EOF' > /etc/wireguard/wg0.conf
[Interface]
PrivateKey = <base64_encoded_private_key_goes_here>
Address = 10.128.0.1/24
ListenPort = 51820
[Peer]
PublicKey = <private-key-hex>
AllowedIPs = 10.128.0.0/24
Endpoint = 10.128.0.2/24
EOF
Start WireGuard server
sudo systemctl start wg-quick@wg0.service
Things to Understand
Both client and server configurations have [Interface] section defined, but only server has ListenPort.
Server has list of [Peer] sections for each client and does not have Endpoint.
On the other hand, client has Endpoint section.
Debugging Wireguard
modprobe wireguard && echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control