To set up WireGuard VPN on Amazon Linux 2, you can use the following steps:
sudo amazon-linux-extras install wireguard
This will install the WireGuard kernel module and the wg-quick
utility.
sudo wg genkey | sudo tee /etc/wireguard/server-privatekey | sudo wg pubkey | sudo tee /etc/wireguard/server-publickey sudo tee /etc/wireguard/wg0.conf << EOF [Interface] Address = 10.0.0.1/24 ListenPort = 51820 PrivateKey = $(cat /etc/wireguard/server-privatekey) [Peer] PublicKey = $(cat /etc/wireguard/client-publickey) AllowedIPs = 10.0.0.2/32 EOF
Replace client-publickey
with the public key of the client that will connect to the server. You can generate a private/public key pair for the client using the wg genkey
and wg pubkey
commands.
sudo systemctl enable --now wg-quick@wg0
sudo firewall-cmd --add-port=51820/udp --permanent sudo firewall-cmd --reload
On the client, create the configuration file for the VPN client:
wg genkey | tee client-privatekey | wg pubkey | sudo tee client-publickey sudo tee /etc/wireguard/wg0.conf << EOF [Interface] PrivateKey = $(cat client-privatekey) Address