Sign inSign up

eidansoft/openvpn

By eidansoft

•Updated over 6 years ago

Easy to use openvpn server with a all-in-one configuration script

Image
0

1.2K

eidansoft/openvpn repository overview

⁠OpenVPN server running on a Docker container

This project let you create a OpenVPN server onto a machine (PC or even just a simple RaspberryPi), and connect to it from outside your network using your laptop or mobile phone giving you access to all resources into your local network with less than 11Mb.

⁠Brief explanation

You will need a machine to act as a VPN server inside your network, and the clients you wanna get connected to your network. Also you will need to generate the certificates and keys to get the clients been identified at the server.

This Docker image will provide you:

  • A easy-to-use wizard to create the VPN server configuration and the keys/certificates needed.
  • The VPN Server code (based on OpenVPN) to be run at your server (PC or RaspberryPi) onto your network.
  • The *.ovpn configuration file to get the OpenVPN client (your PC or mobile phone) connected to the VPN (from outside your local network). There are several clients available for free compatible with the standard OpenVPN protocol⁠, for example for the Laptop I use TunnelBlick⁠ and at the mobile phone I use the OpenVPN Connect⁠.

⁠Manual of use

The first step is to generate all configuration files and keys, you can do it with the wizard 'openvpn_configure.sh'. I strongly recommend you to create this stuff at your laptop, because the generation of the keys takes lot of time at the RaspberryPi. So you can generate the configuration at your PC and later use that configuration files at the RaspberryPi.

⁠Launch the configuration wizard

The wizard will let you generate all configuration files easily, you just need to follow the instructions to provide:

  • The Domain you will use (you can get one for free at No-Ip⁠ if you don't have one)
  • The port you will use. You will need to open the selected port at your router and redirect all the traffic to your VPN Server machine IP. If you don't know what port use, just left the default one 1196.
  • The protocol to use. You can decide to use TCP or UDP, if you don't know what's better fits your needs, you can just left the default one UDP. If your VPN Server will be connected to the network by WiFi probably you will get better results with TPC.
  • Some Certificate Authority params like your location, email and other stuff, but those data can be faked if you prefer do not provide real info.

You can launch the configuration wizard with the command below, you just need to provide a volume (mounted onto /mnt) with the path where the files will be saved:

docker run -it --name configuration --rm -v /path_to_folder/where_save/config:/mnt eidansoft/openvpn openvpn_configure.sh

The wizard will configure the following files:

  • At the openvpn_client.conf file will set the domain and the port you want to use for your server.
  • At the ca_conf.properties file will set the values for the CA, like your city, company name, mail, etc. Also here is the size of the keys to be used. If you don't provide a value, then the default one will be used, 4096.

And also it will call the scripts to generate all keys:

  • Initialize the OpenVPN server certificates, keys and configurations.

    openvpn_server_init.sh <SERVER_NAME>

  • Initialize the OpenVPN CA certificates and keys.

    openvpn_ca_init.sh <SERVER_NAME>

  • Initialize the OpenVPN Client certificates, keys and configuration files.

    openvpn_client_init.sh <CLIENT_NAME>

The last step of the wizard is to generate the Client keys and configuration files, for this step you only need to provide a name to identify it. And you can create as many clients as you need.

Once the wizard finished you have all needed files generated and saved at the volume you set before. To be specific, you will have four folders:

  • files_ca - this folder contains all keys and certificates for your CA.
  • files_svr - this folder contains all keys and certificates for your OpenVPN server.
  • files_clients - this folder contains a folder for each client you have created. Inside those folders you will have the keys, certificates and configurations files for your clients. To be concrete the important file here is the *.ovpn file, that's the file you will need to provide to the VPN Client at your phone or your laptop.
  • files_openvpn - this folder contains the configuration files for your OpenVPN server. This is the folder you will need to copy to the VPN Server machine (in case you are generating the files in another one) like the RaspberryPi.

So in summary, you only need to copy to your RaspberryPi the files_openvpn folder. You can do this easely with scp, for example:

$ scp -r /path/to/files_openvpn pi@raspberryIP:/home/pi

⁠Start the container and run the OpenVPN service

Once you have the files_openvpn folder at your VPN Server machine, you are ready to start the VPN service. You can start it directly with below command:

sudo docker run -d --name openvpn --privileged -v /PATH/TO/files_openvpn:/mnt -p 1194:1194/udp --restart unless-stopped eidansoft/openvpn

If you prefer to start the service with a docker-compose is also possible:

version: '3.5'
  vpn:
    container_name: vpn
    image: eidansoft/openvpn
    privileged: true
    restart: unless-stopped
    ports:
      - "1194:1194/udp"
    volumes:
      - "/PATH/TO/files_openvpn/:/mnt/files_openvpn/"

The logs are available with:

sudo docker logs openvpn

⁠Stop the container with the OpenVPN service

sudo docker rm -f openvpn

⁠What if later I want to add another client?

You can create as much clients as you need (if you have the configuration already created), just call the client generator script passing it the name to identify your new client.

docker run -it --name configuration --rm -v /PATH/TO/ALL/CONFIG_FOLDERS:/mnt eidansoft/openvpn openvpn_client_init.sh <CLIENT_NAME>

⁠Known bugs

I have suffered some issues when the VPN Server is running on a RaspberryPi connected through WiFi. The problem got fixed when you use TCP instead UDP. So if you wanna run the VPN Server into a machine connected by WiFi, choose TCP at the configurations steps.

Tag summary

Content type

Image

Digest

Size

5.6 MB

Last updated

over 6 years ago

docker pull eidansoft/openvpn