【问题标题】:can one instance of google clouds compute engine have multiple external ip addresses谷歌云计算引擎的一个实例可以有多个外部IP地址吗
【发布时间】:2020-08-18 04:01:45
【问题描述】:

我正在使用谷歌云计算引擎来运行一个小型 Web 服务器以及我目前正在使用免费试用版的其他一些服务器,当试用期到期时,我将升级到付费帐户,但我想在不同的 wan IP 地址我知道我可以使用不同的端口并进行转发/重定向,但我的问题是一个实例可以获取多个外部 IP,还是我需要创建/支付另一个实例以获得第二个外部 IP 地址?

【问题讨论】:

    标签: google-cloud-platform google-compute-engine


    【解决方案1】:

    是的,您可以创建具有多个外部 IP 的虚拟机实例。

    查看文档Creating instances with multiple network interfaces

    默认情况下,VPC 网络中的每个实例都有一个默认值 网络接口。使用这些说明创建额外的网络 接口。每个接口都连接到不同的 VPC 网络, 授予该实例访问 Google Cloud 中不同 VPC 网络的权限 平台(GCP)。您不能将多个网络接口连接到 相同的 VPC 网络。

    Requirements部分:

    • 您只能在创建实例时配置网络接口。
    • 在单个实例中配置的每个网络接口必须附加到不同的 VPC 网络,并且每个接口必须属于 IP 范围不与任何其他子网重叠的子网 接口。
    • 在您创建实例之前,多个接口将附加到的其他 VPC 网络必须存在。见Using VPC Networks 有关创建其他 VPC 网络的说明。
    • 您无法在不删除实例的情况下删除网络接口。

    • 每个接口都可以选择有一个外部 IP 地址。

    我尝试过创建这样的虚拟机:

    1. 创建custom VPC networks:

      $ gcloud compute networks create test-vpc-network-1 --subnet-mode=custom
      $ gcloud compute networks create test-vpc-network-2 --subnet-mode=custom
      
    2. 创建custom VPC subnets:

      $ gcloud compute networks subnets create test-subnet-1 --network=test-vpc-network-1 --region=europe-west3 --range=172.16.1.0/24
      $ gcloud compute networks subnets create test-subnet-2 --network=test-vpc-network-2 --region=europe-west3 --range=172.16.2.0/24
      
    3. reserve static external IPs(可选):

      $ gcloud compute addresses create test-static-ip-1 --region=europe-west3
      $ gcloud compute addresses create test-static-ip-2 --region=europe-west3
      
    4. 创建虚拟机实例:

      $ gcloud compute instances create test-instance-2ip --zone=europe-west3-a --machine-type=n1-standard-1 --network-interface subnet=test-subnet-1,address=34.89.215.180 --network-interface subnet=test-subnet-2,address=35.234.123.210 --tags=test-instance-2ip --image=ubuntu-1804-bionic-v20200430 --image-project=ubuntu-os-cloud --boot-disk-device-name=test-instance-2ip
      

      这里是具有 2 个外部 IP 的 VM 实例:

      NAME               ZONE            MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP            EXTERNAL_IP                   STATUS
      test-instance-2ip  europe-west3-a  n1-standard-1               172.16.1.3,172.16.2.2  XXX.89.XXX.180,XXX.234.XXX.210  RUNNING
      
    5. 别忘了create firewall rules:

      $ gcloud compute firewall-rules create test-instance-2ip-vpc-1 --direction=INGRESS --priority=900 --network=test-vpc-network-1 --action=ALLOW --rules=tcp,udp --source-ranges=0.0.0.0/0 --target-tags=test-instance-2ip
      $ gcloud compute firewall-rules create test-instance-2ip-vpc-2 --direction=INGRESS --priority=900 --network=test-vpc-network-2 --action=ALLOW --rules=tcp,udp --source-ranges=0.0.0.0/0 --target-tags=test-instance-2ip
      

      以上规则仅供参考。

    另外,请看第三者example

    另外,您可以尝试Protocol forwarding

    您可以设置多个转发规则以指向单个目标 例如,允许您使用多个外部 IP 地址与一个 虚拟机实例。您可以在可能想要投放的场景中使用它 仅来自一个 VM 实例的数据,但通过不同的外部 IP 地址。这对于设置 SSL 虚拟特别有用 托管。

    【讨论】:

    • 谢谢,这正是我想做的,我找不到用于创建 VPC 子网的区域列表你知道我在哪里可以找到所有可用区域的列表吗?
    • 感谢您的确认。如果对您有帮助,请接受或支持我的回答。当然,请查看文档 Regions and Zones 部分 Locations
    • 我已经接受了你的回答,但是当我尝试运行命令来创建实例时它给出了一个错误我已将区域更改为 us-east1 如何找到用于该 reagin 的 IP 地址?错误:- 字段“resource.networkInterfaces[0].accessConfigs[0].natIP”的值无效:“34.89.215.180”。在区域“us-east1”中找不到指定的外部 IP 地址“34.89.215.180”。
    • 我发现地址参数删除后仅适用于静态IP,现在它可以工作了
    • 太棒了!在我的示例中,我使用了静态 IP,但这不是必需的。您可以在文档Creating instances with multiple network interfaces 中找到更多示例。
    猜你喜欢
    • 2019-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 2020-05-05
    • 1970-01-01
    相关资源
    最近更新 更多