Ubuntu 20.04 set up WireGuard VPN server (2024)

Ubuntu 20.04 set up WireGuard VPN server (1)

How can I install and set up WireGuard VPN server on an Ubuntu 20.4 LTS Linux server? How do I configure Ubuntu 20.04 as the WireGuard VPN server?

WireGuard is an open-source, free, modern, and fast VPN with state-of-the-art cryptography. It is quicker and simpler as compared to IPSec and OpenVPN. Originally, released for the Linux kernel, but it is getting cross-platform support for other operating systems too. This page explains how to install and set up WireGuard VPN on Ubuntu 20.04 LTS Linux server.

Tutorial requirements
RequirementsUbuntu 20.04
Root privileges Yes
Difficulty level Easy
Category WireGuard VPN
Est. reading time 7 minutes

Table of contents ↓

  • 1 Update your system
  • 2 Installing a WireGuard
  • 3 Configuring WireGuard
  • 4 Set up UFW firewall
  • 5 Enable and start WireGuard
  • 6 Wireguard VPN client
  • 7 Verification
  • 8 WireGuard server firewall config
  • 9 Download mobile client
  • 10 Conclusion

nixCraft: Privacy First, Reader Supported

  • nixCraft is a one-person operation. I create all the content myself, with no help from AI or ML. I keep the content accurate and up-to-date.
  • Your privacy is my top priority. I don’t track you, show you ads, or spam you with emails. Just pure content in the true spirit of Linux and FLOSS.
  • Fast and clean browsing experience. nixCraft is designed to be fast and easy to use. You won’t have to deal with pop-ups, ads, cookie banners, or other distractions.
  • Support independent content creators. nixCraft is a labor of love, and it’s only possible thanks to the support of our readers. If you enjoy the content, please support us on Patreon or share this page on social media or your blog. Every bit helps.
Join Patreon

Procedure: Ubuntu 20.04 set up WireGuard VPN server

Our sample setup includes a simple peer connection between a cloud server running Ubuntu 20.04 LTS server, and a Ubuntu/Ubuntu/RHEL/SUSE/OpenSUSECentOS Linux desktop client:
Ubuntu 20.04 set up WireGuard VPN server (2)
The steps are as follows for installing and configuring WireGuard on Ubuntu Linux 20.04 LTS as a VPN server.

Please note that {vivek@ln-sg-vpn-001:~ }$ OR {vivek@ubuntu-20-4-vpn-client:~ }$ is my shell prompt and is not part of actual commands. In other words, you need to copy and paste command after my shell prompt.

Step 1 – Update your system

Run the apt command to install Ubuntu 20.04 security updates:
{vivek@ln-sg-vpn-001:~ }$ sudo apt update
{vivek@ln-sg-vpn-001:~ }$ sudo apt upgrade

Step 2 – Installing a WireGuard VPN server on Ubuntu 20.04 LTS

Now we got our server updates with the latest security patches. It is time for setting up a WireGuard VPN server on Ubuntu 20.04 server. Enter:
{vivek@ln-sg-vpn-001:~ }$ sudo apt install wireguard
Ubuntu 20.04 set up WireGuard VPN server (3)

Step 3 – Configuring WireGuard server

First we need to create a private and public key pair for the WireGuard server. Let us cd into /etc/wireguard using the cd command{vivek@ln-sg-vpn-001:~ }$ sudo -i
# Make a new wireguard dir if not found using mkdir command #
{root@ln-sg-vpn-001:~ }# mkdir -m 0700 /etc/wireguard/
{root@ln-sg-vpn-001:~ }# cd /etc/wireguard/

Execute the following command:
{vivek@ln-sg-vpn-001:~ }# umask 077; wg genkey | tee privatekey | wg pubkey > publickey
To view keys created use the cat command and ls command:
{vivek@ln-sg-vpn-001:~ }# ls -l privatekey publickey
{vivek@ln-sg-vpn-001:~ }# cat privatekey
## Please note down the private key ##
{vivek@ln-sg-vpn-001:~ }# cat publickey

Ubuntu 20.04 set up WireGuard VPN server (4)

Set Up WireGuard VPN on Ubuntu by Editing wg0.conf

Edit or update the /etc/wireguard/wg0.conf file as follows:
{vivek@ln-sg-vpn-001:~ }$ sudo nano /etc/wireguard/wg0.conf
## OR ##
{vivek@ln-sg-vpn-001:~ }$ sudo vim /etc/wireguard/wg0.conf

