Installing OpenVPN On CentOS
Installing OpenVPN On CentOS
CentOS 6
03 Apr 2012/200 Comments/in VPN's /by Admin
In this guide we will show you how to setup OpenVPN on centos the guide will give you a
fully working OpenVPN installation, NOT TESTED ON OTHER DISTROS..
First step is to check if tun/tap is active:
cat /dev/net/tun
wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm
32bit Package:
CentOS 5:
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
CentOS 6:
Wget
http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-
1.el6.rf.i686.rpm
64bit Package:
CentOS 5:
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
CentOS 6:
wget
http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-
1.el6.rf.x86_64.rpm
Install OpenVPN:
cp -R /usr/share/doc/openvpn-2.2.2/easy-rsa/ /etc/openvpn/
**PLEASE NOTE** if the above command brings up an error such as below, then please
follow the following steps to download and copy over easy-rsa as its not included in the new
build OpenVPN 2.3.1:
cannot stat `/usr/share/doc/openvpn-2.2.2/easy-rsa/': No such file or
directory
Download easy-rsa from below:
wget https://github.com/downloads/OpenVPN/easy-rsa/easy-rsa-2.2.0_master.tar.gz
cp -R easy-rsa-2.2.0_master/easy-rsa/ /etc/openvpn/
Please note on CentOS 6 we need to make a small change before you run the commands
below, open up /etc/openvpn/easy-rsa/2.0/vars and edit the below line:
Change:
To:
export KEY_CONFIG=/etc/openvpn/easy-rsa/2.0/openssl-1.0.0.cnf
And save..
Now lets create the certificate:
cd /etc/openvpn/easy-rsa/2.0
chmod 755 *
source ./vars
./vars
./clean-all
Build CA:
./build-ca
./build-key-server server
Almost the same with ./build.ca but check the changes and additional
./build-dh
touch /etc/openvpn/server.conf
dev tun
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
reneg-sec 0
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
client-cert-not-required
username-as-common-name
keepalive 5 30
comp-lzo
persist-key
persist-tun
status 1194.log
verb 3
Save it.
Before we start OpenVPN, lets disable SELinux if enabled, this can cause issues with
OpenVPN, especially when using OpenVPN with multiple configs:
This is a temporary solution and will re-enable once you reboot your system, to disable on a
permanent basis you need to edit the following /etc/selinux/config and edit this line:
SELINUX=enforcing
To:
SELINUX=disabled
*Please note if you receive FAIL when OpenVPN trys to start and you have the following
error in your /var/log/messages:
PLUGIN_INIT:
could
not
load
plugin
shared
object
/usr/share/openvpn/plugin/lib/openvpn-auth-pam.so:
/usr/share/openvpn/plugin/lib/openvpn-auth-pam.so: cannot open shared object file: No
such file or directory
Then this is because the latest OpenVPN package doesnt include this file (which is
reported to be fixed soon) but you can download the pam auth file from here for now:
64Bit:
wget http://safesrv.net/public/openvpn-auth-pam.zip
32Bit:
wget http://safesrv.net/public/dl/openvpn-auth-pam.zip
unzip openvpn-auth-pam.zip
mv openvpn-auth-pam.so /etc/openvpn/openvpn-auth-pam.so
killall -9 openvpn
Now we need to enable IP forwarding. So open the file /etc/sysctl.conf and set
net.ipv4.ip_forward to 1.
net.ipv4.ip_forward = 1
To make the changes to sysctl.conf take effect, use the following command.
sysctl -p
Route Iptables:
The rule below will work fine on xen and KVM based VPSs but for
OpenVZ use the OpenVZ iptable rule instead:
And
If the above rules cause you any problems or dont seem to work (Especially on cPanel
servers) then remove the rules above and use below:
Please note if you are using our FreeRADIUS module for WHMCS then you dont have to do
the below step for adding users just follow the link above to setup OpenVPN to auth off
FreeRADIUS otherwise you can create a user as follows:
passwd username
userdel username
client
dev tun
proto udp
resolv-retry infinite
nobind
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
persist-key
persist-tun
ca ca.crt
auth-user-pass
comp-lzo
reneg-sec 0
verb 3
chkconfig openvpn on