Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Unable to open socket on port

I have a VM running a postgresql server on port 5432 and want to connect this to my local machine to access PGadmin4 on my computer, so that I can import/export data back and forth. 

However, when I try connecting to this on my terminal:

gcloud compute start-iap-tunnel <instance> 5432 \

    --local-host-port=localhost:5432 \

    --zone=us-east4-c

 

I get the following error:

>

ERROR: (gcloud.compute.start-iap-tunnel) Unable to open socket on port [5432].

 

I have configured my firewalls with the following:

IP-ranges: 35.235.240.0/20

tcp: 5432

0 1 1,915
1 REPLY 1

I suggest double checking if the port is already listening  with the following command inside of your VM instance: sudo netstat -lntup   Please note that the  postgresql service should be up and running in order to get an answer from the TCP port 5432. Once said that, please review that your firewall rule has the port tcp:5432 allowed like in the followed example:

    gcloud compute firewall-rules create allow-postgresql-ingress-from-iap \

  --direction=INGRESS \

  --action=allow \

  --rules=tcp:5432 \

  --source-ranges=35.235.240.0/20


The port should be allowed on both sides, (local desktop and the VM instance). In this guide, you will find more info about how tunneling tcp connections with other ports in GCP .