Setup Google Console Firewall

Web Dev 1 Th12 2021

Open a specific port such as 9090 in Google Compute Engine

Google Cloud Console approach

  1. Go to cloud.google.com
  2. Go to my Console
  3. Choose your Project
  4. Choose Networking > VPC network
  5. Choose "Firewall"
  6. Choose "Create Firewall Rule"
  7. To apply the rule to select VM instances, select Targets > "Specified target tags", and enter into "Target tags" the name of the tag. This tag will be used to apply the new firewall rule onto whichever instance you'd like. Then, make sure the instances have the network tag applied.
  8. Set Source IP ranges to allow traffic from all IPs: 0.0.0.0/0
  9. To allow incoming TCP connections to port 9090, in "Protocols and Ports", check “tcp” and enter 9090
  10. Click Create (or click “Equivalent Command Line” to show the gcloud command to create the same rule)

Command-line approach

gcloud compute firewall-rules create <rule-name> --allow tcp:9090 --source-tags=<list-of-your-instances-names> --source-ranges=0.0.0.0/0 --description="<your-description-here>"

This will open the port 9090 for the instances that you name. Omitting --source-tags and --source-ranges will apply the rule to all instances. More details are in the Gcloud documentation and the firewall-rule create command manual

The previous answers are great, but Google recommends using the newer gcloud commands instead of the gcutil commands.

PS: To get an idea of Google's firewall rules, run gcloud compute firewall-rules list and view all your firewall rules

Tags

Tony Phạm

Là một người thích vọc vạch và tò mò với tất cả các lĩnh vực từ khoa học tự nhiên, lập trình, thiết kế đến ... triết học. Luôn mong muốn chia sẻ những điều thú vị mà bản thân khám phá được.