Last active
October 16, 2021 15:28
-
-
Save ouyi/a447d6c57fe9a32c8e5f867ae55d296d to your computer and use it in GitHub Desktop.
Setting up OpenVPN with Docker in a public cloud
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-centos-7
https://www.digitalocean.com/community/tutorials/how-to-run-openvpn-in-a-docker-container-on-ubuntu-14-04
https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-18-04