谷歌云代理商:如何配置谷歌云服务器的NAT网关?

190 阅读2分钟

准备工作

  1. 登录Google Cloud Console:访问Google Cloud Console
  2. 并使用您的Google账户登录。
  3. 选择或创建项目:在Google Cloud Console中,选择或创建一个项目。
  4. 启用Compute Engine API:确保Compute Engine API已启用。
  5. 获取IAM权限:确保您拥有roles/compute.networkAdmin角色,以便创建和管理NAT网关。

创建Cloud Router

  1. 在Google Cloud Console中

    • 导航到 “网络服务” > “Cloud Router”
    • 点击 “创建 Cloud Router”
    • 输入路由器名称,选择网络和区域,然后点击 “创建”
  2. 使用gcloud命令行工具

    bash

    gcloud compute routers create ROUTER_NAME \
        --network=NETWORK --region=REGION
    

    替换以下内容:

    • ROUTER_NAME:Cloud Router的名称。
    • NETWORK:用于创建Cloud Router的VPC网络。
    • REGION:要创建Cloud Router的区域。

创建公共NAT网关

  1. 在Google Cloud Console中

    • 导航到 “网络服务” > “Cloud NAT”
    • 点击 “开始使用”“创建 Cloud NAT 网关”
    • 输入网关名称。
    • “NAT类型” 字段中,选择 “公共”
    • “选择 Cloud Router” 部分中,选择或创建Cloud Router。
    • “Cloud NAT 映射” 部分,确保选择了 “虚拟机实例、GKE 节点、无服务器” 选项。
    • 点击 “创建”
  2. 使用gcloud命令行工具

    bash

    gcloud compute routers nats create NAT_CONFIG \
        --router=NAT_ROUTER \
        --region=REGION \
        --auto-allocate-nat-external-ips \
        --nat-all-subnet-ip-ranges
    

    替换以下内容:

    • NAT_CONFIG:NAT配置的名称。
    • NAT_ROUTER:Cloud Router的名称。
    • REGION:要使用Cloud NAT的区域。

创建专用NAT网关

  1. 在Google Cloud Console中

    • 导航到 “网络服务” > “Cloud NAT”
    • 点击 “开始使用”“创建 Cloud NAT 网关”
    • 输入网关名称。
    • “NAT类型” 字段中,选择 “专用”
    • 选择VPC网络和区域。
    • 选择或创建Cloud Router。
    • “来源” 列表中,选择 “自定义” ,并选择要执行NAT的子网。
    • 点击 “添加规则” ,配置NAT规则。
    • 点击 “创建”
  2. 使用gcloud命令行工具

    bash

    gcloud compute routers nats create NAT_CONFIG \
        --router=ROUTER_NAME --type=PRIVATE --region=REGION \
        --nat-custom-subnet-ip-ranges=SUBNETWORK:ALL
    

    替换以下内容:

    • NAT_CONFIG:NAT配置的名称。
    • ROUTER_NAME:Cloud Router的名称。
    • REGION:要使用Cloud NAT的区域。
    • SUBNETWORK:要为其使用NAT的子网名称。

验证和管理NAT网关

  • 查看NAT网关:在Google Cloud Console中,导航到 “网络服务” > “Cloud NAT” ,查看已创建的NAT网关。
  • 更新NAT配置:使用Google Cloud Console或gcloud命令行工具更新NAT配置,例如更改与NAT关联的子网或更新NAT规则。
  • 删除NAT网关:在Google Cloud Console中,选择要删除的NAT网关,点击 “删除”