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? ›

Go to [VPN] > [VPN Server] > enable and click [WireGuard® VPN] > click add button. 4. For general devices like laptops or phones, you can just click the Apply button.

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 does WireGuard server work? ›

At the heart of WireGuard is a concept called Cryptokey Routing, which works by associating public keys with a list of tunnel IP addresses that are allowed inside the tunnel. Each network interface has a private key and a list of peers. Each peer has a public key.

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 do I access WireGuard server? ›

How to visit WireGuard client LAN side from Server
  1. Go to the VPN Dashboard of the Server. Click the icon and enter the custom rule page. ...
  2. Go to the WireGuard Server you will see the client IP (Gateway) in Profiles and click the modify icon. Click Set More. ...
  3. Download the configuration.

How to setup WireGuard VPN on Windows? ›

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.
Feb 27, 2024

What port does the WireGuard server use? ›

The port used by the peer for WireGuard traffic. The default port is 51820 if left empty. If the Endpoint is empty, this value is ignored. An interval, in seconds, at which an empty packet is sent to the peer to keep the session active.

How to setup VPN on Linux server? ›

Set Up a Linux VPN Server With Hostinger OpenVPN VPS Template
  1. Log in to hPanel and click VPS on the top menu.
  2. Select the VPS you want to install OpenVPN on.
  3. Navigate to the sidebar → OS & Templates → Operating System.
  4. Click Applications.
  5. Select Ubuntu 22.04 64bit with OpenVPN from the drop-down menu and click Change OS.
Mar 20, 2024

How do I test if my WireGuard is working? ›

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.

Which is more secure WireGuard or OpenVPN? ›

While WireGuard is generally faster, OpenVPN provides heavier security. The differences between these two protocols are also what make up their defining features. We've taken a closer look at each so you can really understand how they work for you.

Is OpenWRT better than pfSense? ›

OpenWRT has the best Wireless support and achieves the highest wireless throughput. No other operating system comes close. You should NOT use pfSense or OPNSense - they don't support 802.11ac and have sub-optimal 802.11n support. See more information about OpenWRT performance here.

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 to setup VPN server on OpenWRT? ›

Web interface instructions
  1. Install needed packages. Install openvpn-openssl and luci-app-openvpn to be able to manage OpenVPN using web interface. ...
  2. a Write the configuration manually to create a config file. ...
  3. b Upload a OpenVPN config file. ...
  4. Enable Network Killswitch (Optional, Recommended)
Feb 6, 2024

Is WireGuard VPN free? ›

WireGuard is originally open source and can be used for free, absolutely. There are many free VPNs that support WireGuard, and it is also included by default in the Linux kernel, so those who are adept at programming can establish these types of encrypted connections simply by typing in the command line.

How to setup WireGuard server in Windows? ›

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.

Which routers support WireGuard VPN? ›

What Are The Best WireGuard-Supporting Wi-Fi Routers?
  • Mesh Routers. $284.99.
  • TP-Link BE19000 Archer BE800 Wi-Fi 7 FlashRouter. $689.99 Regular Price $799.99.
  • Asus ROG Rapture GT6 Mesh FlashRouter. $514.99 Regular Price $599.99.

How to setup WireGuard VPN server on Windows 10? ›

How to Setup WireGuard VPN Server on Windows
  1. Download and install WireGuard VPN.
  2. Launch the VPN for Windows and create a tunel by clicking Add Tunel > Add empty tunnel.
  3. After saving, you can get the tunnel on the left sidebar. ...
  4. Download WireGuard VPN provider for Mac from App Store.
  5. Launch the app and Add Empty Tunnel.
Mar 7, 2024

Top Articles
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 5865

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.