Or copy link
OpenVPN is a robust and widely used open-source application that provides a secure way to establish virtual private network (VPN) connections over the internet. VPNs are becoming increasingly essential in today’s digital world, providing an extra layer of security, privacy, and encryption for online activities. Installing OpenVPN on a KVM VPS server is a cost-effective and reliable way to create a secure and private VPN connection that can be accessed from anywhere in the world.
OpenVPN is particularly useful for businesses that require secure remote access to their network resources and individuals who wish to protect their online privacy by hiding their IP addresses and encrypting their internet traffic. While the idea of installing OpenVPN on a KVM VPS server may seem daunting at first, it’s a straightforward process if you follow the right steps.
In this blog post, we’ll take you through a step-by-step guide to installing OpenVPN on your KVM VPS server. We’ll cover everything you need to know, from the necessary requirements to the configuration of the OpenVPN server, the creation of client certificates, and the configuration of the OpenVPN client. By the end of this blog post, you’ll have a secure and reliable OpenVPN connection set up on your KVM VPS server, ready for use. So, let’s dive in and get started!
To begin the OpenVPN installation process on your KVM VPS server, you must have the following prerequisites:
Once you have these prerequisites, follow the steps outlined below to install OpenVPN on your KVM VPS server:
Before installing any new software or applications, it’s essential to update your server to ensure you have the latest security patches and bug fixes. To do this, run the following command:
sudo apt-get update && sudo apt-get upgrade
This command updates the package list and installs any available updates. You may be prompted to enter your sudo password, so make sure you have it on hand. Once the update and upgrade process is complete, you can move on to the next step.
After updating your server, the next step is to install OpenVPN using your distribution’s package manager. For instance, if you’re using Ubuntu, run the command below:
sudo apt-get install openvpn
The installation process should only take a few seconds, and once completed, you can verify the installation by checking the OpenVPN version number using the command:
openvpn –version
This will confirm that OpenVPN is installed and running correctly on your KVM VPS server.
To generate the certificates for OpenVPN, the EasyRSA script can be used. The following steps need to be followed:
sudo apt-get install easy-rsa
make-cadir ~/openvpn-ca
/easyrsa build-ca nopass
/easyrsa gen-req server nopass
/easyrsa sign-req server server
It is important to keep the server key and certificate files in a safe place, as they will be needed for the next steps.
To configure the Certificate Authority (CA), the vars file needs to be edited. This can be done by following these steps:
nano ~/openvpn-ca/vars
After configuring the CA, you need to build it. Follow these steps:
cd ~/openvpn-ca
source vars
./clean-all
./build-ca
Once you have built the CA, you can generate the server certificate and key. Here’s how:
./build-key-server server
Now that you have the server certificate and key, you can configure the OpenVPN server. Follow these steps:
nano /etc/openvpn/server.conf
port 1194
proto udp
dev tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key
dh /etc/openvpn/dh.pem
server 10.8.0.0 255.255.255.0
push “redirect-gateway def1 bypass-dhcp”
push “dhcp-option DNS 8.8.8.8”
To allow clients to access the internet through the OpenVPN server, you need to enable IP forwarding. This can be done by editing the sysctl.conf file:
nano /etc/sysctl.conf
Uncomment the following line by removing the “#” symbol:
#net.ipv4.ip_forward=1
After uncommenting the line, it should look like this:
net.ipv4.ip_forward=1
Save and close the file. Then, reload the sysctl configuration to apply the changes:
sudo sysctl -p
IP forwarding is now enabled on your server, allowing clients to access the internet through the OpenVPN connection.
To allow OpenVPN traffic through the firewall, you need to configure the firewall rules. If you’re using UFW, you can follow these steps:
Allow UDP traffic on port 1194:
sudo ufw allow 1194/udp
Allow SSH traffic:
sudo ufw allow OpenSSH
Enable the firewall:
sudo ufw enable
This will allow UDP traffic on port 1194 and SSH traffic through the firewall, which is necessary for the OpenVPN server to function properly.
Once the configuration is complete, you can start the OpenVPN service by executing the following command:
sudo systemctl start openvpn@server
Additionally, enable it to start automatically upon booting the system by running the command:
sudo systemctl enable openvpn@server
To connect to the OpenVPN server, generate a client certificate and key using the EasyRSA script:
Go to the openvpn-ca directory:
Source the vars file:
Build the client certificate and key:
./build-key client1
To connect to the OpenVPN server, you need to configure the client. First, download and install the OpenVPN client for your operating system. Then, create a new configuration file called “client.ovpn” using a text editor. Copy and paste the following content into the file:
client
remote YOUR_SERVER_IP_ADDRESS 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-CBC
verb 3
<ca>
INSERT_CA_CERTIFICATE_HERE
</ca>
<cert>
INSERT_CLIENT_CERTIFICATE_HERE
</cert>
<key>
INSERT_CLIENT_KEY_HERE
</key>
Replace “YOUR_SERVER_IP_ADDRESS” with your server’s IP address and insert the contents of the CA, client certificate, and client key files.
To establish a connection to the OpenVPN server using the client, run the following command:
sudo openvpn –config client.ovpn
Once the connection is established, you should be able to access your network or the internet securely through the OpenVPN server. Congratulations, you have successfully set up and connected to your OpenVPN server!
Setting up OpenVPN on a KVM VPS server is a simple process, but it requires some technical expertise. By following the steps provided in this blog post, you can quickly establish a secure and dependable OpenVPN connection. If you encounter any problems or have any questions, don’t hesitate to contact your VPS provider for help.
As digital threats and attacks continue to become more ...
In today's digital world, where cyber threats and data ...
The realm of web hosting and server management has long...
Microsoft created Windows Server, a strong operating sy...
MongoDB, the popular NoSQL database, offers a powerful ...
In the world of web hosting, WHM (Web Host Manager) and...
Save my name, email, and website in this browser for the next time I comment.
Δ