CentOS 7 OpenVPN Setup: How to Install and Configure OpenVPN

Introduction

In today’s world, remote access to a network is essential for businesses and individuals alike. However, accessing a network remotely can be risky if proper security measures are not in place. This is where virtual private networks (VPNs) come into play. A VPN provides a secure connection between the user and the network by encrypting all data transmitted over the internet. In this blog post, we will guide you through the process of setting up OpenVPN on CentOS 7, a versatile and secure VPN solution.

CentOS 7 OpenVPN

OpenVPN is an open-source software application that allows users to connect to a VPN. It uses SSL/TLSprotocols for encryption and authentication, making it one of the most secure VPN solutions available. Additionally, OpenVPN is compatible with various platforms such as WindowsmacOSLinux, iOS, and Android.

The recommended solution for setting up a VPN on CentOS 7 is OpenVPN due to its versatility and security features. With OpenVPN, you can create both site-to-site and point-to-point connections with ease. Furthermore, OpenVPN provides better performance than other VPN solutions such as PPTP or L2TP/IPsec.

In this step-by-step guide, we will cover the installation of OpenVPN on CentOS 7 followed by its configuration as an OpenVPN server. We will then generate SSL/TLS certificates and keys required for establishing secure connections between clients and servers. Finally, we will configure an OpenVPN client on remote devices to connect to our newly created VPN server.

Whether you are an IT professional or a network administrator looking for a secure VPN solution for your organization or an individual seeking privacy while browsing the internet from public Wi-Fi hotspots or untrusted networks – this guide will help you set up OpenVPN on CentOS 7 efficiently.

By following this guide carefully, you can ensure that your remote access to your network remains safe from prying eyes while maintaining high-speed connectivity without any interruptions. So let’s get started!

Installation

OpenVPN is a versatile and secure VPN solution for CentOS 7. In this section, we will guide you through the installation process of OpenVPN on CentOS 7.

centos 7 openvpn download

Prerequisites

Before installing OpenVPN on CentOS 7, you need to make sure that your system meets the following prerequisites:

  • A server running CentOS 7 with root access
  • A static IP address assigned to your server
  • Basic knowledge of Linux command-line interface (CLI)

Once you have ensured that your system meets these prerequisites, you can proceed with installing the required packages.

Installing OpenVPN

The first step in installing OpenVPN on CentOS 7 is to install the EPEL repository. EPEL stands for Extra Packages for Enterprise Linux and provides additional packages that are not available in the default CentOS repositories.

To install the EPEL repository, run the following command:

sudo yum install epel-release

Next, update your system by running the following command:

sudo yum update

Once your system is updated, you can proceed with installing OpenVPN by running the following command:

