Skip to main content

Cómo crear un Servidor VPN en una Raspberry Pi B+

¿Ocupas crear una aplicación en una Raspberry Pi que sea accesible desde cualquier parte del mundo y no sólo desde su red local?
En este post se le ayudará a lograr eso, ya que se le explicará una forma de cómo lograrló, usando una VPN (Virtual Private Networks) con el protocolo PPTP (Point-to-Point Tunneling Protocol).
¿Qué es una VPN? ¿Por qué es útil en una RPI?
Una VPN permite desde una red privada conectar a cualquier ubicación geográfica mediante la IP pública, creando un túnel entre el cliente y el servidor, donde los datos cifrados viajan. Siempre y cuando se disponga de los permisos, autorizaciones y autentificaciones necesarias que permita navegar por el dispositivo como si estuviera en una red local.
Una vez estando conectado al servidor VPN nuestro dispositivo pasará a formar parte de la red privada virtual, logrando comunicarnos con ella como si se tratará de una red local y consiguiendo acceder a los servicios e información de la red a la que se conectó.

En una RPI esto es muy importante cuando se tiene aplicaciones corriendo en esta y se necesita estar monitoreando o controlando la misma desde cualquier parte del mundo independientemente donde se encuentren ubicados los equipos.

Precondiciones

  1. Tener acceso a internet (Ethernet o Wi-Fi).
  2. Hardware usado: Raspberry Pi B+ (debería funcionar para cualquier familia de Raspberry Pi u otro hardware).
  3. Sistema Operativo usado: Raspbian

Paso #1: Instalar el protocolo PPTP y asignar una IP Estática

# Actualizar la RPI
sudo apt-get update & sudo apt-get upgrade
Asegurarse que el servidor (dispositivo) tenga una Ip fija o estática (esto es importante porque cuando un paquete llega al router, este debe ser enviado a la Ip correcta donde está el servidor), esto se puede definir en el mismo router o en el dispositivo editando el siguiente archivo:
sudo vim.tiny /etc/network/interfaces
Deberíar estar configurado como se muestra en la imagen de abajo:
# Installar el protocolo pptp
sudo apt-get install pptpd
# Editar el archivo:
sudo vim.tiny /etc/pptpd.conf
Agregar la Ip estática asignada anteriormente y el rango de IPs al final del archivo que se le van a asignar a los clientes. Ejemplo:
localip 192.168.0.50
remoteip 192.168.0.234-238,192.168.0.245

Paso #2:  Agregar los clientes que van a usar el servidor VPN

sudo vim.tiny /etc/ppp/pptpd-options
Agregar a este archivo las siguientes descripciones (usar el gateway de la Ip estática a usar):
ms-dns 192.168.0.1
nobsdcomp
noipx
mtu 1490
mru 1490
Agregar uno o varios nombres de usuarios y las contraseña que deberán tener los clientes que accederán al servidor VPN:
# Agregarlos usando este formato: NOMBRE_USUARIO [TAB] * [TAB]  CONSTRASEÑA [TAB]*
sudo vim.tiny /etc/ppp/chap-secrets
# Reiniciar pptpd
sudo service pptpd restart
# Configurar el tráfico forward en la RPI. Descomentar la linea: net.ipv4.ip_forward=1
sudo nano /etc/sysctl.conf
# Aplicar los cambios del forward 
sudo sysctl -p

Paso #3: Activar los Ports Forwarding en el router

Es importarte que active el puerto 1723. Además, para tener acceso por SSH puede activar el puerto 22 y para HTTP,  el puerto 80. Como se ilustra en la siguiente imagen:

Por otro lado, si desea usar un DNS o una url para acceder desde el exterior en vez de la Ip pública, puede seguir estos simples pasos:
  1. Ingresar a la dirección: www.noip.com. Crear una cuenta, escoger un dominio o usar alguno que ya poséa y asignar la Ip pública de su router.
  2. Ejecutar en terminal:
mkdir /home/pi/noip
cd /home/pi/noip
wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar vzxf noip-duc-linux.tar.gz
cd noip-2.1.9-1
sudo make
sudo make install
# Correr el cliente
sudo /usr/local/bin/noip2
sudo reboot

Para ver el funcionamiento del dominio creado anteriormente puede ver el siguiente video. Aquí se muestra lo visto en en el post, pero ahora no sólo se accede al servidor web desde una red local sino desde cualquier ubicación con acceso a Internet (por ejemplo: su teléfono celular):
Para ver el funcionamiento de la VPN puede ver el video de abajo. Ahí se puede ver como desde un celular (conectado a una red diferente de la que usa la RPI) se tiene acceso a la VPN que corre en la RPI (se puede conectar desde una computadora con Windows o Ubuntu) y como queda registrado el túnel en la RPI:
En el video no se nota, pero también se puede comprobar la conexión con la VPN, viendo cómo cambia la Ip pública cuando se conecta o desconecta de la misma desde su dispositivo.

                                           Espero que esto les haya sido de mucha ayuda.
Agradezco a Ncubo por brindarme el equipo necesario para realizar el post.

Popular posts from this blog

ISTQB - Foundation Level Agile Tester Recap

ISTQB - Foundation Level Agile Tester Recap This is a summary that will help you to approve the Agile Tester certification test. 1 - Agile Software Development 1.1 - The fundamentals of Agile Software Development  The Agile Manifesto has 4 values : - Individuals and interactions over processes and tools (people-centered) - Working software over big documentations (time to market advantage) - Customer collaboration over contract negotiation (customer requirements) - Responding to change over following plan (change is more important)   The Agile Manifesto has 12 principles : - Satisfy the customer with continuous delivery - Changing requirements - Deliver software frequently (few weeks or months) - Business people and developer must work together - Build projects around motivated individuals - Face to face conversation - Working software is the primary measure of progress - The team should maintain a constant pace indefinitely - Technical excellence and good design - Simplic

RasPI Assistant: Google Assistant + Dialogflow + Raspberry Pi

Would you like to control the TV using your voice without spend a lot of money? ... Amazing right?. So, in this post, I will teach you how to do that and more. Some of my dreams always have been control things without touch them, for example: the television, due to tired to raise the hand to change the channel. So ... let's create a device that can do this action automatically. What things will we need? First, I should understand the problem and be aware about it. For example: if we want to control a TV that is not smart, how will we do that? ... a possibility is to send infrared signals (IR) to transmit the events that the person's desire. Also, if I want that the device can hear me, I may need a microphone. Additionally, it should have a speaker to talk with the people. Further, I will need a database to save all the information, APIs that can help me with the smart logic and cheap electronic components like a Raspberry Pi , resistors, leds, wires an

How to create a simple Chatbot?

Developing an amazing Chatbot ... What is a Chatbot? First to understand how it works, you need to know how it was originated and some algorithms  like  the Natural Language Processing (NLP). It is another AI area, but it is around the language (usually written), it is the component that bridges the gap between human conversation and understanding programmed by a computer. NLP allows the computer to interpret the vast and complicated human language, understand it, process it, and effectively "speak", just like humans. Through the process, the machine has to understand all the jargon that is being using and developing or adapting with the ability to respond, as a human computer. NLP has to do with the creation of systems that process or "understand" the language to perform certain tasks, such as answering questions, analyzing the sentiment in a sentence, making translations between different languages, and another. In the past, the NLP involved a lot