BLOG POSTS
Setting up WireGuard VPN on Linux Server

Setting up WireGuard VPN on Linux Server

Setting up WireGuard involves configuring a server and client. In this guide, we’ll walk through setting up a basic WireGuard server and client. This example uses a Linux-based system, but the process is somewhat similar across other platforms.

1. Install WireGuard:

On a Debian/Ubuntu Server:

bash
sudo apt update
sudo apt install wireguard

On a CentOS/RHEL Server:

First, enable the EPEL repository:

bash
sudo yum install epel-release -y

Then, install WireGuard:

bash
sudo yum install wireguard-dkms wireguard-tools -y

2. Server Configuration:

Generate Server Keys:

bash
cd /etc/wireguard/
umask 077
wg genkey | tee server_private_key | wg pubkey > server_public_key

Create and Edit Server Configuration:

bash
nano /etc/wireguard/wg0.conf

Enter the following, adjusting as necessary:

css
[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = [YourServerPrivateKeyFromAbove]
[Peer]
PublicKey = [YourClientPublicKey]
AllowedIPs = 10.0.0.2/32

3. Client Configuration:

Generate Client Keys:

This step can be performed on the server for simplicity, or directly on the client.

bash
wg genkey | tee client_private_key | wg pubkey > client_public_key

Create and Edit Client Configuration:

If you’re on the client:

bash
nano /etc/wireguard/wg0.conf

Enter the following, adjusting as necessary:

css
[Interface]
Address = 10.0.0.2/24
PrivateKey = [YourClientPrivateKeyFromAbove]
[Peer]
PublicKey = [YourServerPublicKey]
Endpoint = [YourServerIPAddress]:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

4. Start and Enable WireGuard:

On the Server:

bash
sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0

On the Client:

bash
sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0

5. Test the Connection:

From the client, you should be able to ping the server using its WireGuard IP:

bash
ping 10.0.0.1

Final Notes:

  1. Always replace placeholders like [YourServerPrivateKeyFromAbove] with the actual values.
  2. The server’s AllowedIPs for the client is restrictive to only allow the client’s WireGuard IP. If you add more clients, add more [Peer] sections to the server config and adjust IPs accordingly.
  3. The client’s AllowedIPs is set to 0.0.0.0/0, which means all traffic will be routed through the VPN. Adjust this if you need split tunneling.
  4. The PersistentKeepalive setting helps with NAT/firewall traversal.
  5. Ensure your server’s firewall allows incoming connections on the chosen WireGuard port (51820 in this case). Adjust firewall settings as necessary.
  6. This is a basic setup; there are many other configurations possible based on your needs. Always remember to secure and monitor your server.


This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked