How to set up Wireguard VPN on your server – Knowledge Base (2024)

This article will describe in detail how to set up Wireguard VPN on your server. It can be a virtual or private server – it doesn’t matter so much.

This VPN Wireguard setup guide is designed for users who do not have much experience, so all the steps will be quite detailed and followed by screenshots.

Traffic passing via our tunnel will be encrypted, and the Internet will display the IP address of our VPN server, not the address of the provider through which we access the network.

It is supposed that you already have a VPS. If not, you can order it from us.

We will install the Ubuntu 22.04 operating system on our server. If you have a server with a different OS, then you can easily reinstall it following the instructions.

So, the server with Ubuntu 22.04 OS ready, now we connect to it via SSH. If suddenly you have not come across this protocol before, then an article in which this process is described in detail will help you. The second paragraph of the article is for Linux OS, the third is for Windows OS.

  • 1 Set up Wireguard server
  • 2 Setting up Wireguard client
  • 3 Set up Wireguard for mobile

Set up Wireguard server

After a successful connection, I will write a few commands and a description of what they produce to understand the process:

We update the list of packages in the repositories

apt update

Renewal of packages themselves

apt upgrade -y

Install the wireguard package

apt install -y wireguard

Our configuration will be stored in the /etc/wireguard/ directory, we need to enter the directory:

cd /etc/wireguard/

We will need a public and private key for our server. We will generate them after setting the correct rights when creating files and directories with commands:

umask 077
wg genkey > privatekey
wg pubkey < privatekey > publickey

Now we set the rights for the private key:

chmod 600 privatekey

Before creating the configuration file, we need the name of our network interface. To discover it, use the command:

ip a

We need the interface with the IP address that is used for the current connection. It will probably be called ens3 in your case, but there may be another name.

How to set up Wireguard VPN on your server – Knowledge Base (1)
How to set up Wireguard VPN on your server – Knowledge Base (2)
How to set up Wireguard VPN on your server – Knowledge Base (3)

We will also need a public and private key. To display them I use tail

tail privatekey publickey

It looks like this:

How to set up Wireguard VPN on your server – Knowledge Base (4)
How to set up Wireguard VPN on your server – Knowledge Base (5)
How to set up Wireguard VPN on your server – Knowledge Base (6)

For editing, you can use any Linux text editor. I will use nano. To install it you need to run the command:

apt install -y nano

We edit the configuration file:

nano /etc/wireguard/wg0.conf

Note

in order to save the file we use the ctrl+o button combination

for exit – ctrl+x

It should look like this:

[Interface]PrivateKey = [ your private key ]Address = 10.30.0.1/24ListenPort = 51928PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o [ interface name ] -j MASQUERADEPostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o [ interface name ] -j MASQUERADE

In my case it looks like this

How to set up Wireguard VPN on your server – Knowledge Base (7)
How to set up Wireguard VPN on your server – Knowledge Base (8)
How to set up Wireguard VPN on your server – Knowledge Base (9)

We turn on ip forwarding

echo "net.ipv4.ip_forward=1" >> /etc/sysctl.confsysctl -p

Launch wireguard service:

systemctl start [emailprotected]

If we want the service to start after the server is restarted, then we do the following:

systemctl enable [emailprotected]

For viewing the service status:

systemctl status [emailprotected]

The status should be active as in the screenshot:

How to set up Wireguard VPN on your server – Knowledge Base (10)
How to set up Wireguard VPN on your server – Knowledge Base (11)
How to set up Wireguard VPN on your server – Knowledge Base (12)

If you carefully followed our instructions, then at this stage, you have everything you need to make the server part of VPN Wireguard operate.

Setting up Wireguard client

The only thing left is to configure the client part. For example and simplicity, I will generate keys for the client part also on the server. But for security purposes, it would be more correct to generate keys on the client side.I use commands for generation:

wg genkey > mypc_privatekeywg pubkey < mypc_privatekey > mypc_publickey

I will also generate keys to use the VPN on the phone:

wg genkey > myphone_privatekeywg pubkey < myphone_privatekey > myphone_publickey

It should be noted that all this is required to be done while being in the catalog

/etc/wireguard/

You can also run in another catalog. But for simplicity, we execute the instructions in /etc/wireguard/

We use the ls command to list the files in a directory. I got it like this:

How to set up Wireguard VPN on your server – Knowledge Base (13)
How to set up Wireguard VPN on your server – Knowledge Base (14)
How to set up Wireguard VPN on your server – Knowledge Base (15)

Let’s display the public keys on the screen. We will need them in order to add nodes to our network:

