You are on page 1of 7

Implementacion de un tunel VPN entre dos ciudades para comunicar sus Redes Locales

Explicacion de como implementar una VPN entre dos ciudades por medio de los dos linux que estan de routers entre dos redes locales y el openvpn. Con esto se ahorrara el costo de lineas dedicada. Los dos routers linux estan bajo la distribucion RedHat 9.

Topologia de las redes: RedLocal1 - eth1_Servidor1_eth0 - Modem1 ----- INTERNET ----- Modem2 eth0_Servidor2_eth1 - RedLocal2 10.30.65.0/24 - 10.30.65.131 (eth1) - 192.168.100.2 (eth0) (192.168.100.1 - 200.80.90.100) -----> INTERNET INTERNET <----- (200.150.160.170 - 192.168.254.254) - 192.168.254.1 (eth0) - 10.30.75.69 (eth1) - 10.30.75.0/24 Modem1 = Speed Touch Pro Alcatel (192.168.100.1 interna - 200.80.90.100 externa y publica) Modem2= SpeedStream 5660-R-ENI (200.150.160.170 externa y publica192.168.254.254 interna ) NOTA: IPs publicas modificadas intencionalmente En el servidor1 bajo el paquete rpm del openvpn ( openvpn-1.4.3-0.dag.rh90.i386.rpm ) desde http://rpm.pbone.net/index.php3/stat/17/dept/3/idg/Networking_Tunnels y para habilitar la caracteristica de compresion del openvpn se baja el paquete lzo-1.08fr2.i386.rpm de http://rpmfind.rediris.es/rpm2html/freshrpms-redhat9/lzo/ByName.html, y se prosigue con la instalacion de ambos paquetes: [root@servidor1 openvpn]# rpm -Uvh lzo-1.08-fr2.i386.rpm Preparing... ########################################### [100%] 1:lzo ########################################### [100%] [root@servidor1 openvpn]# rpm -Uvh openvpn-1.4.3-0.dag.rh90.i386.rpm Preparing... ########################################### [100%] 1:openvpn ########################################### [100%] Se Activa el modulo para tun (tarjeta virtual que manejara el enlace del tunel) [root@servidor1 openvpn]# modprobe tun Se mandan los paquetes al Servidor2 y se instalan de la misma forma. Se Utilizara la autentificacion por llaves pre-compartidas, se genera la llave en el directorio /etc del servidor1 y se manda a el servidor2 por un medio seguro, por ejemplo por SSH. [root@servidor1 etc]# openvpn --genkey --secret static_openvpn.key [root@servidor1 etc]# scp static_openvpn.key root@servidor2:/etc/

root@servidor2's password: static_openvpn.key 100% |*********************************************************************| 346 00:00 Se crean los archivos de configuracion para el open vpn, para el servidor1 quedan como sigue (son 2 archivos de configuracion por servidor, primero el vpnservidor1.conf y despues el vpnservidor1.up ######### servidor1 /etc/openvpn/vpnservidor1.conf ########### #local [ip local] #remote [ip remota] # ips publicas servidor1 200.80.90.100 -- ip servidor2 200.150.160.170 # ips externa servidor1 192.168.100.2 -- ip servidor2 192.168.254.1 # ips internas servidor1 10.30.65.131 -- ip servidor2 10.30.75.69 local 192.168.100.2 remote 200.150.160.170 dev tun0 #puerto UDP port 5000 comp-lzo user nobody ping 15 ifconfig 10.30.65.131 10.30.75.69 up /etc/vpnservidor1.up secret /etc/static_openvpn.key # en el otro equipo se hace lo mismo cambiando las ip # Verbosity level. # 0 -- quiet except for fatal errors. # 1 -- mostly quiet, but display non-fatal network errors. # 3 -- medium output, good for normal operation. # 9 -- verbose, good for troubleshooting # verb 3 ######### servidor1 /etc/vpnservidor1.conf ########### #!/bin/bash route add -net 10.30.75.0 netmask 255.255.255.0 gw $5

