How to enable access to a web service hosted on GCP VM instance

1.2k views Asked by At

I built a web app, that runs and listens on port 5000 using .netcore (default app in VS). I created a VM instance on GCP, and allowed http and https traffic in the configuration. I ran the app, and used the exteral ip(which I succeeded to ping) to access it from the browser: http://:5000

But I got no response, this should have opened the site. I added a firewall rule to allow traffic but still didn't help: enter image description here I'm sure many people encountered this, any help?

2

There are 2 answers

2
Jose Luis Delgadillo On BEST ANSWER

I have the same opinion as @Iñigo, it could be the firewall.

You can create the rule with the following command:

gcloud compute --project=my-project firewall-rules create rule-for-netcore --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:5000 --source-ranges=0.0.0.0/0

The output should be something like:

Creating firewall...⠹Created [https://www.googleapis.com/compute/v1/projects/my-project...l/firewalls/rule-for-netcore].
Creating firewall...done.
NAME              NETWORK  DIRECTION  PRIORITY  ALLOW     DENY  DISABLED
rule-for-netcore  default  INGRESS    1000      tcp:5000        False

Edit 1

Also you need to open the port in your windows firewall:

  1. From the Start menu, click Control Panel, click System and Security, and then click Windows Firewall. Control Panel is not configured for 'Category' view, you only need to select Windows Firewall.
  2. Click Advanced Settings.
  3. Click Inbound Rules.
  4. Click New Rule in the Actions window.

enter image description here

  1. Click Rule Type of Port.
  2. Click Next.
  3. On the Protocol and Ports page click TCP.
  4. Select Specific Local Ports and type a value something like 5000-5010 (this is only an example you need to add the ports needed)
  5. Click Next.
  6. On the Action page click Allow the connection.
  7. Click Next.
  8. On the Profile page click the appropriate options for your environment.
  9. Click Next.
  10. On the Name page enter a name of like “Open port for test”
  11. Click Finish.
  12. Restart the Instance.

At the end you would see the rule like this: enter image description here

You can consult the following link for more information.

1
Iñigo González On

The firewall is dropping your traffic. You should open port 5000, not http(port 80) or https(port 443).