16.04.2025

How to Install and Configure WireGuard VPN Client on Ubuntu 20.04

WireGuard is a VPN solution renowned for its straightforwardness and effectiveness. It employs advanced cryptographic algorithms to ensure secure data transmission. Initially created for the Linux kernel, WireGuard is now also available on various platforms including Windows, macOS, BSD, iOS, and Android. This guide will walk you through the process of setting up the WireGuard VPN client on Ubuntu 20.04.

Installing the WireGuard Client on Ubuntu

The installation process for the WireGuard client mirrors the steps for the server-side setup.

  1. Log into your Linux server via SSH.
  2. Once logged in, update your system by running:
    sudo apt-get update && sudo apt-get upgrade
  3. Install WireGuard with the following command:
    sudo apt-get install wireguard

Creating Private and Public Keys

WireGuard relies on public and private key pairs for securing communication. The public key is shared with the other party, allowing them to encrypt messages that can only be decrypted with the corresponding private key. For mutual communication, both sides must have their own key pairs.

To generate a client key pair, run the following command:

wg genkey | tee private.key | wg pubkey > public.key

Next, create the configuration file for the client in the specified directory:

sudo nano /etc/wireguard/wg0.conf

Add the following content to the file:

[Interface]
PrivateKey = <contents-of-client-privatekey>
Address = 10.0.0.1/24
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
ListenPort = 51820

[Peer]
PublicKey = <contents-of-server-publickey>
AllowedIPs = 10.0.0.2/32

Important Notes:

Example of nano file with our keys:

Starting WireGuard

To activate the VPN connection, use the following command:

sudo wg-quick up wg0

You should now be able to communicate with the server. To verify the connection, try pinging the server:

ping 10.0.0.1

To check the connection status, run:

sudo wg show

This command will show all relevant connection details.

Congratulations! Your client machine is now successfully connected to the VPN network.

Conclusion

WireGuard offers a fast, secure, and easy-to-use solution for setting up VPN connections. By following the steps outlined in this guide, you can quickly establish a WireGuard client on Ubuntu 20.04 and begin secure communication with your server. Its simplicity and performance make it an excellent choice for both personal and professional use, ensuring that data remains encrypted and protected from external threats. With proper key management and firewall configuration, WireGuard provides a robust and reliable VPN service.

FAQ

Q: How can I ensure WireGuard starts automatically on boot?

Q: What should I do if I can't ping the server after setting up WireGuard?

Q: How do I update WireGuard?

Our packages were already updated, so none of them were upgraded or newly installed

Q: How do I troubleshoot WireGuard connectivity issues?

Q: Can I use WireGuard on multiple devices?