Skip to content

Instantly share code, notes, and snippets.

@ouyi
Last active October 16, 2021 15:28
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 ouyi/a447d6c57fe9a32c8e5f867ae55d296d to your computer and use it in GitHub Desktop.
Save ouyi/a447d6c57fe9a32c8e5f867ae55d296d to your computer and use it in GitHub Desktop.
Setting up OpenVPN with Docker in a public cloud
# Install docker
yum check-update
curl -fsSL https://get.docker.com/ | sh
systemctl start docker
systemctl status docker
systemctl enable docker
systemctl status docker
# Set up the server-side of things
## Set up a Docker volume container
OVPN_DATA="ovpn-data"
SERVER_FQDN_OR_IP="your_server_name_or_public_ip"
docker run --name $OVPN_DATA -v /etc/openvpn busybox
## Set up the EasyRSA PKI certificate store
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig -u udp://$SERVER_FQDN_OR_IP:1194
## Generate a EasyRSA PKI certificate authority (CA)
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn ovpn_initpki
## Start the server (Note: incoming udp traffic at port 1194 shall be allowed in the firewall settings)
docker run --volumes-from $OVPN_DATA --rm -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
## Optional: To have the container running automatically at system start
docker run --volumes-from $OVPN_DATA -d --restart=always -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
# Generate client config
CLIENTNAME=laptop
OVPN_DATA=ovpn-data
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn easyrsa build-client-full $CLIENTNAME nopass
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_getclient $CLIENTNAME > $CLIENTNAME.ovpn