y para servidor2 quedan como sigue: ######### servidor2 /etc/openvpn/vpnservidor2.conf ########### #local [ip local] #remote [ip remota] # ips publicas servidor1 200.80.90.100 -- ip servidor2 200.150.160.170 # ips externa servidor1 192.168.100.2 -- ip servidor2 192.168.254.1 # ips internas servidor1 10.30.65.131 -- ip servidor2 10.30.75.69 local 192.168.254.1 remote 200.80.90.100 dev tun0 #puerto UDP port 5000 comp-lzo user nobody ping 15

ifconfig 10.30.75.69 10.30.65.131 up /etc/vpnservidor2.up secret /etc/static_openvpn.key # en el otro equipo se hace lo mismo cambiando las ip # Verbosity level. # 0 -- quiet except for fatal errors. # 1 -- mostly quiet, but display non-fatal network errors. # 3 -- medium output, good for normal operation. # 9 -- verbose, good for troubleshooting # verb 3 ######### servidor2 /etc/vpnservidor2.conf ########### #!/bin/bash route add -net 10.30.65.0 netmask 255.255.255.0 gw $5 - Se configura el firewall en servidor1 y en servidor2 (en este caso la configuracion queda en /etc/Bastille/bastille-firewall-early.sh pues es el firewall del bastille que estamos utilizando), queda como sigue ######### en servidor1 /etc/Bastille/bastille-firewall-early.sh ########### (solo la parte que da acceso al openvpn) ## Recomendadas por el openVPN # Change this subnet to correspond to your private # ethernet subnet. Home will use 10.0.1.0/24 and # Office will use 10.0.0.0/24. PRIVATE=10.30.65./24 # Loopback address LOOP=127.0.0.1 # eth0 is connected to the internet. # eth1 is connected to a private subnet. # Prevent external packets from using loopback addr iptables -A INPUT -i eth0 -s $LOOP -j DROP iptables -A FORWARD -i eth0 -s $LOOP -j DROP iptables -A INPUT -i eth0 -d $LOOP -j DROP iptables -A FORWARD -i eth0 -d $LOOP -j DROP # Aceptar trafico desde el router de infinitum (para el telnet) iptables -A FORWARD -i eth0 -s 192.168.100.1/255.255.255.0 -j ACCEPT iptables -A INPUT -i eth0 -s 192.168.100.1/255.255.255.0 -j ACCEPT # Anything coming from the Internet should have a real Internet address iptables -A FORWARD -i eth0 -s 192.168.0.0/16 -j DROP iptables -A FORWARD -i eth0 -s 172.16.0.0/12 -j DROP iptables -A FORWARD -i eth0 -s 10.0.0.0/8 -j DROP iptables -A INPUT -i eth0 -s 192.168.0.0/16 -j DROP iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP # Block outgoing NetBios (if you have windows machines running # on the private subnet). This will not affect any NetBios # traffic that flows over the VPN tunnel, but it will stop # local windows machines from broadcasting themselves to # the internet. iptables -A FORWARD -p tcp --sport 137:139 -o eth0 -j DROP iptables -A FORWARD -p udp --sport 137:139 -o eth0 -j DROP iptables -A OUTPUT -p tcp --sport 137:139 -o eth0 -j DROP iptables -A OUTPUT -p udp --sport 137:139 -o eth0 -j DROP # Check source address validity on packets going out to internet # iptables -A FORWARD -s ! $PRIVATE -i eth1 -j DROP

