-
-
Save CenoX/98ce9b32806aabc40c452658ebd55fd6 to your computer and use it in GitHub Desktop.
VPN Server for Google 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
#!/bin/bash | |
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1) | |
SERVER_NAME=vpn-$NEW_UUID | |
gcloud compute instances create $SERVER_NAME \ | |
--machine-type "e2-micro" \ | |
--image-family ubuntu-2004-lts \ | |
--image-project "ubuntu-os-cloud" \ | |
--boot-disk-size "10" \ | |
--boot-disk-type "pd-ssd" \ | |
--boot-disk-device-name "$NEW_UUID" \ | |
--tags https-server,http-server \ | |
--zone asia-northeast3-a \ | |
--labels ready=true \ | |
--can-ip-forward \ | |
--metadata startup-script='#! /bin/bash | |
sudo su - | |
cd /root | |
echo "deb https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.2 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.2.list | |
echo "deb https://repo.pritunl.com/stable/apt focal main" > /etc/apt/sources.list.d/pritunl.list | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv E162F504A20CDF15827F718D4B7C549A058F8B6B | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 7568D9BB55FF9E5287D586017AE645C0CF8E292A | |
apt update -y | |
apt install -y pritunl mongodb-server | |
systemctl start pritunl mongodb | |
systemctl enable pritunl mongodb | |
# Collect setup key | |
echo "setup key follows:" | |
pritunl setup-key | |
' | |
IP=$(gcloud compute instances describe $SERVER_NAME --zone asia-northeast3-a | grep natIP | cut -d: -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') | |
gcloud beta compute firewall-rules create vpn-allow-8787-$NEW_UUID --allow tcp:8787 --network default --priority 65535 --source-ranges $IP/32 | |
gcloud beta compute firewall-rules create vpn-allow-3838-$NEW_UUID --allow tcp:3838 --network default --priority 65535 --source-ranges $IP/32 | |
echo "VPN server will be available for setup at https://$IP in a few minutes." |
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/bash | |
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 4 | head -n 1) | |
SERVER_NAME=vpn-$NEW_UUID | |
gcloud compute instances create $SERVER_NAME \ | |
--machine-type "g1-small" \ | |
--image-family ubuntu-1604-lts \ | |
--image-project "ubuntu-os-cloud" \ | |
--boot-disk-size "10" \ | |
--boot-disk-type "pd-ssd" \ | |
--boot-disk-device-name "$NEW_UUID" \ | |
--tags https-server,http-server \ | |
--zone asia-northeast1-a \ | |
--labels ready=true \ | |
--can-ip-forward \ | |
--metadata startup-script='#! /bin/bash | |
sudo su - | |
cd /root | |
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" > /etc/apt/sources.list.d/mongodb-org-3.2.list | |
echo "deb http://repo.pritunl.com/stable/apt xenial main" > /etc/apt/sources.list.d/pritunl.list | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 42F3E95A2C4F08279C4960ADD68FA50FEA312927 | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 7568D9BB55FF9E5287D586017AE645C0CF8E292A | |
apt-get update -y | |
apt-get install pritunl mongodb-org -y | |
systemctl start pritunl mongod | |
systemctl enable pritunl mongod | |
# Collect setup key | |
echo "setup key follows:" | |
pritunl setup-key | |
' | |
IP=$(gcloud compute instances describe $SERVER_NAME --zone asia-northeast1-a | grep natIP | cut -d: -f2 | sed 's/^[ \t]*//;s/[ \t]*$//') | |
gcloud beta compute firewall-rules create vpn-allow-8787-$NEW_UUID --allow tcp:8787 --network default --priority 65535 --source-ranges $IP/32 | |
gcloud beta compute firewall-rules create vpn-allow-3838-$NEW_UUID --allow tcp:3838 --network default --priority 65535 --source-ranges $IP/32 | |
echo "VPN server will be available for setup at https://$IP in a few minutes." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment