Introduction, WireGuard is a relatively new VPN protocol but has become popular thanks to its speed, security, and ease of use. It uses modern encryption techniques and is suitable for both servers and mobile devices. In this guide, we will learn how to install and set up WireGuard on Ubuntu 20.04.
Steps
1. Update the system Before installing any new software, make sure the system is up to date to ensure you have the latest packages.
sudo apt update
sudo apt upgrade2. Install WireGuard, Ubuntu 20.04 already has WireGuard packages in the official repositories, so you can easily install it using apt:
sudo apt install wireguard3. Generating public and private keys, WireGuard relies on public and private encryption keys.
First, we need to generate these keys. Navigate to the /etc/wireguard to store the keys:
sudo mkdir /etc/wireguard
cd /etc/wireguard
sudo umask 077
sudo wg genkey | sudo tee privatekey | sudo wg pubkey | sudo tee publickeyprivatekey: Your private key.publickey: Your public key.4. Setting up WireGuard After generating the keys, we need to set up a configuration file. Create a new file:
sudo nano /etc/wireguard/wg0.confThen add the following configuration:
[Interface]
PrivateKey = put_your_private_key_here
Address = 10.0.0.1/24
ListenPort = 51820
[Peer]
PublicKey = Put_Your_Client_Public_Key_Here
AllowedIPs = 10.0.0.2/325. Activate and run WireGuard, after completing the configuration, you can activate and run WireGuard:
sudo wg-quick up wg0To stop the service:
sudo wg-quick down wg0To make sure the service runs automatically at startup:
sudo systemctl enable wg-quick@wg06. Verifying the connection, To verify that the connection has been set up successfully, you can use the following command to see the status of the connection and switches:
sudo wg