MRKAVANA (mrkavana@gmail.com) - www.facebook.com/kavanathai
Showing posts with label vpn. Show all posts
Showing posts with label vpn. Show all posts

Jul 28, 2011

OpenVPN and CentOS 5 Installation and Configuration Guide


Many ppl found that installing VPN on linux is not that easy, the abvailable installation guides on VPN is often limited. I have tried a lot of installation guides and finally get it connected successfully.
Here are the steps to guide you installed a secure connection between your� CentOS5 and Windows with OpenVPN open source application.
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
You may need the required repository before start your installation
#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/i386/lzo-*.rpm
#rpmbuild -tb openvpn-2.0.9.tar.gz
#rpm -Uvh /usr/src/redhat/RPMS/i386/openvpn-2.0.9-1.i386.rpm
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/
#pico vars (or use vi editor, I just like to use pico)
then scroll down to the bottom, edit as you like.
export KEY_COUNTRY=AU
export KEY_PROVINCE=VIC
export KEY_CITY=MELBOURNE
export KEY_ORG=”THROXVPN”
export KEY_EMAIL=”name@email.com”
#.� ./vars (note a space between . . )
#./clean-all
5. Build CA
#./build-ca
Generating a 1024 bit RSA private key
………………………++++++
…………………….++++++
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) [AU]:
State or Province Name (full name) [VIC]:
Locality Name (eg, city) [MELBOURNE]:
Organization Name (eg, company) [THROXVPN]:
Organizational Unit Name (eg, section) []:Throx
Common Name (eg, your name or your server’s hostname) []:throx.net
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) [AU]:
State or Province Name (full name) [VIC]:
Locality Name (eg, city) [MELBOURNE]:
Organization Name (eg, company) [THROXVPN]:
Organizational Unit Name (eg, section) []:Throx
Common Name (eg, your name or your server’s hostname) []:throx.net
Email Address [name@email.com]:
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:<enter your password here>
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
countryName���������� :P RINTABLE:’AU’
stateOrProvinceName�� :P RINTABLE:’VIC’
localityName��������� :P RINTABLE:’MELBOURNE’
organizationName����� :P RINTABLE:’THROXVPN’
organizationalUnitName:PRINTABLE:’Throx’
commonName����������� :P RINTABLE:’throx.net’
emailAddress��������� :IA5STRING:’name@email.com’
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 ../
#pico server.conf
dev tap
;dev tun
ca ca.crt
cert ovpnsrv1.crt
key ovpnsrv1.key # This file should be kept secret
10. Startup the OpenVPN service (Finally, hold your breath)
#service openvpn restart
#chkconfig openvpn on
Windows Client Installation and Configuration
1. Download a copy of windows client
http://openvpn.net/release/openvpn-2.0.9-install.exe and install it.
2. Create CA in windows machine
Open windows cmd.exe command promp and change directory (cd) into c:\program files\openvpn\
>copy vars.bat.sample vars.bat
>edit vars.bat (scroll down to the bottom)
set KEY_COUNTRY=AU
set KEY_PROVINCE=VIC
set KEY_CITY=MELBOURNE
set KEY_ORG=THROXVPN
set KEY_EMAIL=name@mail.com
note: the above information must be same as the details set in server previously.
3. Run the file vars.bat
>vars
4. Build client’s key and certificate
>copy openssl.cnf.sample openssl.cnf
>md keys
>build-key vpnhome
5. Copy vpnhome.csr to the server directory /etc/openvpn/easy-rsa/keys
#cd /etc/openvpn/easy-rsa/
#./sign-req vpnhome
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
countryName���������� :P RINTABLE:’AU’
stateOrProvinceName�� :P RINTABLE:’VIC’
localityName��������� :P RINTABLE:’MELBOURNE’
organizationName����� :P RINTABLE:’THROXVPN’
organizationalUnitName:PRINTABLE:’Throx’
commonName����������� :P RINTABLE:’throx.net’
emailAddress��������� :IA5STRING:’name@mail.com’
Certificate is to be certified until Apr 10 16:04:33 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
6. Copy new signed certificate to your windows machine
Go to /etc/openvpn/easy-rsa/keys/ , you will see 2 new generated file – ca.crt and vpnhome.crt
Copy both of them to your Windows home machine c:/Program Files/OpenVPN/config
Also copy your windows generated vpnhome.key from C:\Program Files\OpenVPN\easy-rsa\keys to C:\Program Files\OpenVPN\config
7. 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 alanghome.crt
key alanghome.key
ns-cert-type server
8. Configure the network interface for OpenVPN
Select “Control Panel” -> “Network Connection” -> “TAP-Win32#(#)”
Right-Click to rename as ‘OpenVPN_Tap’
9. 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”
Phew…. if everything set correctly, now you should be connected to your linux via OpenVPN.


