Skip to content
TrySitePrice

Ubuntu 20.04 set up WireGuard VPN server

Best/Tutorial

Here are the general steps to set up a WireGuard VPN server on Ubuntu 20.04:

  1. Install the WireGuard package by running the following command:

sudo apt install wireguard

  1. Create a new WireGuard configuration file for the server. You can do this by running the following command:

sudo nano /etc/wireguard/wg0.conf

This will open the Nano text editor, where you can add the server's configuration.

  1. Inside the configuration file, add the following information:

Address = 10.0.0.1/24

ListenPort = 51820

SaveConfig = true

PublicKey = <client public key>

AllowedIPs = 10.0.0.2/32

  • In the section, you can specify the IP address and subnet mask for the server, as well as the listening port.
  • In the section, you can specify the public key of the client, as well as the IP address range that the client will be assigned.
  1. Generate a private and public key pair for the server by running the following command:

sudo wg genkey | tee privatekey | wg pubkey > publickey

  1. Add the server's public key to the configuration file by running the following command:

sudo nano /etc/wireguard/wg0.conf

  1. Inside the configuration file, add the following information:

Address = 10.0.0.1/24

ListenPort = 51820

PrivateKey = <server private key>

SaveConfig = true

  1. Enable and start the WireGuard service by running the following command:

sudo systemctl enable --now wg-quick@wg0

  1. Configure the firewall to allow incoming WireGuard traffic by running the following command:

sudo ufw allow 51820/udp

  1. You can also configure the firewall to forward the traffic to the wireguard interface by running:

sudo nano /etc/ufw/before.rules

  1. Add these line at the top of the file:

*nat

:POSTROUTING ACCEPT [0:0]

-A POSTROUTING -o ens3 -j MASQUERADE

COMMIT

  1. Restart the firewall service

sudo ufw disable

sudo ufw enable

Once you've completed these steps, you should have a working WireGuard VPN server on Ubuntu 20.04. You can now generate a client configuration and connect to the server using the WireGuard client on a different device.

Please note, this guide is just a basic setup, and there are other things to consider like security, firewall, and routing. Consider consulting the official documentation for more detailed information.