📧 info@skyhost.co.ke

☏ +254 207 906 629

login-rounded-rightLogin

☎+254 207 906 629

Login

How to Install OpenVPN on a VPS Server

by | VPS Servers

In the digital age, ensuring secure communication and data transfer is paramount for businesses and individuals alike. One robust solution to achieve this is by implementing a Virtual Private Network (VPN). Among the various VPN options available, OpenVPN stands out for its reliability, security, and versatility. In this comprehensive guide, we’ll walk you through the process of installing OpenVPN on a VPS server, empowering you with the tools to safeguard your online activities effectively.

Understanding OpenVPN and VPS Servers

What is OpenVPN?

OpenVPN is an open-source VPN protocol renowned for its robust encryption capabilities and flexibility. It allows users to create secure point-to-point or site-to-site connections in routed or bridged configurations.

What is a VPS Server?

A Virtual Private Server (VPS) is a virtual machine sold as a service by an Internet hosting service. It runs its copy of an operating system (OS), and customers have superuser-level access to that operating system instance, so they can install almost any software that runs on that OS.

Prerequisites for Installation

Before embarking on the installation process, ensure you have the following prerequisites in place:

  • VPS Server: Access to a virtual private server with root privileges.
  • Operating System: A Linux-based operating system such as Ubuntu or CentOS is recommended.
  • SSH Client: Ability to connect to your VPS server via SSH.
  • Basic Command Line Knowledge: Familiarity with basic command line operations.

Step-by-Step Installation Guide

Follow these detailed steps to install OpenVPN on your VPS server:

Step 1: Connect to Your VPS Server via SSH

Open your preferred SSH client and connect to your VPS server using the provided credentials.

bashCopy code

ssh username@your_server_ip

Step 2: Update System Packages

Ensure your system packages are up to date by running the following commands:

bashCopy code

sudo apt update sudo apt upgrade

Step 3: Install OpenVPN

Install OpenVPN by executing the following command:

bashCopy code

sudo apt install openvpn

Step 4: Configure OpenVPN

Navigate to the OpenVPN directory and copy the sample configuration files:

bashCopy code

cd /etc/openvpn sudo cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0 /etc/openvpn/easy-rsa

Step 5: Generate Keys and Certificates

Edit the vars file to configure the key generation parameters:

bashCopy code

nano /etc/openvpn/easy-rsa/vars

Once configured, execute the following commands to generate keys and certificates:

bashCopy code

source /etc/openvpn/easy-rsa/vars sudo /etc/openvpn/easy-rsa/clean-all sudo /etc/openvpn/easy-rsa/build-ca sudo /etc/openvpn/easy-rsa/build-key-server server sudo /etc/openvpn/easy-rsa/build-dh

Step 6: Configure OpenVPN Server

Create a server configuration file:

bashCopy code

nano /etc/openvpn/server.conf

Paste the following configuration into the file:

bashCopy code

port 1194 proto udp dev tun ca /etc/openvpn/easy-rsa/keys/ca.crt cert /etc/openvpn/easy-rsa/keys/server.crt key /etc/openvpn/easy-rsa/keys/server.key dh /etc/openvpn/easy-rsa/keys/dh2048.pem server 10.8.0.0 255.255.255.0 push "redirect-gateway def1 bypass-dhcp" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" keepalive 10 120 comp-lzo user nobody group nogroup persist-key persist-tun status /var/log/openvpn-status.log verb 3

Save and close the file.

Step 7: Enable IP Forwarding

Uncomment the IP forwarding line in the sysctl configuration file:

bashCopy code

nano /etc/sysctl.conf

Find and uncomment the following line:

bashCopy code

net.ipv4.ip_forward=1

Save and close the file, then apply the changes:

bashCopy code

sudo sysctl -p

Step 8: Configure Firewall

Allow traffic to pass through the VPN by configuring firewall rules:

bashCopy code

sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE sudo iptables-save > /etc/iptables.rules

Step 9: Start OpenVPN Service

Start the OpenVPN service and enable it to start on boot:

bashCopy code

sudo systemctl start openvpn@server sudo systemctl enable openvpn@server

Conclusion

Congratulations! You’ve successfully installed OpenVPN on your VPS server, enhancing your online security and privacy. By following this comprehensive guide, you’ve equipped yourself with the necessary knowledge to establish a secure VPN connection, safeguarding your sensitive data from prying eyes

You Might Also Like

Join Our Newsletter for Updates & Offers

× Chat with us on What's App?