Append the following config directives:

## Set Up WireGuard VPN on Ubuntu By Editing/Creating wg0.conf File ##[Interface]## My VPN server private IP address ##Address = 192.168.6.1/24## My VPN server port ##ListenPort = 41194## VPN server's private key i.e. /etc/wireguard/privatekey ##PrivateKey = eEvqkSJVw/7cGUEcJXmeHiNFDLBGOz8GpScshecvNHU=

Save and close the file when using vim text editor.

Step 4 – Set up UFW firewall rules to open required ports

I am assuming that you have UFW configured and we are going to open UDP 41194 port using the ufw command as follows:
{vivek@ln-sg-vpn-001:~ }$ sudo ufw allow 41194/udp
Verify it:
{vivek@ln-sg-vpn-001:~ }$ sudo ufw status
Turn on IPv4 and IPv6 forwarding. Append to a file with sudo as follows using the echo command:
{vivek@ln-sg-vpn-001:~ }$ echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.d/10-wireguard.conf
{vivek@ln-sg-vpn-001:~ }$ echo 'net.ipv6.conf.all.forwarding=1' | sudo tee -a /etc/sysctl.d/10-wireguard.conf
## Reload changes using the sysctl command ##
{vivek@ln-sg-vpn-001:~ }$ sysctl -p /etc/sysctl.d/10-wireguard.conf

See firewall section below for more info.

Step 5 – Enable and start WireGuard service

Turn the WireGuard service at boot time using the systemctl command, run:
{vivek@ln-sg-vpn-001:~ }$ sudo systemctl enable wg-quick@wg0
Start the service, execute:
{vivek@ln-sg-vpn-001:~ }$ sudo systemctl start wg-quick@wg0
Get the service status, run:
{vivek@ln-sg-vpn-001:~ }$ sudo systemctl status wg-quick@wg0

Verify that interface named wg0 is up and running on Ubuntu server using the ip command:
{vivek@ln-sg-vpn-001:~ }$ sudo wg
{vivek@ln-sg-vpn-001:~ }$ sudo ip a show wg0

Ubuntu 20.04 set up WireGuard VPN server (5)

Step 6 – Wireguard VPN client configuration

The procedure for installing and configuring a VPN client is the same as setting up the server. Let us install the client on an Ubuntu Linux 20.04 LTS desktop:
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo apt install wireguard
Next we need create VPN client config on Ubuntu/Debian/CentOS Linux destkop:
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo sh -c 'umask 077; touch /etc/wireguard/wg0.conf'
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo -i
{root@ubuntu-20-4-vpn-client:~ }# cd /etc/wireguard/
{root@ubuntu-20-4-vpn-client:/etc/wireguard }# umask 077; wg genkey | tee privatekey | wg pubkey > publickey
{root@ubuntu-20-4-vpn-client:/etc/wireguard }# ls -l publickey privatekey
## Note down the privatekey ##
{root@ubuntu-20-4-vpn-client:/etc/wireguard }# cat privatekey

Ubuntu 20.04 set up WireGuard VPN server (6)
Edit the /etc/wireguard/wg0.conf file on your client side:
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo nano /etc/wireguard/wg0.conf
## OR ##
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo vim /etc/wireguard/wg0.conf

Append the following directives:

[Interface]## This Desktop/client's private key ##PrivateKey = uJPzgCQ6WNlAUp3s5rabE/EVt1qYh3Ym01sx6oJI0V4=## Client ip address ##Address = 192.168.6.2/24[Peer]## Ubuntu 20.04 server public key ##PublicKey = qdjdqh2+N3DEMDUDRob8K3b+9BZFJbT59f+rBrl99zM## set ACL ##AllowedIPs = 192.168.6.0/24## Your Ubuntu 20.04 LTS server's public IPv4/IPv6 address and port ##Endpoint = 172.105.112.120:41194## Key connection alive ##PersistentKeepalive = 15

Enable and start VPN client/peer connection, run:
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo systemctl enable wg-quick@wg0
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo systemctl start wg-quick@wg0
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo systemctl status wg-quick@wg0

Allow desktop client and Ubuntu server connection over VPN

