Have you ever had a situation when you needed to virtually place yourself into a different city, country, or continent for whatever reason? Being a software developer and, at the same time, being very passionate about Internet and cyber security, I have such a need very often, and, therefore, the ability to quickly start reliable VPN server with a decent level of security is essential.
Nowadays, the quickest possible way to launch anything anywhere is Docker. Many hosting platforms already provide VPS with preinstalled Docker and even if it’s not the case — it’s a matter of just a couple of minutes to install it yourself. Having this said, for me it was a no-brainer that the service I needed should be a Docker image. Of course, there are thousands of such images on Docker Hub, just try to make a search by “openvpn” keyword and you will end up with more than 50 pages listing different images. But none of them sufficed my needs: they were either too complicated in setup (the most popular image requires a volume container and few “docker run” commands with different set of parameters) or lacked decent documentation, or were abandoned long ago. At some point I got tired trying to find an existing solution and decided to make my own openvpn docker image.
I began my work on the Docker-Openvpn project vigorously and kept working at a good pace all the time, though sometimes it felt like I went down the wrong way and I had to go back to the drawing board. For instance, when I realised that Ubuntu was rather a bad choice to use as a base image, I had to start everything anew with Alpine Linux. Nonetheless, the project saw the daylight very soon and now I’m very proud to present it to the wide audience.
Let me guide you through a few very simple steps to bootstrap dockerized OpenVPN server. The overall process of getting your VPS with Digital Ocean shouldn’t take longer than 3 minutes and bootstrapping the service takes just 2 seconds. So, here we go. In order to use Docker-Openvpn you have to have few things:
- Public IP address.
To keep things as simple as possible, we will be using Digital Ocean hosting provider. To highlight but some of its features:
- It provides easy access to the servers,
- It has prebuilt Linux images with Docker on board,
- It’s reasonably priced: we can get by with its cheapest instance which costs only $5 a months and yet we will be capable of lunching few more containers on the same instance.
After logging into your DO account, you will be taken into the dashboard. This is how mine looks like:
From this point, you need to hit the big green button “Create” in the top right corner. You will see the list of available options:
Click on “Droplets” item.
Go to the “Marketplace” tab and select Docker image, scroll the page down to pick a VPS of a right size. In our case, it is an instance with 1GB RAM, 1CPU and 25GB SSD storage. This should totally suffice our needs, unless we’re going to have hundreds of simultaneous connections to our server, but this goes beyond the purposes of this service.
Scroll the page down and pick the datacenter location for your server. We will use Amsterdam location in this tutorial, and, after we have the service up and running we will check that our internet IP address is in Netherlands.
Make sure to add your ssh key. This step is optional, but I highly recommend you to do so if you want to access your server via ssh the easy way.
Scroll the page further down and hit the big green button “Create Droplet”.
Your VPS — droplet, in terms of Digital Ocean — is now being created. The process shouldn’t take long — usually, up to 1 minute.
After your droplet was created it was also be assigned a public IP address. Copy it for the future use.
Now, go in your terminal window and type:
You should see the following output:
Copy and paste the snippet bellow into your terminal window:
docker run --cap-add=NET_ADMIN \ -it -p 1194:1194/udp -p 8080:8080/tcp \ -e HOST_ADDR=$(curl -s https://api.ipify.org) \ alekslitvinenk/openvpn
You will see the following output:
Now, you should be able to go to the
http:<your server's url>:8080/ and download
client.ovpn file. Use it with your favourite OpenVPN client. I prefer Tunnelblick for Mac and in my case it’s enough just to double-click this configuration file to install it.
Now, you can check your location with any whois service. It should tell you that your internet IP address is the IP address of your VPS server and you are virtually located in the area your datacenter is. In my case it should be Amsterdam:
Now you can browse the Internet safely.
If the way of downloading
client.ovpn plain HTTP doesn’t seem secure enough to you, there’s an option to download zipped archive with password protection. Just add
czp <password> option to the last line of the previous snippet, where password is the password of your choice:
docker run --cap-add=NET_ADMIN \ -it -p 1194:1194/udp -p 8080:8080/tcp \ -e HOST_ADDR=$(curl -s https://api.ipify.org) \ alekslitvinenk/openvpn czp somepassword
If you think this project is useful, please star it on GitHub https://github.com/alekslitvinenk/docker-openvpn