Skip to content

Instantly share code, notes, and snippets.

@whophil
Created December 5, 2015 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whophil/a3a5dc5d752960eb4205 to your computer and use it in GitHub Desktop.
Save whophil/a3a5dc5d752960eb4205 to your computer and use it in GitHub Desktop.
Complete setup of a containerized OpenVPN server based on kylemanna/openvpn.
#!/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