News
New 1-Click Apps are now available in the Serverspace control panel
JT
May 25 2026
Updated May 25 2026

How to Set Up WireGuard VPN Server on Ubuntu 20.04

WireGuard is an application that allows you to establish a secure virtual private network (VPN), known for its simplicity and ease of use. It uses proven cryptographic protocols and algorithms to protect data. Originally designed for the Linux kernel, it can be deployed on Windows, macOS, BSD, iOS and Android.

This WireGuard vpn setup uses Ubuntu 20.04.

Installing WireGuard Server on Ubuntu Linux

Log in via SSH to the Linux server, after logging in, check if the machine is updated by running the following command:

sudo apt-get update && sudo apt-get upgrade

Now install WireGuard by running the following command:

sudo apt-get install wireguard

2_vpn02

Setting up IP Forwarding

For VPN to work we need to enable packet forwarding, only then we will be able to connect through Wireguard server, to do this we need to edit /etc/sysctl.conf file:

sudo nano /etc/sysctl.conf

remove the "#" for the following command:

net.ipv4.ip_forward=1

After that, run the following command to apply the changes:

sysctl -p

The following message will be displayed:

46_vpns1

Generation of Private and Public Keys

WireGuard works by encrypting the connection using a cryptographic key pair. The key pair is used by passing the public key to the other party, which can then encrypt its message so that it can only be decrypted with the corresponding private key. To secure two-way communication, each side must have its own private and public keys, since each pair provides only one-way communication.

Before generating the key pair, go to the

sudo cd /etc/wireguard

Set the permission for this directory:

umask 077

To generate a key pair, type the following command:

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

Setting Up the Server Configuration

To start configuring the WireGuard server, go to the /etc/wireguard folder and create the file wg0.conf

sudo nano /etc/wireguard/wg0.conf

Add the following directives to the configuration file:

[Interface]
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 =
AllowedIPs = 10.0.0.2/32

54_vpns2

Copy the private key we generated earlier and paste it into the PrivateKey.

Similarly, we have to generate a key pair for the client, copy the client's public key and paste it into PublicKey.

To copy the key value, run the following command:

sudo cat /etc/wireguard/public.key
sudo cat /etc/wireguard/private.key

Launch WireGuard and Make It Start at Boot

Now we are ready to start the server, to start WireGuard we use wg-quick and specify the name of the new interface:

wg-quick up wg0

If the configuration is perfect, you will see the following screen,

89_vpn1

To check the status of the WireGuard server enter:

wg show

78_vpns4

Congratulations, we have successfully started up the WireGuard server!

Installing WireGuard on the Client

The client setup depends on the operating system you are using. On Ubuntu/Debian-based systems, install WireGuard using the same command as on the server:

sudo apt-get install wireguard

On Windows or macOS, download and install the official WireGuard client from the official website at wireguard.com/install.

Generating Client Keys

On the client machine, generate a dedicated key pair just as we did on the server. First, navigate to the WireGuard directory and set permissions:

sudo cd /etc/wireguard
umask 077

Then generate the client key pair:

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

Retrieve both key values for use in the configuration files:

sudo cat /etc/wireguard/client-public.key
sudo cat /etc/wireguard/client-private.key

Copy the client public key and paste it into the [Peer] section of the server's wg0.conf file under the PublicKey field, as described in the server configuration step above.

Setting Up the Client Configuration

On the client machine, create the configuration file wg0.conf:

sudo nano /etc/wireguard/wg0.conf

Add the following directives, replacing the placeholders with your actual values:

[Interface]
PrivateKey =
Address = 10.0.0.2/32
DNS = 8.8.8.8

[Peer]
PublicKey =
Endpoint = :51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

Connecting the Client to the Server

Once the configuration file is saved, bring up the WireGuard tunnel on the client:

wg-quick up wg0

To verify the connection is established and the handshake with the server has occurred, run:

wg show

You should see the server listed as a peer with a recent last handshake timestamp. To enable the client tunnel automatically at system boot, run:

sudo systemctl enable wg-quick@wg0

Congratulations, the client is now securely connected to the WireGuard VPN server!

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33401 West Palm Beach, FL 700 S Rosemary Ave, Suite 204
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP | All rights reserved
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.