Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ssh port forwarding google compute engine

I am trying to forward traffic with google instances but no luck. Here is the scenario: I have 2 instances currently main-server, and mini-server-1 I want to ssh mini-server-1 from main-server and create a dynamic port forwarding like so:

gcloud compute ssh "mini-server-1" --zone="us-central1-f" --ssh-flag="-D:5551" --ssh-flag="-N" --ssh-flag="-n" &

I have this error:

bind: Cannot assign requested address

I tried: ssh -N username@mini-server-1(all ips internal external, hostname) -D 5551 &

When i run netstat i can see that ports are free. Here is wget with proxy from main-server

wget google.com -e use_proxy=yes -e http_proxy=127.0.0.1:5551

Connecting to 127.0.0.1:5551... connected.
Proxy request sent, awaiting response...

Does someone know how can i achieve this?

like image 407
user3057678 Avatar asked Dec 04 '14 12:12

user3057678


People also ask

How do I port forward for GCP?

GCP doesn't offer port forwarding unless you run your API in the Kubernetes cluster - only then you can expose it as a service on a port you choose. You can also run your API on a non standard ports (if it allows it) or use iptables (assuming you're running Linux) to redirect all queries from 30433 to 433.

How do I SSH into my GCE without a public IP?

To connect to an instance without an external IP address, use the gcloud compute ssh command with the --internal-ip flag. In the Google Cloud console, go to the VM Instances page and find the internal IP address for the instance that you want to connect to. Connect to the instance.

How do I SSH from one VM to another in GCP?

Connect through a browser from the GCP MarketplaceBrowse to the Google Cloud Platform console and sign in if required using your Google account. Find and select your project in the project list. Select the “Compute -> Compute Engine” menu item. Locate your server instance and select the SSH button.


2 Answers

Much simpler syntax:

gcloud compute ssh my-vm-name --zone=europe-west1-b -- -NL 4000:localhost:4000

You can pass as many options as you want:

-NL 8080:localhost:80 -NL 8443:localhost:443
  • https://cloud.google.com/solutions/connecting-securely
  • https://cloud.google.com/community/tutorials/ssh-tunnel-on-gce
  • https://cloud.google.com/community/tutorials/ssh-port-forwarding-set-up-load-testing-on-compute-engine
like image 186
gavenkoa Avatar answered Sep 25 '22 00:09

gavenkoa


run the command with the debug flag to help you find more information:

gcloud compute ssh --ssh-flag=-vvv "mini-server-1" \
                   --zone="us-central1-f" \
                   --ssh-flag="-D:5551" \
                   --ssh-flag="-N" \
                   --ssh-flag="-n" &

and as mention in my comment before, use https_proxy.

like image 36
Marilu Avatar answered Sep 26 '22 00:09

Marilu