You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GCP中对应AWS describe-network-interfaces的等效命令及类似脚本

GCP中与AWS aws ec2 describe-network-interfaces 的等效命令

GCP里对应的命令是gcloud compute network-interfaces list,你可以通过过滤条件精准查询:

  • 按VPC过滤:gcloud compute network-interfaces list --filter="network=[VPC_NAME]"
  • 按内部IP过滤:gcloud compute network-interfaces list --filter="networkIP=10.0.0.5"
  • 格式化输出指定字段:gcloud compute network-interfaces list --filter="network=my-vpc" --format="value(name, networkIP, externalIP, instance)"
等效于AWS VPC资源查询脚本的GCP版本

以下是bash脚本,可查询指定VPC下的各类网络资源,替换VPC_NAME和PROJECT_ID为你的实际值即可:

#!/bin/bash
VPC_NAME="your-vpc-name"
PROJECT_ID="your-project-id"

# 设置当前操作的GCP项目
gcloud config set project $PROJECT_ID

echo "=== 互联网路由(等效AWS Internet Gateway) ==="
gcloud compute routes list --filter="network=$VPC_NAME AND destRange=0.0.0.0/0" --format="value(name, nextHopGateway)"

echo -e "\n=== 子网 ==="
gcloud compute subnets list --filter="network=$VPC_NAME" --format="value(name, region, ipCidrRange)"

echo -e "\n=== 路由表 ==="
gcloud compute routes list --filter="network=$VPC_NAME" --format="value(name, destRange, nextHop)"

echo -e "\n=== 防火墙规则(等效AWS Security Group/Network ACL) ==="
gcloud compute firewall-rules list --filter="network=$VPC_NAME" --format="value(name, direction, allowed, sourceRanges)"

echo -e "\n=== VPC对等连接 ==="
gcloud compute networks peerings list --filter="network=$VPC_NAME" --format="value(name, peerNetwork, state)"

echo -e "\n=== VPC端点(Private Service Connect) ==="
gcloud compute forwarding-rules list --filter="network=$VPC_NAME AND targetType=PRIVATE_SERVICE_CONNECT" --format="value(name, targetService, region)"

echo -e "\n=== NAT网关 ==="
# 遍历所有区域查询云路由器NAT配置
REGIONS=$(gcloud compute regions list --format="value(name)")
for region in $REGIONS; do
    echo "区域 $region:"
    gcloud compute routers nats list --router-region $region --filter="network=$VPC_NAME" --format="value(name, router, natIpAllocateOption)"
done

echo -e "\n=== 虚拟机实例 ==="
gcloud compute instances list --filter="networkInterfaces.network=$VPC_NAME" --format="value(name, zone, networkInterfaces.networkIP)"

echo -e "\n=== VPN隧道 ==="
gcloud compute vpn-tunnels list --filter="network=$VPC_NAME" --format="value(name, region, peerIp, targetVpnGateway)"

echo -e "\n=== VPN网关 ==="
gcloud compute target-vpn-gateways list --filter="network=$VPC_NAME" --format="value(name, region, network)"

echo -e "\n=== 网络接口 ==="
gcloud compute network-interfaces list --filter="network=$VPC_NAME" --format="value(name, networkIP, externalIP, instance)"

说明

  • GCP资源模型和AWS有差异:比如没有独立的Internet Gateway,VPC通过路由表中的默认路由(0.0.0.0/0)实现互联网访问;防火墙规则同时承担了AWS中安全组和网络ACL的部分功能。
  • 脚本用--format="value(...)"精简输出,和原AWS脚本的grep逻辑一致,只展示关键字段。

内容的提问来源于stack exchange,提问作者Paku

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 02:54:35