Last active
December 12, 2020 22:58
-
-
Save devlifeX/396b2efae8c72ab589c50a4251788e4a to your computer and use it in GitHub Desktop.
Easy Setup And Run OpenVPN Server with docker compose, Using Same profile for multiple connections. Easy Setup! Enjoy :)
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
# Requiremnts: Docker, Docker Compose a Server with 256 MB Of RAM. | |
# If you neeed Install docker and docker compose on ubuntu (tested on ubuntu 16) use this gist: https://gist.github.com/devlifeX/be64df7608e08853aad995c65872df59 | |
# 1) Put the content in ovpn.sh | |
# 2) chmod +x ovpn.sh | |
# 3) execute like this: ./ovpn.sh xxx.xxx.xxx.xxx (xxx's is your ip or domain address) | |
BASE=/home/$(whoami) | |
CONFIG="$BASE/openvpn-data/conf/openvpn.conf" | |
mkdir -p $BASE | |
cd $BASE | |
cat <<EOT >> docker-compose.yml | |
version: '2' | |
services: | |
openvpn: | |
cap_add: | |
- NET_ADMIN | |
image: kylemanna/openvpn | |
container_name: openvpn | |
ports: | |
- "1194:1194/udp" | |
restart: always | |
volumes: | |
- ./openvpn-data/conf:/etc/openvpn | |
EOT | |
docker-compose run --rm openvpn ovpn_genconfig -u udp://"$1" | |
docker-compose run --rm openvpn ovpn_initpki | |
sudo chown -R $(whoami): ./openvpn-data | |
docker-compose up -d openvpn | |
export CLIENTNAME="dariush" | |
docker-compose run --rm openvpn easyrsa build-client-full $CLIENTNAME | |
docker-compose run --rm openvpn ovpn_getclient $CLIENTNAME > $CLIENTNAME.ovpn | |
echo " | |
push \"redirect-gateway def1\" | |
client-to-client | |
duplicate-cn | |
" >> $CONFIG | |
docker-compose down && docker-compose up -d | |
echo ">>>>>>>>DONE<<<<<<<<<" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment