Home > Documentation > VPN - Virtual Private Network > How to setup Openvpn on Centos

How to setup Openvpn on Centos

Posted by peter on December 22, 2011

1. Download the required package files.

#wget http://openvpn.net/release/openvpn-2.0.9.tar.gz
#wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm

2. Install and build your download files

make sure the following are installed

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

If you have the above dependencies installed, you can start your installation as follows:

#rpmbuild –r1. Download the required package files.
#wget http://openvpn.net/release/openvpn-2.0.9.tar.gz
#wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm

2. Install and build your download files

make sure the following are installed

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

If you have the above dependencies installed, you can start your installation as follows:

#rpmbuild --rebuild lzo-1.08-4.rf.src.rpm
#rpm -Uvh /usr/src/redhat/RPMS/x86_64/lzo-*.rpm
#rpmbuild -tb openvpn-2.0.9.tar.gz
#rpm -Uvh /usr/src/redhat/RPMS/x86_64/openvpn-2.0.9-1.x86_64.rpm
NOTE – for i386 change the x8_64 directory to i386

3. Copy configuration files

#cp -r /usr/share/doc/openvpn-2.0.9/easy-rsa/ /etc/openvpn/
#cp /usr/share/doc/openvpn-2.0.9/sample-config-files/server.conf /etc/openvpn/

4. CA configuration

#cd /etc/openvpn/easy-rsa/
#vi vars

then scroll down to the bottom, edit as you like.

export KEY_COUNTRY=SA
export KEY_PROVINCE=GP
export KEY_CITY=JHB
export KEY_ORG=”Companynamevpn”
export KEY_EMAIL=”name@email.com”
#. ./vars (note a space between . . )
#./clean-all

5. Build CA

#./build-ca
Generating a 1024 bit RSA private key1. Download the required package files.
#wget http://openvpn.net/release/openvpn-2.0.9.tar.gz
#wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm

2. Install and build your download files

make sure the following are installed

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

If you have the above dependencies installed, you can start your installation as follows:

#rpmbuild –rebuild lzo-1.08-4.rf.src.rpm
#rpm -Uvh /usr/src/redhat/RPMS/x86_64/lzo-*.rpm
#rpmbuild -tb openvpn-2.0.9.tar.gz
#rpm -Uvh /usr/src/redhat/RPMS/x86_64/openvpn-2.0.9-1.x86_64.rpm
NOTE – for i386 change the x8_64 directory to i386

3. Copy configuration files

#cp -r /usr/share/doc/openvpn-2.0.9/easy-rsa/ /etc/openvpn/
#cp /usr/share/doc/openvpn-2.0.9/sample-config-files/server.conf /etc/openvpn/

4. CA configuration

#cd /etc/openvpn/easy-rsa/
#vi vars

then scroll down to the bottom, edit as you like.

export KEY_COUNTRY=SA
export KEY_PROVINCE=GP
export KEY_CITY=JHB
export KEY_ORG=”Companynamevpn”
export KEY_EMAIL=”name@email.com”
#. ./vars (
………………………++++++
…………………….++++++
writing new private key to ‘ca.key’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [ZA]:
State or Province Name (full name) [GP]:
Locality Name (eg, city) [JHB]:
Organization Name (eg, company) [Companynamevpn]:
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server’s hostname) []: Companynamevpn
Email Address [name@mail.com]:

Some information above already entered in step 4, hust hit enter and go to next line.

6. Building server key

#./build-key-server ovpnsrv1
Generating a 1024 bit RSA private key
………………………………….++++++
…………………….++++++
writing new private key to ‘ovpnsrv1.key’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [SA]:
State or Province Name (full name) [GP]:
Locality Name (eg, city) [JHB]:
Organization Name (eg, company) [Companynamevpn]:
Organizational Unit Name (eg, section) []: Companynamevpn
Common Name (eg, your name or your server’s hostname) []:Companynamevpn
Email Address [name@email.com]:
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject’s Distinguished Name is as follows


Blah blah and then see the following.
Certificate is to be certified until Apr 10 15:15:27 2018 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

7. Building Diffie Hellman

#./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time

(Wait until it finished)

8. Copy key certificates to the required folder

#cp keys/ca.crt ../
#cp keys/dh1024.pem ../
#cp keys/ovpnsrv1.key ../
#cp keys/ovpnsrv1.crt ../

9. OpenVPN configuration

#cd ../
#vi server.conf
dev tap
;dev tun
ca ca.crt
cert ovpnsrv1.crt
key ovpnsrv1.key # This file should be kept secret
; You can also add a route to a network as follows:
push "route 10.200.0.0 255.255.255.0"

Important NOTE:

If you want to connect to another network once you have connected via vpn, then you will need to add a push "route 10.200.0.0 255.255.255.0" in the server.conf file on the server. And the other network might need a route added in the routing table to tell them where to find the client that has connected via vpn

10. Startup the OpenVPN service

#service openvpn restart
#chkconfig openvpn on

11. Generating client keys and certs on the server

The first time you try run the following you might come get errors – if so edit the /etc/openvpn/easy-rsa/keys/index.txt.attr file and change to the following:

unique_subject = no

You might also need to create an empty “.old” file in the /etc/openvpn/easy-rsa/keys/ folder

For each client you want to have connect do the following from the command prompt:

cd /etc/openvpn/easy-rsa

source ./vars

./build-key branch1 (choose a name for the client eg here is branch1)

./sign-req branch1



Windows Client Installation and Configuration

1. Download a copy of windows client

http://openvpn.net/release/openvpn-2.1.3-install.exe and install it.

2. Obtain cert and key

Get the following files from the server (located in /etc/openvpn/easy-rsa/keys/) and copy them to C:\Program Files\OpenVPN\config\

 

branch1.crt (or name of cert assigned)

branch1.csr (or name of cert assigned)

branch1.key (or name of key assigned)

ca.crt

ca.key

client.ovpn (if given along with the above – if not follow step 3)

 

3. Setting the client configuration for OpenVPN

Copy client.ovpn from C:\Program Files\OpenVPN\sample-config to C:\Program Files\OpenVPN\config

Edit it with the followings changes, similar to what you have done in the linux server

dev tap
;dev tun
dev-node OpenVPN_Tap
remote <ipaddress> 1194 (example: remote 202.188.1.1 1194)
ca ca.crt
cert branch1.crt #name of the cert you have been given
key branch1.key #name of the key you have been given
ns-cert-type server

4. Configure the network interface for OpenVPN
Select “Control Panel” -> “Network Connection” -> “TAP-Win32#(#)” (ie rename the “new” connection that has now appeared.
Right-Click to rename as ‘OpenVPN_Tap’

5. Startup the connection of client

Go to START>All Programs>OpenVPN>OpenVPN GUI , click it

In the task-bar, select “OpenVPN GUI” -> right-click “Connect”



Important NOTE:

If you want to connect to another network once you have connected via vpn, then you will need to add a push "route 10.200.0.0 255.255.255.0" in the server.conf file on the server. And the other network might need a route added in the routing table to tell them where to find the client that has connected via vpn

?

Comments:

Posted by zensh on
i never see so stupid person, completely copy of another blog and tow completed. copy one statment 4 times. be a man and right your own words.
Leave a Reply



(Your email will not be publicly displayed.)

Please type the letters and numbers shown in the image.Captcha CodeClick the image to see another captcha.