Skip to content

How to connect to an remote server from a VM using OpenVPN

This guide walk through how to setup a VM in GCP so that it can connect to a remote server using OpenVPN.

Create a VM in GCP

  1. Create a new VM instance in Vertex AI workbench.
gcloud notebooks instances create medstreaming-eda \
  --project=trially-staging \
  --location=us-central1-a \
  --machine-type=e2-standard-4 \
  --vm-image-project=deeplearning-platform-release \
  --vm-image-family=workbench \
  --boot-disk-size=150GB \
  --boot-disk-type=pd-standard \
  --data-disk-size=100GB \
  --data-disk-type=pd-standard \
  --no-public-ip \
  --network=default \
  --subnet=default \
  --service-account=965051512294-compute@developer.gserviceaccount.com \
  --scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email \
  --tags=deeplearning-vm,notebook-instance \
  --metadata=idle-timeout-seconds=10800,disable-mixer=true,proxy-backend-id=69abeac80631c182,serial-port-logging-enable=true,shutdown-script=/opt/deeplearning/bin/shutdown_script.sh,enable-guest-attributes=TRUE,notebooks-api=PROD,disable-swap-binaries=true,enable-oslogin=TRUE,report-event-health=true,report-dns-resolution=true,notebooks-api-version=v2,proxy-mode=service_account,version=123,framework=workbench,title=workbench \
  --shielded-secure-boot \
  --shielded-vtpm \
  --shielded-integrity-monitoring \
  --labels=consumer-project-id=trially-staging,consumer-project-number=965051512294,notebooks-product=workbench-instances,resource-name=medstreaming-eda
  1. Install OpenVPN
sudo apt-get update
sudo apt-get install openvpn
  1. Configure OpenVPN:

  2. Obtain the OpenVPN configuration file (.ovpn) from the server owner.

  3. Place the .ovpn file in the /etc/openvpn/ directory inside your VM instance and ensure it has the correct permissions (e.g., sudo chmod 600 /etc/openvpn/your_config_file.ovpn).
sudo cp your_config_file.ovpn /etc/openvpn/your_config_file.ovpn
sudo chmod 600 /etc/openvpn/your_config_file.ovpn
  1. Start the OpenVPN service:
sudo systemctl start openvpn@your_config_file