# Allow incoming pings (can be disabled) from servidor2 iptables -A INPUT -p icmp --icmp-type echo-request -s 200.150.160.170 -j ACCEPT # Allow incoming OpenVPN packets # Duplicate the line below for each # OpenVPN tunnel, changing --dport n # to match the OpenVPN UDP port. # # In OpenVPN, the port number is # controlled by the --port n option. # If you put this option in the config # file, you can remove the leading '--' # # If you taking the stateful firewall # approach (see the OpenVPN HOWTO), # then comment out the line below. iptables -A INPUT -p udp --dport 5000 -j ACCEPT # Allow packets from TUN/TAP devices. # When OpenVPN is run in a secure mode, # it will authenticate packets prior # to their arriving on a tun or tap # interface. Therefore, it is not # necessary to add any filters here, # unless you want to restrict the # type of packets which can flow over # the tunnel. iptables -A INPUT -i tun+ -j ACCEPT iptables -A FORWARD -i tun+ -j ACCEPT iptables -A INPUT -i tap+ -j ACCEPT iptables -A FORWARD -i tap+ -j ACCEPT # Forward a los paquetes que vengan por la tarjeta eth1 a el tunel iptables -A FORWARD -i eth1 -j ACCEPT # Keep state of connections from local machine and private subnets iptables -A OUTPUT -m state --state NEW -o eth0 -j ACCEPT #iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -m state --state NEW -o eth0 -j ACCEPT #iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT # Masquerade local subnet # Mejor hago la SNAT y ver si no afecta a el openvpn (nota: NO, no le afecto el SNAT) -------------- En servidor2 queda asi: ######### en servidor2 /etc/Bastille/bastille-firewall-early.sh ########### (solo la parte que da acceso al openvpn) ## Recomendadas por el openVPN # Change this subnet to correspond to your private # ethernet subnet. Home will use 10.0.1.0/24 and # Office will use 10.0.0.0/24. PRIVATE=10.30.75./24 # Loopback address LOOP=127.0.0.1 # eth0 is connected to the internet. # eth1 is connected to a private subnet. # Prevent external packets from using loopback addr iptables -A INPUT -i eth0 -s $LOOP -j DROP

iptables -A FORWARD -i eth0 -s $LOOP -j DROP iptables -A INPUT -i eth0 -d $LOOP -j DROP iptables -A FORWARD -i eth0 -d $LOOP -j DROP # Anything coming from the Internet should have a real Internet address #iptables -A FORWARD -i eth0 -s 192.168.0.0/16 -j DROP iptables -A FORWARD -i eth0 -s 172.16.0.0/12 -j DROP iptables -A FORWARD -i eth0 -s 10.0.0.0/8 -j DROP #iptables -A INPUT -i eth0 -s 192.168.0.0/16 -j DROP iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP # Block outgoing NetBios (if you have windows machines running # on the private subnet). This will not affect any NetBios # traffic that flows over the VPN tunnel, but it will stop # local windows machines from broadcasting themselves to # the internet. iptables -A FORWARD -p tcp --sport 137:139 -o eth0 -j DROP iptables -A FORWARD -p udp --sport 137:139 -o eth0 -j DROP iptables -A OUTPUT -p tcp --sport 137:139 -o eth0 -j DROP iptables -A OUTPUT -p udp --sport 137:139 -o eth0 -j DROP # Check source address validity on packets going out to internet # iptables -A FORWARD -s ! $PRIVATE -i eth1 -j DROP # Allow incoming pings (can be disabled) from servidor1 # Duplicate the line below for each # OpenVPN tunnel, changing --dport n # to match the OpenVPN UDP port. # # In OpenVPN, the port number is # controlled by the --port n option. # If you put this option in the config # file, you can remove the leading '--' # # If you taking the stateful firewall # approach (see the OpenVPN HOWTO), # then comment out the line below. iptables -A INPUT -p udp --dport 5000 -j ACCEPT # Allow packets from TUN/TAP devices. # When OpenVPN is run in a secure mode, # it will authenticate packets prior # to their arriving on a tun or tap # interface. Therefore, it is not # necessary to add any filters here, # unless you want to restrict the # type of packets which can flow over # the tunnel. iptables -A INPUT -i tun+ -j ACCEPT iptables -A FORWARD -i tun+ -j ACCEPT iptables -A INPUT -i tap+ -j ACCEPT iptables -A FORWARD -i tap+ -j ACCEPT # Forward a los paquetes que vengan por la tarjeta eth1 a el tunel iptables -A FORWARD -i eth1 -j ACCEPT # Keep state of connections from local machine and private subnets iptables -A OUTPUT -m state --state NEW -o eth0 -j ACCEPT #iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -m state --state NEW -o eth0 -j ACCEPT #iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

