How To Install OpenVPN on CentOS 7

r00t December 6, 2017

Install OpenVPN on CentOS 7

In this tutorial we will show you how to install OpenVPN on your CentOS 7 server. For those of you who didn’t know, OpenVPN is an open source application which is widely used to create secure virtual private networks over the unsecured public Internet. OpenVPN is an SSL VPN solution which drains your system connection securely through the Internet. OpenVPN functions in the client server structure. All the devices connected to a virtual private network act as if they’re linked to your local area network. The packets sent through the VPN tunnel are encrypted with 256 bit AES encryption making data theft impossible.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation OpenVPN open source virtual private network on a CentOS 7 server.

Install OpenVPN on CentOS 7

Step 1. First let’s start by ensuring your system is up-to-date.

Step 2. Installing OpenVPN on CentOS 7.

We will now install OpenVPN and Easy-RSA package. The Easy-RSA package is provided so we can have an easier way of generating certificates:

Step 3. Configuring Easy-rsa.

Now that you have installed OpenVPN successfully, you have to create keys and certificates, follow this section step by step:

Next, we will copy the certificate generation scripts from their default location to our OpenVPN folder:

We will go to the easy-rsa directory and source the variables:

Then run “./clean-all” right away to ensure that we have a clean certificate setup:

Now you have to generate a “Certificate Authority (ca)” file. you will be asked for country name etc. that you edited in the “vars” file. you can hit “Enter” to accept your default values.

Now move to the following directory:

Step 4. Generating a server key and certificate.

Run the command below in the current directory:

We will also need to create a Diffie-Hellman file. Creation of this file will depends on the length of the key. For this default we will use 2048 bit key but you can always change it by editing the vars file in the easy-rsa folder:

Step 5. OpenVPN server configuration.

We will now configure the OpenVPN server. First, create a configuration file named server.conf:

Paste the configurations below (you may change the values of port etc.):

Save the file and enable and start the OpenVPN service:

Step 6. Configure Iptables for OpenVPN.

We will need to enter some iptable rules to enable internet on the client machine:

Next, edit systctl.conf to enable packet forwarding:

Add the line:

Step 7. Create client certificate and key.

The following commands will generate a client certificate and key:

Add following line:

Set file permissions and make executable:

Congratulation’s! You have successfully installed OpenVPN. Thanks for using this tutorial for installing OpenVPN open source virtual private network on your CentOS 7 system. For additional help or useful information, we recommend you to check the official OpenVPN web site.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get a best deal!
Share on Google+0Share on Facebook0Tweet about this on TwitterShare on Tumblr0Share on StumbleUpon0Share on Reddit0Pin on Pinterest0
The Tags:

Leave a Comment