How to Set Up WireGuard VPN on a VPS: A Step-by-Step Tutorial

WireGuard is a modern, lightweight VPN protocol that provides a high level of security and performance. Its simplicity, speed, and efficiency make it an excellent choice for setting up a private VPN on a VPS. This guide will walk you through the steps to set up WireGuard on your VPS, ensuring you have a secure and private connection.

Prerequisites

Before starting, ensure you have the following:

  1. A VPS: Choose a reliable VPS provider like Hosteons with a Linux operating system (e.g., Ubuntu or Debian).
  2. Basic Linux Knowledge: Familiarity with command-line operations.
  3. Root Access: Administrative privileges on your VPS.

Step 1: Update Your VPS

Start by updating your VPS to ensure all packages are up-to-date.

sudo apt update && sudo apt upgrade -y

Step 2: Install WireGuard

WireGuard is included in most modern Linux distributions. To install it, use the following commands:

sudo apt install wireguard -y

If you’re using a different distribution, check the WireGuard documentation for specific installation instructions.

Step 3: Generate Keys

WireGuard uses public and private key pairs for encryption. Generate these keys as follows:

wg genkey | tee privatekey | wg pubkey > publickey
  • privatekey: Your private key (keep this secure and never share it).
  • publickey: Your public key (used to configure the client).

Step 4: Configure WireGuard

Create a configuration file for WireGuard on your VPS:

sudo nano /etc/wireguard/wg0.conf

Add the following content to the file:

[Interface]
PrivateKey = YOUR_PRIVATE_KEY
Address = 10.0.0.1/24
ListenPort = 51820
SaveConfig = true

[Peer]
PublicKey = CLIENT_PUBLIC_KEY
AllowedIPs = 10.0.0.2/32

Replace:

  • YOUR_PRIVATE_KEY with the private key generated earlier.
  • CLIENT_PUBLIC_KEY with the public key from your client device.

Step 5: Enable IP Forwarding

Enable IP forwarding to allow traffic to pass through your VPS:

sudo sysctl -w net.ipv4.ip_forward=1

To make this change permanent, edit the sysctl configuration file:

sudo nano /etc/sysctl.conf

Uncomment or add the following line:

net.ipv4.ip_forward=1

Step 6: Start and Enable WireGuard

Start the WireGuard service and enable it to run at boot:

sudo systemctl start [email protected]
sudo systemctl enable [email protected]

Step 7: Configure the Client

On your client device (e.g., laptop or smartphone), install WireGuard and create a configuration file. For example:

[Interface]
PrivateKey = CLIENT_PRIVATE_KEY
Address = 10.0.0.2/24

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = YOUR_VPS_IP:51820
AllowedIPs = 0.0.0.0/0

Replace:

  • CLIENT_PRIVATE_KEY with the client’s private key.
  • SERVER_PUBLIC_KEY with your VPS’s public key.
  • YOUR_VPS_IP with the public IP address of your VPS.

Step 8: Test the Connection

Activate the VPN on your client and test the connection:

  1. Start the VPN:
   sudo wg-quick up wg0
  1. Verify the connection on the server:
   sudo wg

You should see details of the connected peer.

Optional: Add a Firewall Rule

To enhance security, configure your firewall to only allow WireGuard traffic:

sudo ufw allow 51820/udp
sudo ufw enable

Conclusion

Setting up WireGuard on a VPS is a straightforward process that provides a secure, high-performance VPN solution. With your own private VPN, you gain control over your data and privacy without relying on third-party commercial VPN services. Hosteons offers affordable and reliable VPS solutions to get you started with your WireGuard VPN today!

Why You Should Use a VPN While Traveling or Using Public Networks

In today’s interconnected world, the convenience of accessing the internet from virtually anywhere is a double-edged sword. Public networks—whether in airports, cafes, hotels, or malls—offer easy internet access but come with significant security risks. One of the most effective ways to protect your data and privacy in such situations is by using a Virtual Private Network (VPN). This article explores why you should use a VPN while traveling or on public networks and why setting up your own private VPN on a small VPS is a better choice than relying on commercial VPN services.

The Risks of Public Networks

When you connect to public Wi-Fi networks, you expose your data to several threats, including:

  1. Man-in-the-Middle (MITM) Attacks: Cybercriminals can intercept data transmitted between your device and the network, gaining access to sensitive information such as passwords, emails, and financial details.
  2. Data Snooping: Without encryption, your browsing activities, login credentials, and other data are visible to anyone with the right tools on the same network.
  3. Fake Wi-Fi Hotspots: Hackers can set up rogue hotspots designed to steal data from unsuspecting users who connect to them.
  4. Malware Distribution: Public networks can be used to inject malware into devices, compromising your security further.

Why Use a VPN?