tail mypc_publickey myphone_publickey

For me it looks like this:

How to set up Wireguard VPN on your server – Knowledge Base (16)
How to set up Wireguard VPN on your server – Knowledge Base (17)
How to set up Wireguard VPN on your server – Knowledge Base (18)

Let’s edit our config file:

nano wg0.conf

Add the following lines:

[Peer]PublicKey = [ mypc_publickey ]AllowedIPs = 10.30.0.2/32 [Peer]PublicKey = [ myphone_publickey ]AllowedIPs = 10.30.0.3/32

Now the config file looks like this:

How to set up Wireguard VPN on your server – Knowledge Base (19)
How to set up Wireguard VPN on your server – Knowledge Base (20)
How to set up Wireguard VPN on your server – Knowledge Base (21)

Save the file and restart our service:

systemctl restart wg-quick@wg0

Let’s check that everything was successful:

systemctl status wg-quick@wg0

The status must be active

Reloading the service is required every time after editing the server configuration file (wg0.conf)

Next, we will create configurations for clients (in my case, my PC and phone). I will do the same on the server.

nano mypc.conf
[Interface] PrivateKey = [mypc_privatekey private key] Address = 10.30.0.2/32 DNS = 8.8.8.8 [Peer] PublicKey = [publickey server publc key] Endpoint =[ server ip address]:51928 AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 20

In the Endpoint field, you can see the server’s IP address – this is the IP address that we used to connect via SSH. To see the interfaces and addresses, you can use the ip a command.

Set up Wireguard for mobile

We create a similar configuration for our phone. Just need to change the address. For the PC it was 10.30.0.2/32, and in the configuration for the phone we will make 10.30.0.3/32. Also, if we want to use VPN on other devices, then we should add other addresses to the Address field in the configuration files and the wg0.conf server configuration file, the AllowedIPs field when creating configurations

Files look like that in my case:

mypc.conf

How to set up Wireguard VPN on your server – Knowledge Base (22)
How to set up Wireguard VPN on your server – Knowledge Base (23)
How to set up Wireguard VPN on your server – Knowledge Base (24)

myphone.conf

How to set up Wireguard VPN on your server – Knowledge Base (25)
How to set up Wireguard VPN on your server – Knowledge Base (26)
How to set up Wireguard VPN on your server – Knowledge Base (27)

For connection, we install wireguard client https://www.wireguard.com/install/

In the Windows application, we add a new tunnel and enter the configuration created in the mypc.conf file

How to set up Wireguard VPN on your server – Knowledge Base (28)

We launch the tunnel and go to the browser to the website that displays our address

How to set up Wireguard VPN on your server – Knowledge Base (29)

In order to conveniently add a VPN to your phone, install a program for generating qr codes on the server:

apt install -y qrencode

Being in theconfiguration directory, make the following step:

qrencode -t ansiutf8 -r myphone.conf
How to set up Wireguard VPN on your server – Knowledge Base (30)

Then we enter the Wireguard app on the phone, press + to create a new tunnel, select scan the QR code, scan it, turn on the VPN. Next, we will check that we are displaying the address of our server by using any resource that displays the output IP address.

How to set up Wireguard VPN on your server – Knowledge Base (31)
How to set up Wireguard VPN on your server – Knowledge Base (32)
How to set up Wireguard VPN on your server – Knowledge Base (33)
How to set up Wireguard VPN on your server – Knowledge Base (34)
How to set up Wireguard VPN on your server – Knowledge Base (35)
How to set up Wireguard VPN on your server – Knowledge Base (36)

You did it!

Previous article 3proxy configuration on CentOS/ArchLinux

Next article VPN server setup on Linux: PPTP or OpenVPN?

How to set up Wireguard VPN on your server – Knowledge Base (2024)

FAQs

How do I setup a 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.

How do I connect to VPN with WireGuard? ›

1 Answer
  1. On both machines: download WireGuard. ...
  2. On server machine: configuration. ...
  3. On client machine: configuration. ...
  4. Important note: Keep these files secure! ...
  5. On server machine: add the client to server configuration. ...
  6. On client machine: change network type to Private. ...
  7. Firewall / router configuration.
Feb 26, 2023

How to setup WireGuard VPN server on pfSense? ›

Set WireGuard Configuration
  1. In your pfSense device, navigate to VPN > WireGuard and click + Add Tunnel .
  2. Check Enabled .
  3. Enter a Description , like IVPN WG.
  4. Upload the Public key and obtain a client IP address: ...
  5. Enter the client IP address into Address field.