Jul 18, 2011

Installing and configuring l2tp vpn using xl2tpd

xl2tpd howto

Vpn is use to create a tunnel from your pc to your office system. There are lots of vpn softwares such as openvpn, pptpd, xl2tpd etc.
Here we will discuss about the installaion and configuration of xl2tpd vpn software.
For other vpn installations search in the tags of this very same site.
These steps will work with Redhat, CentOS, Fedora and other redhat distributions.

Install the following packages using yum or rpms :
yum install -y ppp iptables make gcc gmp-devel xmlto bison flex xmlto libpcap-devel lsof vim-enhanced

Download and install Openswan :
mkdir -p /ztmp/l2tp
cd /ztmp/l2tp
wget http://www.openswan.org/download/openswan-2.6.24.tar.gz
tar zxvf openswan-2.6.24.tar.gz
cd openswan-2.6.24
make programs install

If there is ipsec.conf file take a backup and create new one as follows :
cp /etc/ipsec.conf{,.bkp}
rm -rf /etc/ipsec.conf
touch /etc/ipsec.conf

vi /etc/ipsec.conf
config setup
nat_traversal=yes
virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12
oe=off
protostack=netkey

conn L2TP-PSK-NAT
rightsubnet=vhost:%priv
also=L2TP-PSK-noNAT

conn L2TP-PSK-noNAT
authby=secret
pfs=no
auto=add
keyingtries=3
rekey=no
ikelifetime=8h
keylife=1h
type=transport
left=25.289.2.24 #your vps public IP 
leftprotoport=17/1701
right=%any
rightprotoport=17/%any

In the file ipsec.secrets, Give the following line :
vi /etc/ipsec.secrets
25.289.2.24 %any: PSK "server.lap.work"

Enable IP Forwarding in /etc/sysctl.conf
net.ipv4.ip_forward = 1

Reload Sysctl settings
sysctl -p

Enable masquerading
iptables -t nat -A POSTROUTING -j MASQUERADE

