How to Install OpenVPN on CentOS VPS


OpenVPN is an open source virtual private network (VPN) software. Follow the steps below to configure OpenVPN on CentOS:

1. Install dependencies:

# yum install gcc make rpm-build autoconf.noarch zlib-devel pam-devel openssl-devel


2. Get OpenVPN:

# wget

# wget


3. Prepare to install:

# rpmbuild --rebuild lzo-1.08-4.rf.src.rpm

# rpm -Uvh /usr/src/redhat/RPMS/x86_64/lzo-*.rpm

# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm


4. Install OpenVPN:

# yum install openvpn


5. Copy the OpenVPN directory:

# cp -r /usr/share/doc/openvpn-2.2.0/easy-rsa/ /etc/openvpn/


6. Build SSL keys. When prompted for key information, you can simply press enter to bypass:

#cd /etc/openvpn/easy-rsa/2.0

#chmod 755 *

#source ./vars




#./build-key-server server



7. Create the OpenVPN config:

# cd /etc/openvpn

# vi server.conf


Copy the following sample config into the document, edit the IP address and port to your main IP address and desired port, then press ESC, then :wq and enter to save and exit the document.


local #- change it with your server ip address

port 1234 #- change the port you want

proto udp #- protocol can be tcp or udp

dev tun

tun-mtu 1500

tun-mtu-extra 32

mssfix 1450

ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt

cert /etc/openvpn/easy-rsa/2.0/keys/server.crt

key /etc/openvpn/easy-rsa/2.0/keys/server.key

dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem

plugin /usr/share/openvpn/plugin/lib/ /etc/pam.d/login




push "redirect-gateway def1"

push "dhcp-option DNS"

push "dhcp-option DNS"

keepalive 5 30




status server-tcp.log

verb 3


8. Start OpenVPN:

# openvpn /etc/openvpn/server.conf

Check that it returns "Initialization Sequence Completed." If so, press ctrl-c to quit.


9. Setup NAT rules:

# echo 1 > /proc/sys/net/ipv4/ip_forward

# iptables -t nat -A POSTROUTING -s -j SNAT --to

(Modify "" to your server's IP)


Create a user to login to the VPN with:

#useradd username -s /bin/false

#passwd username


10. Create an OpenVPN config file on your local machine with name vpn1.ovpn, copy the sample below with your IP and port, and place it in your OpenVPN configurations folder:


dev tun

proto udp

remote 4567 #- your OPENVPN server ip and port

resolv-retry infinite


tun-mtu 1500

tun-mtu-extra 32

mssfix 1450



ca ca.crt



verb 3


11. Download ca.crt from /etc/openvpn/easy-rsa/2.0/keys to the same OpenVPN configs folder.

12. Start the VPN on the VPS:

# openvpn /etc/openvpn/server.conf


Log in to the VPN from your local machine (using OpenVPN or another desktop client) with the username/password you created.


Was this answer helpful?

 Print this Article

Also Read

Virtualmin Getting Started Guide

After deploying one of the Bitronic Technologies Virtualmin templates we recommend the following...

How to Install RapidLeech v42 on a Debian or Ubuntu VPS

This guide will walk you through the installation of RapidLeech v42 r358 on a VPS running Debian...

How to Install VNC with GNOME Desktop on a Debian VPS

NOTE: Bitronic Technologies come pre-configured for VNC access, just click Product...

Installing htop on a CentOS VPS

If you want to install ‘htop’ (a very good Linux process viewer) onto a server...

How to Setup Ruby on Rails on a CentOS or Fedora VPS

This tutorial will walk you through the setup of a basic Ruby on Rails environment, including:...