Created
December 5, 2015 02:15
-
-
Save whophil/a3a5dc5d752960eb4205 to your computer and use it in GitHub Desktop.
Complete setup of a containerized OpenVPN server based on kylemanna/openvpn.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# This script creates the configuration for an OpenVPN server (in Docker) | |
# and runs it. A client configuration file is saved OVPN_CLIENT_FILENAME. | |
# The OpenVPN docker container creates a volume container with the name | |
# given by OVPN_DATA_NAME. The OpenVPN server docker is exposed on the port | |
# OVPN_EXTERNAL_PORT. | |
OVPN_DATA_NAME="ovpn-data" | |
OVPN_SERVER_HOSTNAME="udp://pups.ddns.net" | |
OVPN_SERVER_NAME="pups" | |
OVPN_CLIENT_FILENAME="./pups-client-config.ovpn" | |
OVPN_EXTERNAL_PORT=1194 | |
# create a docker volume container to store openvpn data, based on busybox | |
docker run --name $OVPN_DATA_NAME -v /etc/openvpn busybox | |
# generate OpenVPN configuration | |
docker run --volumes-from $OVPN_DATA_NAME --rm kylemanna/openvpn ovpn_genconfig -u $OVPN_SERVER_HOSTNAME | |
# create keys | |
docker run --volumes-from $OVPN_DATA_NAME --rm -it kylemanna/openvpn ovpn_initpki | |
# run the OpenVPN server container with appropriate ports passed through | |
docker run --volumes-from $OVPN_DATA_NAME -d -p $OVPN_EXTERNAL_PORT:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn | |
# create a client configuration | |
docker run --volumes-from $OVPN_DATA_NAME --rm -it kylemanna/openvpn easyrsa build-client-full $OVPN_SERVER_NAME nopass | |
# save the client configuration to a file | |
docker run --volumes-from $OVPN_DATA_NAME --rm kylemanna/openvpn ovpn_getclient $OVPN_SERVER_NAME > $OVPN_CLIENT_FILENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment