How to Set Up WireGuard VPN on Amazon Linux 2

How to Set Up WireGuard VPN on Amazon Linux 2

To set up WireGuard VPN on Amazon Linux 2, you can use the following steps:

  1. Install the required packages:
r‮e‬fer to:lautturi.com
sudo amazon-linux-extras install wireguard

This will install the WireGuard kernel module and the wg-quick utility.

  1. Create the configuration file for the VPN server:
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.

  1. Enable and start the WireGuard service:
sudo systemctl enable --now wg-quick@wg0
  1. Configure the firewall to allow incoming connections to the WireGuard service:
sudo firewall-cmd --add-port=51820/udp --permanent
sudo firewall-cmd --reload
  1. Test the connection:

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
Created Time:2017-10-29 22:08:35  Author:lautturi