We need to configure the server-side peer-to-peer VPN option and allow a connection between the client computer and the server. Let us go back to our Ubuntu 20.04 LTS server and edit wg0.conf file to add [Peer] (client) information as follows (type commands on your server box):
{vivek@ln-sg-vpn-001:~ }$ sudo systemctl stop wg-quick@wg0
{vivek@ln-sg-vpn-001:~ }$ sudo vi /etc/wireguard/wg0.conf

Append the following config:

[Peer]## Desktop/client VPN public key ##PublicKey = u2ao8GNNUWAirtjq0eL1UpHVkMep5/EUalbZcdH0imc=## client VPN IP address (note the /32 subnet) ##AllowedIPs = 192.168.6.2/32

Save and close the file. Next start the service again, run:
{vivek@ln-sg-vpn-001:~ }$ sudo systemctl start wg-quick@wg0

Step 7 – Verification

That is all, folks. By now, both Ubuntu servers and clients must be connected securely using a peer-to-peer VPN called WireGuard. Let us test the connection. Type the following ping command on your client machine/desktop system:
{vivek@ubuntu-20-4-vpn-client:~ }$ ping -c 4 192.168.6.1
{vivek@ubuntu-20-4-vpn-client:~ }$ sudo wg

Step 8 – Firewall configurations

The page is getting long. Hence, the firewall rules section is in the second tutorial. Please do not skip it; otherwise, it will not work correctly.

Now we have set up and configured peer-to-peer VPN networking for our Ubuntu server and client. However, you may want to give access to the Internet for all VPN clients. For these purposes, we need to set up IPv4 and IPv6 firewall rules, including NAT and IP forwarding. See the following tutorial:

Step 9 – Getting WireGuard mobile/Windows clients

You can download WireGurad clients from the following locations:

Conclusion

Congratulation! You just learned about setting up a WireGuard VPN server on Ubuntu 20.04 LTS server and peer (client machine) on both Ubuntu/CentOS Linux desktop. I strongly suggest that you read WireGuard project documentation here.

Did you notice? 🧐

nixCraft is ad-free to protect your privacy and security. We rely on reader support to keep the site running. Please consider subscribing to us on Patreon or supporting us with a one-time support through PayPal or purchase official merchandise. Your support will help us cover the costs of hosting, CDN, DNS, and tutorial creation.

I'm a seasoned professional with extensive knowledge and hands-on experience in setting up and configuring VPN servers, particularly WireGuard on Ubuntu 20.04 LTS Linux servers. My proficiency in this domain is exemplified by my ability to guide users through the installation and configuration process, ensuring a secure and efficient VPN setup.

In this comprehensive guide, the author emphasizes the use of WireGuard, an open-source, modern, and fast VPN solution renowned for its state-of-the-art cryptography. WireGuard is positioned as a superior alternative to IPSec and OpenVPN, noted for its speed and simplicity. The tutorial is structured with clarity, outlining each step meticulously to facilitate easy comprehension, making it an ideal resource for users with various levels of expertise.

The tutorial is divided into ten sections, covering essential aspects of setting up WireGuard on an Ubuntu 20.04 LTS Linux server:

  1. Update your system: The importance of keeping the system up-to-date with security patches is highlighted, demonstrating the use of sudo apt update and sudo apt upgrade commands.

  2. Installing WireGuard VPN server: The tutorial provides instructions on installing the WireGuard package using the sudo apt install wireguard command.

  3. Configuring WireGuard server: A step-by-step guide is given for creating a private and public key pair for the WireGuard server. Commands include creating directories, generating keys, and viewing key information.

  4. Set up UFW firewall: The author assumes the presence of UFW (Uncomplicated Firewall) and instructs users to open the required UDP port (41194) using sudo ufw allow 41194/udp. IPv4 and IPv6 forwarding are also configured.

  5. Enable and start WireGuard: Systemctl commands are used to enable, start, and check the status of the WireGuard service on the server.

  6. WireGuard VPN client configuration: The tutorial extends to configuring a WireGuard VPN client on an Ubuntu Linux 20.04 LTS desktop. It covers key generation, client configuration file creation, and service enablement.

  7. Verification: A brief section is dedicated to verifying the established connection using a ping command and checking the WireGuard interface.

  8. Firewall configurations: Acknowledging the length of the tutorial, the firewall rules section is deferred to a second tutorial. It emphasizes the importance of not skipping this section for correct functionality.

  9. Getting WireGuard mobile/Windows clients: The article concludes with guidance on where to download WireGuard clients for various platforms, including Apple iOS, Google Android, macOS, and Windows.

  10. Conclusion: The author congratulates the reader on successfully setting up a WireGuard VPN server on Ubuntu 20.04 LTS and provides a link to the WireGuard project documentation for further reference.

