twitter
    Sigueme en el Twitter :-)

21 diciembre 2009

OpenVPN Roadwarrior en Centos

Las Redes Privadas o VPN, actualmente se usan para unir redes fisicamente ubicadas en lugar lejanos "simulado" que estuvieran en el mismo ambiente.
Bueno esto es lo que dice la definición o algo así, pero lo que quiero compartir ahora va un poco más allá, pienso que tener implementado una VPN podría reducir los ataques SPAM (si esta bien configurada al igual que el correo), así como la compartición de la información en la empresa. Sea cual sea la utilidad que desees darle he aquí lo que generalmente realizó para armar una. Dentro de las mas conocidas existen los sgts tipos de VPN: point to point, roadwarrior, lan to lan...

La instalación será usando CentOS 5.4 y se implementará una VPN RoadWarrior

1.- Instalar el repositorio RPM Forge (DAG) para poder instalar con YUM la aplicacion
2.- Instalando openvpn:

yum -y install openvpn lzo
.
3.- Copiamos lo siguiente:
cp -a /usr/share/openvpn/easy-rsa /etc/openvpn

4.- No dirigimos a:
cd /etc/openvpn/easy-rsa/2.0

5.- Luego de ingresar al directorio procederemos a ejecutar lo siguiente:
. vars

sh clean-all

sh build-ca

6.- Los comandos que se digitaron anteriormente preparan la configuracion de certificados para lo cual veremos en pantalla:
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) [KG]:PE
State or Province Name (full name) [NA]:Lima
Locality Name (eg, city) [BISHKEK]:Peru
Organization Name (eg, company) [OpenVPN-TEST]:Mi_Empresa
Organizational Unit Name (eg, section) []:Sistemas
Common Name (eg, your name or your server's hostname) []:hostname_server
Email Address [me@myhost.mydomain]:admin@empresa.com


7.- Ahora generamos un certificado de autoridad para el servidor:
sh build-key-server server


8.- Lo siguiente nos debe de mostrar:
Generating a 1024 bit RSA private key
......................++++++
writing new private key to 'server.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) [KG]:Pe
State or Province Name (full name) [NA]:Lima
Locality Name (eg, city) [BISHKEK]:Peru
Organization Name (eg, company) [OpenVPN-TEST]:Mi_Empresa
Organizational Unit Name (eg, section) []:Sistemas
Common Name (eg, your name or your server's hostname)[]:hostname_server
server Email Address [me@myhost.mydomain]:admin@empresa.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 countryName :PRINTABLE:'EC' stateOrProvinceName :PRINTABLE:'Pichincha' localityName :PRINTABLE:'Quito' organizationName :PRINTABLE:'EcuaLinux' organizationalUnitName:PRINTABLE:'IT' commonName :PRINTABLE:'server' emailAddress :IA5STRING:'info@ecualinux.com' The stateOrProvinceName field needed to be the same in the CA certificate


9.- Este paso nos generará dos archivos en el directorio /etc/openvpn/easy-rsa/keys/ que se deben de copiar dentro del mismo servidor en la ruta /etc/openvpn, ellos son:

server.crt,server.key


10.- Ahora para generar los certificados de los clientes, de forma similar ejecutamos lo siguiente:
sh build-key pepito


11.- El resultado en pantalla será:



Generating a 1024 bit RSA private key

...............................................................................................++++++
writing new private key to 'pepito.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) [KG]:Pe
State or Province Name (full name) [NA]:Lima
Locality Name (eg, city) [BISHKEK]:Peru
Organization Name (eg, company) [OpenVPN-TEST]:Mi_Empresa
Organizational Unit Name (eg, section) []:Sistemas
Common Name (eg, your name or your server's hostname) []:pepito
Email Address [me@myhost.mydomain]:admin@empresa.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
countryName :PRINTABLE:'Pe'
stateOrProvinceName :PRINTABLE:'Lima'
localityName :PRINTABLE:'Peru'
organizationName :PRINTABLE:'Mi_Empresa'
organizationalUnitName:PRINTABLE:'Sistemas'
commonName :PRINTABLE:'pepito'
emailAddress :IA5STRING:'admin@empresa.com'
Certificate is to be certified until Dec 21 05:25:40 2010 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


12.- Si queremos generar mas certificados para mas clientes, seguimos el mismo mecanismo, y para finalizar ejecutamos el comando:
sh build-dh


13.- Debemos tener en cuenta que en /etc/openvpn del servidor deben de estar los siguientes archivos:

ca.crt, ca.key, server.key, server.crt, dh1024.pem


14.- Estos archivos los encontramos en: /etc/openvpn/easy-rsa/keys

15.- Ahora procedemos a configurar el archivo "/etc/openvpn/server.conf"

port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
server 10.8.0.0 255.255.255.0 # Rango de ips para los clientes
ifconfig-pool-persist ipp.txt
#Ruta para que los clientes alcancen la red local del server (56.0/24)
push "route 192.168.56.0 255.255.255.0"
keepalive 10 120
comp-lzo
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
verb 4


16.- Para realizar la conexion con la VPN, el cliente tiene que tener instalado la aplicacion openvpn-gui, la cual la pueden encontrar aqui, Luego de instalarlo, nos ubicamos en C:/Archivos de programa/OpenVPN/config, aqui modificaremos el archivo "servidior.opvn" (le pueden colocar cualquier nombre) de la siguiente forma:

client
dev tun
proto udp
remote IP_PUBLICA_DEL_SERVIDOR 1194
resolv-retry infinite
nobind
#Las dos siguientes opciones no van en windows
user nobody
group nobody
persist-key
persist-tun
ca ca.crt
cert pepito.crt
key pepito.key
comp-lzo
verb 4

A su vez tambien copiamos los certificados que creamos anteriormente, pepito.crt, pepito.ca y los pegamos en: C:\Archivos de programa\OpenVPN\config

Espero que les sea de utilidad, he tratado de hacerlo lo mas detallado posible.
Saludos

1 comentario:

Diego Sanchez dijo...

Tengo un problemin:

root@proxy ~/ # cp -a /usr/share/openvpn/easy-rsa /etc/openvpn
cp: no se puede efectuar `stat' sobre «/usr/share/openvpn/easy-rsa»: No existe el fichero o el directorio