sudo yum install openvpn [easy-rsa](https://github.com/OpenVPN/easy-rsa)

This will install both OpenVPN and Easy-RSA, which is a tool used for generating SSL/TLS certificates and keys.

After installing OpenVPN and Easy-RSA, you need to copy the sample configuration files to their respective directories. To do so, run the following commands:

sudo cp /usr/share/doc/openvpn-*/sample/sample-config-files/server.conf /etc/openvpn/
sudo cp /usr/share/doc/openvpn-*/sample/sample-config-files/client.conf /etc/openvpn/
sudo mkdir -p /etc/openvpn/easy-rsa/keys

These commands will copy the sample configuration files for both server and client configurations to their respective directories. They will also create a directory where SSL/TLS certificates and keys will be stored.

Now that you have installed OpenVPN and copied the sample configuration files, it’s time to configure OpenVPN on CentOS 7. In the next section, we will guide you through this process.

Configuration

Configuring OpenVPN on CentOS 7 requires a few steps, but it is straightforward. In this section, we will cover how to configure the OpenVPN server, generate SSL/TLS certificates and keys, and configure the OpenVPN client.

Configuring OpenVPN Server

Before configuring the OpenVPN server, make sure you have installed the necessary packages. You can install them by running the following command:

sudo yum install epel-release
sudo yum install openvpn easy-rsa

Once you have installed the packages, follow these steps to configure the OpenVPN server:

  1. Copy the sample configuration file to /etc/openvpn/server.conf:
sudo cp /usr/share/doc/openvpn-*/sample/sample-config-files/server.conf /etc/openvpn/
  1. Edit the configuration file:
sudo nano /etc/openvpn/server.conf
  1. Uncomment the following lines:
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
  1. Add your network information:
server 10.8.0.0 255.255.255.0
dev tun
proto udp
port 1194
ca /etc/openvpn/easy-rsa/pki/ca.crt
cert /etc/openvpn/easy-rsa/pki/issued/server.crt
key /etc/openvpn/easy-rsa/pki/private/server.key # This file should be kept secret
dh none # Use faster cipher (no DH)

5. Save and close the file.

6. Start and enable OpenVPN service:

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


### Generating SSL/TLS Certificates and Keys

SSL/TLS certificates and keys are used for secure communication between clients and servers in an OpenVPN environment.

To generate SSL/TLS certificates and keys, follow these steps:

1. Create a new directory for your certificate authority (CA) files:

mkdir ~/openvpn-ca && cd ~/openvpn-ca


2. Copy easy-rsa scripts to CA directory:

cp -r /usr/share/easy-rsa/3/* .


3. Edit vars file:

nano vars export KEY_COUNTRY=”US” export KEY_PROVINCE=”CA” export KEY_CITY=”SanFrancisco” export KEY_ORG=”OpenVPN” export KEY_EMAIL=”[email protected]” export KEY_OU=”Community”

Save and exit.

4 . Run init-pki script:

./easyrsa init-pki

5 . Build CA:

./easyrsa build-ca

6 . Generate Server Certificates & Key:

./easyrsa gen-req server nopass

7 . Sign Server Certificate:

./easyrsa sign-req server server

8 . Generate Diffie-Hellman Parameters:

./easyrsa gen-dh

9 . Move Certificates to appropriate directories:

mkdir -p ~/client-configs/keys chmod -R 700 ~/client-configs cp pki/ca.crt pki/issued/server.crt pki/private/server.key 
pki/dh.pem ~/client-configs/keys/

10 . Generate Client Certificates & Keys:

To generate client certificates & keys repeat step 6-7 with different name than ‘server’.

11 . Create TLS Auth Key:

openvpn –genkey –secret ta.key

12 . Move TLS Auth Key to appropriate directory:

mv ta.key ~/client-configs/keys/

Configuring OpenVPN Client

After generating SSL/TLS certificates and keys, you need to configure your remote devices to connect to your VPN.

Follow these steps to configure your client device:

1 . Install openVPN client on remote device.

2 . Copy relevant certificate files from CA directory created earlier in Step#1 of Generating SSL/TLS Certificates & Keys section.

3 . Create a new configuration file for each user/device that will connect to VPN.

4 . Edit configuration file as follows:

client dev tun proto udp

remote SERVER_IP_ADDRESS 1194

resolv-retry infinite

nobind

persist-key

persist-tun

ca ca.crt

cert CLIENT_NAME.crt

key CLIENT_NAME.key

ns-cert-type server

tls-auth ta.key 1

cipher AES-256-CBC

comp-lzo

verb 3

5 . Save configuration file.

6 . Start VPN connection using this command :

sudo openvpn –config CONFIGURATION_FILE_PATH/client.ovpn

Video Tutorial on CentOS 7 OpenVPN Setup

Conclusion

After following our step-by-step guide, you should now have a secure OpenVPN server set up on your CentOS 7 machine. With OpenVPN, you can remotely access your network from anywhere in the world with peace of mind knowing that your connection is encrypted and secure.

One of the benefits of using OpenVPN is its versatility. It can be used in a variety of scenarios, such as connecting to a remote office network or accessing personal files from home. Additionally, OpenVPN’s SSL/TLS encryption provides an extra layer of security that ensures your data remains confidential.

Another advantage of using OpenVPN is its ease of use. With our guide, even those with little to no experience in networking can easily set up and configure their own VPN server on CentOS 7. This makes it an accessible option for small businesses or individuals who want to improve their online security without breaking the bank.

FAQs

Here are some frequently asked questions about setting up OpenVPN on CentOS 7:

Q: Is OpenVPN secure?
A: Yes, OpenVPN is considered one of the most secure VPN solutions available. It uses SSL/TLS encryption to protect your network traffic.

Q: Can I use OpenVPN on other operating systems besides CentOS 7?
A: Yes, OpenVPN is compatible with many different operating systems, including Windows, macOS, and Linux.

Q: Do I need to be an IT professional to set up OpenVPN on CentOS 7
A: While some technical knowledge is required to set up OpenVPN on CentOS 7, our step-by-step guide should make the process manageable for most users.

Q: Are there any additional security measures I should take when using OpenVPN?
A: It’s always a good idea to use strong passwords and keep your software up-to-date. Additionally, you may want to consider implementing two-factor authentication for added security.

Overall, setting up OpenVPN on CentOS 7 can be a great way to securely access your network from anywhere. By following our step-by-step guide and taking appropriate security measures, you can enjoy the benefits of remote access without compromising your data.

Share your love
Ramashankar
Ramashankar

A Nomad who loves Experimenting With Linux, Android, and New Technologies.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Shares
Tweet
Share
Share
Pin