This tutorial, presented by nixCraft, is a valuable resource for individuals seeking a reliable guide to deploy WireGuard VPN on Ubuntu 20.04 LTS Linux servers, combining clarity, expertise, and a commitment to user privacy.

Ubuntu 20.04 set up WireGuard VPN server (2024)

FAQs

How to setup your own VPN server using WireGuard on Ubuntu? ›

  1. Step 1: Update Ubuntu Server packages.
  2. Step 2: Install Wireguard on ubuntu.
  3. Step 3: Generate WireGuard Server Key Pairs.
  4. Step 4: Configure IPv4 and IPv6 addresses.
  5. Step 5: Port Forwarding configuration and /etc/sysctl.conf file.
  6. Step 6: WireGuard server firewall configuration.
  7. Step 7: Start the WireGuard server in Ubuntu.
Jan 3, 2023

How to set up WireGuard VPN server? ›

How to get started with WireGuard VPN
  1. Sign up with UpCloud. ...
  2. Deploy a new cloud server. ...
  3. Installing WireGuard. ...
  4. IP forwarding. ...
  5. Configuring firewall rules. ...
  6. Generating private and public keys. ...
  7. Generate server config. ...
  8. Starting WireGuard and enabling it at boot.

Why is my WireGuard not working? ›

When a WireGuard connection isn't working, it's usually one of four things: a WireGuard configuration problem, a firewall problem, a routing problem, or a DNS problem. The tcpdump utility can help you quickly diagnose what kind of problem it is, by identifying where packets are going awry.

Which is more secure, WireGuard or OpenVPN? ›

The biggest notable differences between WireGuard and OpenVPN are speed and security. While WireGuard is generally faster, OpenVPN provides heavier security. The differences between these two protocols are also what make up their defining features.

How to setup your own VPN Ubuntu? ›

Ultimate Guide to Setting Up Your Own VPN with OpenVPN on Ubuntu
  1. Step 1: Update Your System. ...
  2. Step 2: Install OpenVPN and Easy-RSA. ...
  3. Step 3: Configure Easy-RSA. ...
  4. Step 4: Build the Certificate Authority. ...
  5. Step 5: Create the Server Certificate, Key, and Encryption Files. ...
  6. Step 6: Configure the OpenVPN Service.
May 24, 2024

Does WireGuard require a server? ›

A WireGuard VPN usually involves a client (the app on your phone, for example) and a VPN server. Like other encryption protocols, WireGuard communicates with the server and establishes an encrypted tunnel between server and client.

Do I need a static IP address for WireGuard? ›

If you have a static IP address from your ISP then you don't need to do anything, we can just use the IP name you have been given or the IP itself. If you have a dynamic IP address then you will need to setup dynamic DNS. For my setup I used NoIP.com.

What ports does WireGuard VPN server use? ›

What ports do you use for WireGuard? UDP ports 53, 80, 443, 1194, 2049, 2050, 30587, 41893, 48574, 58237.

How do I manually set a WireGuard? ›

I have a key pair
  1. Go to Surfshark's login page and log in. Then, visit VPN > Manual setup. Choose the Desktop or mobile option and click on WireGuard.
  2. In the next window, click on I have a key pair.
  3. Name your key pair and click Next.
  4. Enter your public key and hit Save.
Jun 19, 2024

How do I know if WireGuard is working Linux? ›

To view the status of one or more WireGuard tunnels, use the show wireguard [<instance>] command. This command prints the status of all WireGuard tunnels and can optionally limit the output to a specific instance.

How do I activate WireGuard automatically? ›

Autostart WireGuard in systemd
  1. Generate a valid and working WireGuard configuration file /etc/wireguard/wg0. ...
  2. Add the WireGuard service to systemd: ...
  3. Start the new service immediately: ...
  4. Reboot your computer system to verify the automatic connection on startup works as expected.
  5. Check the service status:

How do I connect to the WireGuard server? ›

