adi-goldstein-EUsVwEOsblE-unsplash

How to Install and Set Up WireGuard VPN on Linux

WireGuard is a relatively new VPN technology that is becoming increasingly popular for its simplicity, speed, and security. In this tutorial, we’ll guide you through the process of installing and setting up WireGuard VPN on your Linux machine.

Step 1: Check the Kernel Version Before you start

make sure that your Linux kernel is version 3.10 or higher, as WireGuard requires this to run. You can check your kernel version by typing the following command in your terminal:

uname -r

Step 2: Install WireGuard

WireGuard is available in most Linux distributions’ official repositories. To install it, type the following command in your terminal:

For Debian/Ubuntu based systems:

sudo apt-get install wireguard

For CentOS/RHEL based systems:

 yum install wireguard-tools

Step 3: Generate Public and Private Keys

WireGuard uses public-key cryptography to establish a secure connection. You’ll need to generate a pair of public and private keys for your VPN server and client. To generate them, type the following command in your terminal:

umask 077
wg genkey | tee privatekey | wg pubkey > publickey

This will generate a private key and a public key. Make sure to keep the private key safe, as it should only be known to you.

Step 4: Configure the VPN Server

Next, you’ll need to configure the VPN server. This involves creating a configuration file and setting up the network interface. Here’s an example configuration file:

[Interface]
PrivateKey = <server-private-key>
Address = 10.0.0.1/24
ListenPort = 51820

[Peer]
PublicKey = <client-public-key>
AllowedIPs = 10.0.0.2/32

Replace <server-private-key> with the private key you generated in Step 3, and <client-public-key> with the public key of the client you’ll be connecting to. You can add more [Peer] sections to allow more clients to connect.

Save this configuration file as /etc/wireguard/wg0.conf, and then start the WireGuard service by typing:

sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0

Step 5: Configure the VPN Client

To connect to the VPN server, you’ll need to configure the client. This involves creating a configuration file similar to the server’s configuration file. Here’s an example:

makefileCopy code[Interface]
PrivateKey = <client-private-key>
Address = 10.0.0.2/24

[Peer]
PublicKey = <server-public-key>
Endpoint = <server-ip>:51820
AllowedIPs = 0.0.0.0/0

Replace <client-private-key> with the private key you generated in Step 3, <server-public-key> with the public key of the server, and <server-ip> with the IP address of the server.

Save this configuration file as /etc/wireguard/wg0.conf, and then start the WireGuard service by typing:

sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0

That’s it! You should now be able to connect to your WireGuard VPN server. You can check the status of your VPN connection by typing:

sudo wg show

In this tutorial, we’ve covered the basics of installing and setting up WireGuard VPN on Linux. With its simplicity, speed, and security, WireGuard is