我有2谷歌计算引擎实例,我想在两个实例中打开端口9090。我认为我们需要添加一些防火墙规则。

你能告诉我该怎么做吗?


当前回答

我不得不通过降低优先级(使其更高)来解决这个问题。这立即引起了反应。跟我想的不一样,但成功了。

其他回答

下面是回答这个问题的命令行方法:

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>"

这将为您指定的实例打开端口9090。省略——source-tags和——source-ranges将该规则应用于所有实例。更多细节在Gcloud文档和firewall-rule创建命令手册中

前面的答案很好,但是谷歌建议使用更新的gcloud命令而不是gcutil命令。

PS: 要了解谷歌的防火墙规则,请运行gcloud compute firewall-rules list并查看所有防火墙规则

console.cloud.google.com >>选择项目>>组网> VPC网络>>防火墙>>创建防火墙

选择“Targets”,指定目标标签,在“target tags”中输入标签名。该标记将用于将新的防火墙规则应用到您想要的任何实例上。

在“协议和端口”中输入tcp:9090

单击Save。

我不得不通过降低优先级(使其更高)来解决这个问题。这立即引起了反应。跟我想的不一样,但成功了。

你需要:

Go to cloud.google.com Go to my Console Choose your Project Choose Networking > VPC network Choose "Firewall" Choose "Create Firewall Rule" 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. Set Source IP ranges to allow traffic from all IPs: 0.0.0.0/0 To allow incoming TCP connections to port 9090, in "Protocols and Ports", check “tcp” and enter 9090 Click Create (or click “Equivalent Command Line” to show the gcloud command to create the same rule)

请参考文档自定义您的规则。

使用此命令打开端口

gcloud compute --project=<project_name> firewall-rules create firewall-rules --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:<port number> --source-ranges=0.0.0.0/0