CONFIGURACION DEL SPEED TOUCH PRO PARA EL FORWARD DEL PUERTO 5000 (no es necesario si se tiene un ip publica para el servidor1) conectarse por telnet a 192.168.100.1 user passwd # nat #create protocol=udp inside_addr=192.168.100.2 inside_port=5000 outside_addr=200.80.90.100 outside_port=5000 #save En servidor2 solo se pone en DMZ el modem hacia el servidor linux (por administracion web) PUESTA EN MARCHA Y PRUEBAS DEL VPN - Se prueba el vpn con la siguiente instruccion, el verb esta en 9 para verificar posibles problemas en el archivo de logs(dar el comando en ambos servidores) en servidor1 [root@servidor1 openvpn]# openvpn --daemon --verb 9 --config /etc/openvpn/vpnservidor1.conf en servidor2 [root@servidor1 openvpn]# openvpn --daemon --verb 9 --config /etc/openvpn/vpnservidor2.conf y en los logs de servidor2 o servidor1 (el ultimo openvpn que se haya ejecutado) debe haber algo como "Peer Connection Initiated with", que indica que el tunel se realizo exitosamente [root@servidor1 openvpn]# grep "Peer Connection Initiated with" /var/log/messages Oct 25 12:42:42 servidor1 openvpn[23468]: Peer Connection Initiated with 200.150.160.170:5000 o [root@servidor2 openvpn]# grep "Peer Connection Initiated with" /var/log/messages Oct 25 12:44:46 servidor2 openvpn[6922]: Peer Connection Initiated with 200.80.90.100:5000 Se verifica la conexion dando un ping desde la subred de servidor1 a la subred de servidor2 y se la la instruccion #tcpdump -i tun0 Para verificar que los paquetes se esten comunicando por el tunel

Se puede dar las siguientes instrucciones para que no genere tantos logs: #openvpn --daemon --verb 3 --config /root/openvpn/vpnservidor1.conf #openvpn --daemon --verb 3 --config /root/openvpn/vpnservidor2.conf Se puede dar las siguiente instrucciones para verificar que el firewall no este parando algun paquete que se necesite y estar monitoreando el firewall [root@servidor1 store]# watch iptables -L -v -n --exact --line-numbers [root@servidor1 store]# iptables -L -v -n --exact --line-numbers | grep DROP [root@servidor1 store]# iptables -L -v -n --exact --line-numbers | grep ACCEPT [root@servidor1 store]# watch iptables -L -v -n --exact --line-numbers -t nat PARA QUE SE EJECUTE AL INICIO EL VPN Ya que se probo que funciona el tunel se configura linux para que se ejecute automaticamente al inicio Se copia el archivo de configuracion a /etc/openvpn/ en ambos servidores se activa en el chkconfig :) [root@servidor1 openvpn]# cp vpnservidor1.conf /etc/openvpn/ [root@servidor2 root]# chkconfig openvpn on [root@servidor2 root]# chkconfig --list |grep vpn openvpn 0:off 1:off 2:on 3:on 4:on 5:on 6:off LISTO ! Ya quedo el VPN entre servidor1 y servidor2 MAS AYUDA EN: http://openvpn.sourceforge.net/howto.html http://openvpn.sourceforge.net/howto.html#pre-shared http://www.netfilter.org/ http://www.google.com/

You might also like