How to Install WireGuard on Ubuntu Server Latest

WireGuard is an open-source VPN solution which is simple, fast, and secure. In this tutorial, we will walk you through how to install WireGuard on the latest version of Ubuntu Server.

Prerequisites

Before we start the installation, we need to ensure that the following prerequisites are met:

Step 1: Adding WireGuard PPA Repository

The first step is to add the WireGuard PPA repository to your Ubuntu Server. We will use this repository to install the WireGuard software.

  1. First, update the package list using the following command:
sudo apt update
  1. Next, install the software-properties-common package, which is required to add new repositories using the following command:
sudo apt install software-properties-common -y
  1. Now add the WireGuard PPA repository to your Ubuntu Server using the following command:
sudo add-apt-repository ppa:wireguard/wireguard
  1. To finish this step, update the package list once again using the following command:
sudo apt update

Step 2: Installing WireGuard

Now that we have added the WireGuard PPA repository, we can go ahead and install it.

  1. Install WireGuard using the following command:
sudo apt install wireguard -y
  1. Once the installation is complete, check the version of WireGuard installed using the following command:
sudo wg

If the output of the above command is something like command not found: wg, it means that there is an issue with the installation. You will need to troubleshoot the installation and try again.

Step 3: Configuring WireGuard

Now that WireGuard is installed, it's time to configure it to connect to your VPN network.

  1. First, create a directory to store your WireGuard configuration files using the following command:
sudo mkdir /etc/wireguard
  1. Next, generate a private key using the following command:
sudo wg genkey | tee /etc/wireguard/privatekey | wg pubkey > /etc/wireguard/publickey

This command will generate a private key and a public key, and save them to the /etc/wireguard/privatekey and /etc/wireguard/publickey files respectively.

  1. Now create a configuration file for your WireGuard VPN interface using the following command:
sudo nano /etc/wireguard/wg0.conf
  1. Add the following configuration to the file:
[Interface]
Address = 10.0.0.1/24
PrivateKey = <private key>
ListenPort = 51820

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

Replace the <private key> and <peer public key> placeholders with the actual keys generated in the previous step.

  1. Save and exit the file.

  2. Now start the WireGuard service using the following command:

sudo systemctl start wg-quick@wg0

Step 4: Testing WireGuard

To test if WireGuard is working correctly, you can ping the remote server.

  1. On the client machine, install WireGuard using the same procedure as above.

  2. Create a configuration file for the WireGuard interface on the client machine using the following command:

sudo nano /etc/wireguard/wg0.conf
  1. Add the following configuration to the file:
[Interface]
Address = 10.0.0.2/24
PrivateKey = <private key of client>

[Peer]
PublicKey = <public key of server>
AllowedIPs = 10.0.0.1/32
Endpoint = <server public ip>:51820

Replace the <private key of client>, <public key of server>, and <server public ip> placeholders with the actual keys and IP address of the server.

  1. Save and exit the file.

  2. Start the WireGuard service on the client machine using the following command:

sudo systemctl start wg-quick@wg0
  1. Finally, ping the IP address of the server using the following command:
ping 10.0.0.1

If the ping is successful, it means that WireGuard is working correctly.

Conclusion

In this tutorial, we have shown you how to install and configure WireGuard on the latest version of Ubuntu Server. With WireGuard, you can now enjoy a fast, secure, and easy-to-use VPN solution on your Ubuntu Server.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!