Set the following parameters
for each in /proc/sys/net/ipv4/conf/*
do
echo 0 > $each/accept_redirects
echo 0 > $each/send_redirects
done

Restart ipsec and verify :
/etc/init.d/ipsec restart
ipsec verify

Download and install rp-l2tp :
cd /ztmp/l2tp
wget http://mirror.zeddicus.com/sources/rp-l2tp-0.4.tar.gz
tar zxvf rp-l2tp-0.4.tar.gz
cd rp-l2tp-0.4
./configure
make

cp handlers/l2tp-control /usr/local/sbin/
mkdir /var/run/xl2tpd/
ln -s /usr/local/sbin/l2tp-control /var/run/xl2tpd/l2tp-control

Download and install xl2pd
cd /ztmp/l2tp
wget http://mirror.zeddicus.com/sources/xl2tpd-1.2.4.tar.gz
tar zxvf xl2tpd-1.2.4.tar.gz
cd xl2tpd-1.2.4
make install

mkdir /etc/xl2tpd
rm -rf /etc/xl2tpd/xl2tpd.conf
touch /etc/xl2tpd/xl2tpd.conf

Edit the configuration file of xl2pd as follows
vi /etc/xl2tpd/xl2tpd.conf
[global]
ipsec saref = yes
[lns default]
ip range = 10.0.0.2-10.0.0.254
local ip = 10.0.0.1
refuse chap = yes
refuse pap = yes
require authentication = yes
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

cp /etc/ppp/options.xl2tpd{,.bkp}
rm -rf /etc/ppp/options.xl2tpd
touch /etc/ppp/options.xl2tpd

Edit the options file as given below
vi /etc/ppp/options.xl2tpd
require-mschap-v2
ms-dns 8.8.8.8
ms-dns 8.8.4.4
asyncmap 0
auth
crtscts
lock
hide-password
modem
debug
name l2tpd
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4

Add the user login details to chap-secrets file
vi /etc/ppp/chap-secrets
test l2tpd test123 *

Create the following script
vi /usr/bin/zl2tpset
#!/bin/bash
for each in /proc/sys/net/ipv4/conf/*"
do
echo 0 > \$each/accept_redirects
echo 0 > \$each/send_redirects
done

Give it execution permission
chmod +x /usr/bin/zl2tpset

Run the commands :
zl2tpset
xl2tpd

Append the following lines to rc.local
vi /etc/rc.local
iptables -t nat -A POSTROUTING -j MASQUERADE
/etc/init.d/ipsec restart
/usr/bin/zl2tpset
/usr/local/sbin/xl2tpd

Verify ipsec :
ipsec verify

Now you can connect the vpn using the following credentials

ServerIP:25.289.2.24
username:test
password:test123
PSK Key:server.lap.work




How to install pptpd on vpn openvz linux vps

The following post explains how to setup pptpd vpn on centos linux vps created on openvz server node.

On openvz node machine :
Enable these modules. 

modprobe ppp_mppe 
modprobe ppp_deflate 
modprobe zlib_deflate 
modprobe ppp_async 
modprobe ppp_generic 
modprobe slhc 
modprobe crc_ccitt 

[root@me ~]# lsmod | grep ppp
ppp_mppe 39816 0
ppp_deflate 39168 0
zlib_deflate 52760 1 ppp_deflate
ppp_async 45056 0
ppp_generic 63632 4 ppp_mppe,ppp_deflate,ppp_async
slhc 39680 1 ppp_generic
crc_ccitt 35200 1 ppp_async

Creating and enabling PPP for vps :
Replace the VEnumber with your vps id and execute the following commands on openvz server.



vzctl set [VEnumber] --features ppp:on --save
vzctl start [VEnumber]
vzctl set [VEnumber] --devices c:108:0:rw --save
vzctl exec [VEnumber] mknod /dev/ppp c 108 0
vzctl exec [VEnumber] chmod 600 /dev/ppp

/usr/sbin/pppd
You should see output like
~?}#?!}!}!} }4}"}&} } } } }%}&)Q?}4}'}"}(}"p})
Now thats done.

On openvz vps :
Install pptpd :

yum install pptpd
/etc/init.d/pptpd start

Add users :
[root@me ]# vi /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client server secret IP addresses
vpn1 pptpd cyiefdxYn *
[root@me ]#

Usename is : vpn1
Password is : cyiefdxYn

now restart the pptpd service.
/etc/init.d/pptpd restart

Thats it.
You can check the logs while connecting to this server as

tail -f /var/log/messages




Installing Webmin and pptp with ssl on openvz

This post explains installing and configuring webmin and pptp with ssl on openvz vps. The os template is centos5. 

On the node :
modprobe ppp_async
modprobe ppp_deflate
modprobe ppp_mppe
vzlist -a |grep IP_of_vps
vzctl stop [VEID]
vzctl set [VEID] --features ppp:on --save
vzctl start [VEID]
vzctl set [VEID] --devices c:108:0:rw --save
vzctl exec [VEID] mknod /dev/ppp c 108 0
vzctl exec [VEID] mknod /dev/ppp c 108 0
vzctl exec [VEID] chmod 600 /dev/ppp

You need all these modules on node:
[root@dallas5 ~]# lsmod | grep ppp
ppp_mppe 39816 0
ppp_deflate 39168 0
zlib_deflate 52760 1 ppp_deflate
ppp_async 45184 0
ppp_generic 63760 4 ppp_mppe,ppp_deflate,ppp_async
slhc 39680 1 ppp_generic
crc_ccitt 35200 1 ppp_async

On the VPS:[Openvz]
wget http://prdownloads.sourceforge.net/webadmin/webmin-1.550-1.noarch.rpm
rpm -ivh webmin-1.550-1.noarch.rpm
/etc/init.d/webmin start
chkconfig --level 35 webmin on
wget http://poptop.sourceforge.net/yum/stable/packages/pptpd-1.3.4-2.rhel5.i386.rpm
rpm -ivh pptpd-1.3.4-2.rhel5.i386.rpm
/etc/init.d/pptpd start
chkconfig --level 35 pptpd on
yum install openssl openssl-devel
yum install perl-Net-SSLeay #for ssl+webmin
perl -e 'use Net::SSLeay' #testing
echo $? #testing exit status '0'

You can access the webmin at https://IP_address:10000 and do the further configuration of pptpd and ppp.

Some useful links :
http://www.webmin.com/ssl.html
http://wiki.openvz.org/PPP_in_container




How to create users in pptpd vpn

Open the chap-secrets file using your favorate editor and give username and password as follows.

[root@me]# vi /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client server secret IP addresses
user1 pptpd abc123



save the file and restart the pptpd service.
[root@me]# /etc/init.d/pptpd restart