A VPN creates a secure, encrypted tunnel between your device and the internet, protecting your data from prying eyes. Here’s how a VPN can safeguard your online activities:

  1. Encryption: VPNs encrypt your internet traffic, ensuring that even if it’s intercepted, the data is unreadable.
  2. Anonymity: By masking your IP address, VPNs make it harder for third parties to track your online activities.
  3. Access to Restricted Content: VPNs can bypass geo-restrictions, allowing you to access websites or services that may be unavailable in certain regions.
  4. Protection on Public Networks: VPNs shield your data from the inherent vulnerabilities of public Wi-Fi.

The Problem with Commercial VPNs

While commercial VPNs offer convenience, they come with their own set of issues:

  1. Trust Issues: You’re placing your trust in a third-party company to handle your data. Many commercial VPN providers have been caught logging user data despite claims of “no-logs” policies.
  2. Performance: Shared infrastructure can result in slower speeds and inconsistent performance, especially during peak usage hours.
  3. Cost: Subscription fees for commercial VPNs can add up over time.
  4. Security Concerns: Some providers may use weak encryption protocols or lack transparency about their practices.

Why Set Up Your Own Private VPN on a VPS

A better alternative to using commercial VPNs is to set up your own private VPN on a small VPS. Here’s why this approach stands out:

  1. Complete Control: By setting up your own VPN, you control how your data is handled and stored.
  2. Enhanced Privacy: No third-party provider can log your data, as you manage the entire setup.
  3. Cost-Effective: Many VPS providers, like Hosteons, offer affordable plans that make it economical to run your private VPN.
  4. Customizability: You can configure your VPN to meet your specific needs, including advanced encryption settings and protocols.
  5. Performance: Since the VPN is exclusively yours, you avoid the performance issues common with shared commercial VPNs.

Setting Up a Private VPN on a VPS

Setting up a private VPN on a VPS might sound technical, but it’s more straightforward than you think. Popular software like OpenVPN or WireGuard can be installed and configured on your VPS with the help of readily available tutorials. Once set up, your private VPN provides the same level of security as commercial options—without the downsides.

Conclusion

Using a VPN while traveling or connecting to public networks is essential for safeguarding your data and privacy. However, instead of relying on commercial VPN services, setting up your own private VPN on a small VPS offers better privacy, control, and performance at a lower cost. With providers like Hosteons offering affordable VPS solutions, there’s never been a better time to take charge of your online security.

Setup OpenVPN on a KVM Based VPS like hosteons

install openvpn on lvm based vps

Just run following command as root on a CentOS / Ubuntu / Debian based VPS or Dedicated Server and follow the prompts to install OpenVPN:

wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh

Once it ends, you can run it again to add more users, remove some of them or even completely uninstall OpenVPN.

It works even on the cheapest VPS Package provided by hosteons.com

 

Quick setup of L2TP or IPsec VPN on CentOS, Ubuntu or Debian

One line setup:

First get a fresh install of Ubuntu LTS, Debian or CentOS on your hosteons VPS or Dedicated Server (VPS should be KVM based not OpenVZ, if you are using hosteons.com VPS then need not worry as it’s KVM based VPS)

Use following command to set up an IPsec VPN server on Ubuntu or Debian:

wget https://git.io/vpnsetup -O vpnsetup.sh && sudo sh vpnsetup.sh

If you are on CentOS then use following command:

wget https://git.io/vpnsetup-centos -O vpnsetup.sh && sh vpnsetup.sh

Your VPN login details will be randomly generated, and displayed on screen when finished.

Also it’s best to run these commands in a screen session to avoid any interruptions due to any reasons.

Custom Setup of VPN:

Ubuntu and Debian:

Make sure your VPS/Dedicated server is upto date, you can do it with following commands:

apt-get update && apt-get dist-upgrade

and reboot.

Now Edit the script and provide your own VPN credentials:

wget https://git.io/vpnsetup -O vpnsetup.sh
nano -w vpnsetup.sh
[Replace with your own values: YOUR_IPSEC_PSK, YOUR_USERNAME and YOUR_PASSWORD]

sudo sh vpnsetup.sh

CentOS:

Make sure your VPS/Dedicated server is upto date, you can do it with following commands:

yum -y update

(if you are using hosteons.com vps then need not worry, our templates update everything when the VPS is setup)

Now Edit the script and provide your own VPN credentials:

wget https://git.io/vpnsetup-centos -O vpnsetup.sh
nano -w vpnsetup.sh
[Replace with your own values: YOUR_IPSEC_PSK, YOUR_USERNAME and YOUR_PASSWORD]

sh vpnsetup.sh

 

Your VPN server is now ready, just connect using the Shared Key, username and password you provided during setup or displayed on script, depending upon how you setup your VPN.