Open up your web browser and paste in your server's IP address and port and hit 'Enter'. This will now take you to the login page. Simply input your username and password into the corresponding fields and click on the 'Sign In' button.

How to configure VPN in Linux server step by step? ›

2. VPN Server Setup
  1. 2.1. Basic VPS Setup. Our test VPS contains a fresh installation of Ubuntu Server 22.04, SSH access, and a root account only. ...
  2. 2.2. OpenVPN Installation. ...
  3. 2.3. Serve . ...
  4. 2.4. Fine-Tuning the OpenVPN Configuration. ...
  5. 2.5. Firewall Configuration.
Jul 6, 2024

How do I setup a custom VPN server? ›

Steps for setting up a VPN
  1. Step 1: Line up key VPN components. ...
  2. Step 2: Prep devices. ...
  3. Step 3: Download and install VPN clients. ...
  4. Step 4: Find a setup tutorial. ...
  5. Step 5: Log in to the VPN. ...
  6. Step 6: Choose VPN protocols. ...
  7. Step 7: Troubleshoot. ...
  8. Step 8: Fine-tune the connection.

How to set up an IKEv2 VPN server with StrongSwan on Ubuntu? ›

  1. Prerequisites.
  2. Step 1 — Installing StrongSwan.
  3. Step 2 — Creating a Certificate Authority.
  4. Step 3 — Generating a Certificate for the VPN Server.
  5. Step 4 — Configuring StrongSwan.
  6. Step 5 — Configuring VPN Authentication.
  7. Step 6 — Configuring the Firewall & Kernel IP Forwarding.
Sep 16, 2020

How to setup private VPN on Linux? ›

How to Install VPN on Linux?
  1. Step 1: Download. Download and install our dedicated Linux VPN after creating your account.
  2. Step 2: Log in. Use your unique username and password to log in.
  3. Step 3: Connect. Choose your country and connect to start browsing.

How to install OpenVPN on Ubuntu self hosted VPN? ›

First time connecting to the VPN server
  1. Navigate to the Client Web UI in a browser.
  2. Sign in with user credentials.
  3. Choose the OpenVPN Connect app for their operating system.
  4. After it downloads, install the software.
  5. Open the app and click on the connection profile. The user connects to Access Server.

Top Articles
The 5 Pillars of Go-to-Market Strategy: A Comprehensive G...
How to Do a Reverse Image Search From Your Phone
Cranes For Sale in United States| IronPlanet
Canary im Test: Ein All-in-One Überwachungssystem? - HouseControllers
Affidea ExpressCare - Affidea Ireland
T Mobile Rival Crossword Clue
Aadya Bazaar
Polyhaven Hdri
Costco The Dalles Or
Wild Smile Stapleton
Free Robux Without Downloading Apps
Whiskeytown Camera
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Thayer Rasmussen Cause Of Death
Cvs Learnet Modules
Athens Bucket List: 20 Best Things to Do in Athens, Greece
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Video shows two planes collide while taxiing at airport | CNN
Van Buren County Arrests.org
Fsga Golf
Jobs Hiring Near Me Part Time For 15 Year Olds
Wnem Tv5 Obituaries
The best brunch spots in Berlin
Renfield Showtimes Near Paragon Theaters - Coral Square
Vera Bradley Factory Outlet Sunbury Products
Jurassic World Exhibition Discount Code
A Man Called Otto Showtimes Near Carolina Mall Cinema
Possum Exam Fallout 76
Primerica Shareholder Account
Otis Offender Michigan
Word Trip Level 359
Scioto Post News
One Credit Songs On Touchtunes 2022
Appraisalport Com Dashboard /# Orders
Chris Provost Daughter Addie
Foolproof Module 6 Test Answers
Watchseries To New Domain
Laff Tv Passport
National Insider Threat Awareness Month - 2024 DCSA Conference For Insider Threat Virtual Registration Still Available
Craigslist Ludington Michigan
Trap Candy Strain Leafly
Indio Mall Eye Doctor
Lake Andes Buy Sell Trade
Sun Tracker Pontoon Wiring Diagram
Tricia Vacanti Obituary
3 Zodiac Signs Whose Wishes Come True After The Pisces Moon On September 16
Chubbs Canton Il
R/Gnv
Laura Houston Wbap
Acuity Eye Group - La Quinta Photos
Greg Steube Height
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 5487

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.