CentOS 8 set up WireGuard VPN server

Setting up a WireGuard VPN server on CentOS 8 is a relatively simple process, and can be done by following these steps:

  1. First, enable the EPEL (Extra Packages for Enterprise Linux) repository by running the command:
sudo dnf install epel-release
  1. Next, install the WireGuard package by running the command:
sudo dnf install wireguard-dkms wireguard-tools
  1. After the installation is complete, you can create a new WireGuard interface by running the command:
sudo wg genkey | sudo tee /etc/wireguard/privatekey | sudo wg pubkey > /etc/wireguard/publickey
  1. Next, create a new configuration file for the WireGuard interface by running the command:
sudo nano /etc/wireguard/wg0.conf
  1. Add the following to the configuration file, replacing the IP addresses and keys with the appropriate values for your setup:
[Interface]
PrivateKey = <privatekey>
ListenPort = 51820

[Peer]
PublicKey = <client public key>
AllowedIPs = <client IP address>/32

  1. Once you’ve created the configuration file, you can enable the WireGuard interface by running the command:
sudo systemctl enable --now wg-quick@wg0
  1. To check the status of the WireGuard interface, you can run the command:
sudo wg show
  1. To add a new client to the VPN, you will need to generate a key pair for the client by running the command:
sudo wg genkey | sudo tee /etc/wireguard/client1_privatekey | sudo wg pubkey > /etc/wireguard/client1_publickey
  1. Next, you need to add the client’s public key to the server’s configuration file by running the command:
sudo nano /etc/wireguard/wg0.conf
  1. Add the following to the configuration file, replacing the IP address and key with the appropriate values for the client:
[Peer]
PublicKey = <client1_publickey>
AllowedIPs = <client1 IP address>/32
  1. Finally, you need to reload the WireGuard interface by running the command:
sudo systemctl reload wg-quick@wg0

The client can now connect to the VPN using the WireGuard client, using the private key and server’s public key generated earlier.

Keep in mind that this is a basic setup and you will have to configure your firewall and IP forwarding rules to allow VPN traffic. Also, it’s recommended to use a static IP address for your VPN server and also consider securing your VPN with a pre-shared key and/or a certificate.

Leave a Comment