How to setup WireGuard VPN server on OpenWrt? ›

We will cover the following steps:
  1. Get your key pair.
  2. I have a key pair.
  3. I don't have a key pair.
  4. Choose a Surfshark server.
  5. Install and configure WireGuard.
  6. Configure the interface.
  7. Configure the VPN Zone.
  8. Ensure the connection is successful.
Jan 26, 2024

How to setup a VPN server? ›

Set Up a VPN on an Android Device

Go to “Settings” and from there click “Network & Internet” then “Advanced” and, finally, “VPN.” Click “Add VPN.” Fill out your VPN's “Name” and “Server” and hit save. Click on your newly added VPN profile and fill out the “Account” and “Password” fields then click “Connect.”

How to setup WireGuard server on Windows server? ›

WireGuard Windows setup
  1. Download the current version for Windows: https://www.wireguard.com/install/ and install.
  2. Run C:\Program Files\WireGuard\wireguard.exe and add an empty tunnel (we will configure the server side): ...
  3. Add another empty tunnel (we will configure the client side): Add tunnel → Add empty tunnel.

How do I know if WireGuard VPN is working? ›

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.

What ports does WireGuard VPN server use? ›

By default, WireGuard uses UDP port 51820. L2TP (Layer Two Tunneling Protocol) - this one uses various port numbers as well; TCP port 1701, UDP port 4500, and UDP port 500.

How do I check my WireGuard connection? ›

To check if WireGuard Server is working properly

The simpliest way is to use a cell phone with WireGuard official client app installed, turn off its Wi-Fi connection, and only connect to Internet via 3G/4G/5G.

How to set up VPN server on pfSense? ›

Create the OpenVPN server
  1. From the pfSense menu, select VPN, and OpenVPN. Click Add.
  2. Select the Server mode, either Remote Access (SSL/TLS), Remote Access (User Auth), or Remote Access (SSL/TLS + User Auth).
  3. Change the Local port if necessary. Otherwise, the default is 1194.
  4. Name your server in the Description section.
Dec 11, 2023

How to setup VPN client on pfSense? ›

3. Configuring OpenVPN on pfSense
  1. Access pfSense the main menu. Select the “VPN” tab and click on “OpenVPN”.
  2. Select the “Clients” tab and click on the “Add” button.
  3. You will be presented with fields that are required to configure OpenVPN on pfSense. Fill in the fields as given below:
Nov 9, 2023

How do I install and configure WireGuard VPN on Linux? ›

Installing and Configuring WireGuard on the server
  1. Connect to your Instance via SSH.
  2. Install Linux kernel headers and WireGuard. sudo apt update && apt upgrade -y. sudo apt install linux-headers-$(uname --kernel-release) # installs the right kernel headers for your version. sudo apt install wireguard.
Mar 28, 2019

How to setup WireGuard VPN server Debian? ›

Configuring a VPN with WireGuard on Debian 12
  1. Step 1: Install WireGuard. First, you'll need to install WireGuard. ...
  2. Step 2: Generate Keys. Next, generate the private and public keys for the server: ...
  3. Step 3: Configure WireGuard Interface. ...
  4. Step 4: Configure Firewall. ...
  5. Step 5: Set up a Peer.
Jan 24, 2024

How do I set up WireGuard client in VPN Fusion? ›

Configure the VPN Fusion interface
  1. Once there, you'll have to log in. ...
  2. On your router's web panel interface's left side, look for the VPN option and click on it. ...
  3. Configure a new connection by pressing on Add profile.
  4. Change the VPN type to WireGuard and click on Upload Config.
Mar 1, 2024

How to setup WireGuard VPN server on Android? ›

Install the WireGuard app for Android. Sign in to your account on our website and go to Settings -> WireGuard Configs. Select the VPN server you want to connect to. In the field below, you will get the Wireguard configuration and the QR code for the selected server.

Is WireGuard easy to setup? ›

Simple & Easy-to-use

WireGuard aims to be as easy to configure and deploy as SSH. A VPN connection is made simply by exchanging very simple public keys – exactly like exchanging SSH keys – and all the rest is transparently handled by WireGuard. It is even capable of roaming between IP addresses, just like Mosh.

Is WireGuard VPN free? ›

WireGuard is originally open source and can be used for free, absolutely.

Do you need a VPN for WireGuard? ›

WireGuard is an extremely fast yet secure VPN protocol that can also be used as a standalone VPN. In fact, it's considered the fastest VPN protocol available today, making it a better option than IPsec/IKEv2 or OpenVPN when you're looking for speed and performance.

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 6226

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.