In this tutorial, we will show you how to install and configure an OpenVPN server on CentOS 7. OpenVPN is one of the most popular VPN software solutions that implements virtual private network techniques for creating secure point-to-point or site-to-site connections. This guide should work on other Linux VPS systems as well but was tested and written for an CentOS 7. Installing openVPN on CentOS7 is an easy task, just carefully follow the steps bellow and you should have it done in less than 10 minutes.
Table of Contents
1. Login to your VPS via SSH
2. Update the system
3. Install OpenVPN on CentOS 7
OpenVPN is not available in the official CentOS 7 repositories so first we need to add the EPEL repository and then install the package:
To enable the Epel repository run the following command:
Once the repository is enabled install the openvpn and openssl packages:
4. Generate local certificate authority
First, generate the Diffie-Hellman parameters (DH file) which is used to secure the key exchange between the server and the client. This command can take a while to run depending on the server.
Generate ca.crt
(certificate authority) file:
5. Configure OpenVPN server
Create server certificate and key with the following commands will generate a server certificate and key:
6. Create OpenVPN server configuration file
You can either copy and edit the default OpenVPN configuration or create a new one from scratch.
save the file and enable and start the OpenVPN service with:
Add the following iptables
rule so that traffic can leave the VPN. Change the eth0
with the public network interface of your server.
Note: If you are running an openvz based VPS
instead of the rule above add: iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source YOUR_SERVER_IP
>
Finally, we also need to allow IP forwarding:
7. Create client certificate and key
The following commands will generate a client certificate and key:
Next, copy the following files to your client machine
8. Start OpenVPN on CentOS 7
start your OpenVPN client with the following configuration.
Do not forget to change YOUR_SERVER_IP
with your OpenVPN server IP address.
That’s it. You have successfully installed a configured an OpenVPN server on your CentOS 7 VPS.
Of course, you don’t have to install OpenVPN on CentOS 7, if you use one of our CentOS 7 Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install OpenVPN on CentOS 7, for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, on how to install OpenVPN on CentOS 7, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.