Sie sind auf Seite 1von 7

5/6/2019 How To Install OpenVPN on CentOS

(https://www.quickservers.com/en/index.php)

BLOG
VPS HOSTING (HTTPS://WWW.QUICKSERVERS.COM/EN/INDEX.PHP)

TUTORIALS: How To..


DEDICATED SERVERS (HTTPS://WWW.QUICKSERVERS.COM/EN/BAREMETAL-SERVERS.PHP)

DOMAINS (HTTPS://WWW.QUICKSERVERS.COM/EN/DOMAIN-NAMES.PHP)

SSL (HTTPS://WWW.QUICKSERVERS.COM/EN/SSL-CERTIFICATES.PHP)

ABOUT (HTTPS://WWW.QUICKSERVERS.COM/EN/CONTACT.PHP)

(HTTPS://WWW.QUICKSERVERS.COM/NL/HOW-TO-INSTALL-OPENVPN-ON-
CENTOS.PHP)

HOW TO INSTALL OPENVPN ON CENTOS


LINUX (6 AND 7)
[Last updated: 24 May 2019]

In this tutorial we explain how to install OpenVPN on your QuickServers virtual or dedicated server.
OpenVPN is an open source VPN application that lets you create and join a private network securely
over the internet.

Use promo code QRP10031 (https://www.quickservers.com/order.php?plan=cloud1&lang=en) and have


your OpenVPN virtual server for only EUR 1,50.

Step 1: Enable EPEL repository

On CentOS 6:

https://www.quickservers.com/en/how-to-install-openvpn-on-centos.php 1/7
5/6/2019 How To Install OpenVPN on CentOS
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

On CentOS 7:

yum install epel-release

Step 2: Install and con gure OpenVPN

yum install -y openvpn easy-rsa

Copy the sample.conf to /etc/openvpn as starting point for our own con g le.

cp /usr/share/doc/openvpn-*/sample/sample-con g- les/server.conf /etc/openvpn

Now, let's change the con guration le.

vi /etc/openvpn/server.conf

Uncomment the following lines and make them look like as below:

push "redirect-gateway def1 bypass-dhcp"


push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"

Step 3: Generate OpenVPN key and certi cates

Create a folder to store the key and certi cates in, copy the key generation script and openssl.cnf with
this command:

mkdir -p /etc/openvpn/easy-rsa/keys && cp -rf /usr/share/easy-rsa/2.0/* /etc/openvpn/easy-rsa &&


cp /etc/openvpn/easy-rsa/openssl-1.0.0.cnf /etc/openvpn/easy-rsa/openssl.cnf

Now, we're going to open en change /etc/openvpn/easy-rsa/vars:

vi /etc/openvpn/easy-rsa/vars

Find (and uncomment when commented) these lines and change them with your own information.

export KEY_COUNTRY="NL"
export KEY_PROVINCE="FL"
export KEY_CITY="Amsterdam" 
export KEY_ORG="QuickServers"
https://www.quickservers.com/en/how-to-install-openvpn-on-centos.php 2/7
5/6/2019 How To Install OpenVPN on CentOS
export KEY_EMAIL="admin@quickservers.com"
export KEY_OU="IT"

Change KEY_NAME to "server". Do not change it to something else since we use 'server' also in other
commands in this tutorial.

export KEY_NAME="server"

Change KEY_CN to a subdomain resolving to the IP address of your server.

export KEY_CN=openvpn.quickservers.com

Now we're going to generate all keys and certi cates. As we specifed all variables already in
/etc/openvpn/easy-rsa/vars, just press ENTER on each question.

cd /etc/openvpn/easy-rsa && source ./vars && ./clean-all

./build-ca

./build-key-server server

./build-dh

cd /etc/openvpn/easy-rsa/keys && cp dh2048.pem ca.crt server.crt server.key /etc/openvpn

cd /etc/openvpn/easy-rsa && ./build-key client

Step 4 for CentOS 6: Add iptables rule

Add this rule to allow VPN traf c go through. Change 'venet0' to your main network adapter name. In
most cases this is venet0 or eth0.

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE

Save the new rewall rule

service iptables save

Then we must enable IP forwarding in sysctl. Open sysctl.conf: 


https://www.quickservers.com/en/how-to-install-openvpn-on-centos.php 3/7
5/6/2019 How To Install OpenVPN on CentOS
vi /etc/sysctl.conf

Locate the line 'net.ipv4.ip_forward = 0' and change it to:

net.ipv4.ip_forward = 1

Step 4 for CentOS 7: Install iptables-services and add iptables rule

Execute these commands:

yum install -y iptables-services


systemctl mask rewalld
systemctl enable iptables
systemctl stop rewalld
systemctl start iptables
iptables -- ush

Add this rule to allow VPN traf c go through. Change 'venet0' to your main network adapter name. In
most cases this is venet0 or eth0.

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE

Save the new rewall rule

iptables-save > /etc/syscon g/iptables

Then we must enable IP forwarding in sysctl. Open sysctl.conf:

vi /etc/sysctl.conf

Locate the line with net.ipv4.ip_forward = 0 and change it to:

net.ipv4.ip_forward = 1

Step 5: Start OpenVPN

Last command; start OpenVPN!

service network restart

service openvpn start 


https://www.quickservers.com/en/how-to-install-openvpn-on-centos.php 4/7
Your OpenVPN server is now installed and running
5/6/2019 How To on your
Install CentOS
OpenVPN server.
on CentOS

And now?

You need to install the OpenVPN client on your PC or Mac.

Windows: http://openvpn.net/index.php/open-source/downloads.html

Mac: https://code.google.com/p/tunnelblick/

And you need a myvpn.ovpn le, which has this content:

client
dev tun
proto udp
remote vpn.quickservers.com 1194
resolv-retry in nite
nobind
persist-key
persist-tun
comp-lzo
verb 3
< ca>
-----BEGIN CERTIFICATE-----
MIIEtzCCA5+gAwIBAgIJAKdTKTrDcEmpMA0GCSqGSIb3DQEBCwUAMIGYMQswCQYD
VQQGEwJOTDELMAkGA1UECBMCRkwxDzANBgNVBAcTBkFsbWVyZTERMA8GA1UEChMI
-----END CERTIFICATE-----
< /ca>
< cert>
-----BEGIN CERTIFICATE-----
MIIE9TCCA92gAwIBAgIBAjANBgkqhkiG9w0BAQsFADCBmDELMAkGA1UEBhMCTkwx
CzAJBgNVBAgTAkZMMQ8wDQYDVQQHEwZBbG1lcmUxETAPBgNVBAoTCEVub3JtYWls
-----END CERTIFICATE-----
< /cert>
< key>
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7N5Bd12XYuDBz
lWmyaGsuRbf3k0gQuRwzO88pqSd rhEb036gfPIIv5SQrEPZ+2fLqbqQqg+weQS
-----END PRIVATE KEY-----
< /key>

Double click on this le to start OpenVPN.



https://www.quickservers.com/en/how-to-install-openvpn-on-centos.php 5/7
5/6/2019 How To Install OpenVPN on CentOS
SHARE

OTHER BLOG POSTS

HOW TO INSTALL OPENVPN (HOW-TO-INSTALL-OPENVPN-ON-CENTOS.PHP)

HOW TO INSTALL VSFTPD (HOW-TO-INSTALL-VSFTPD-ON-CENTOS.PHP)

HOW TO INSTALL REDIS (HOW-TO-INSTALL-REDIS-ON-CENTOS.PHP)

HOW TO INSTALL BOXROOM (HOW-TO-INSTALL-BOXROOM-ON-CENTOS.PHP)

HOW TO INSTALL CPANEL (HOW-TO-INSTALL-CPANEL-ON-LINUX.PHP)

HOW TO INSTALL SOLR (HOW-TO-INSTALL-SOLR-ON-CENTOS.PHP)

HOW TO INSTALL OWNCLOUD (HOW-TO-INSTALL-OWNCLOUD.PHP)

HOW TO INSTALL DIRECTADMIN (HOW-TO-INSTALL-DIRECTADMIN.PHP)

HOW TO INSTALL PLESK (HOW-TO-INSTALL-PLESK.PHP)

HOW TO INSTALL MEMCACHED (HOW-TO-INSTALL-MEMCACHED.PHP)

(https://www.quickservers.com/en/index.php)

Hosting

Cloud Servers (https://www.quickservers.com/en/index.php)

Dedicated servers (https://www.quickservers.com/en/baremetal-servers.php)

Big Storage Servers (https://www.quickservers.com/en/dedicated-server-owncloud.php)


https://www.quickservers.com/en/how-to-install-openvpn-on-centos.php 6/7
5/6/2019 How To Install OpenVPN on CentOS

Services

Domains (https://www.quickservers.com/en/domain-names.php)

SSL certi cates (https://www.quickservers.com/en/ssl-certi cates.php)

Managed hosting (https://www.quickservers.com/en/managed-server-hosting.php)

QuickServers

Customer Area (https://my.quickservers.com/)

Sign Up (https://www.quickservers.com/en/signup.php)

Referral Program (https://www.quickservers.com/en/referral-program.php)

Language

English (http://www.quickservers.com/en/index.php)

Nederlands (http://www.quickservers.com/nl/index.php)


https://www.quickservers.com/en/how-to-install-openvpn-on-centos.php 7/7

Das könnte Ihnen auch gefallen