3.6. 为私有 Google 访问创建私有域名系统记录
私有域名系统(DNS)区通过确保流量永远不会通过公共互联网来优化您的资源连接到 Google API 的方式。它的功能通过截获 Google 服务的 DNS 请求,并将它们解析为私有 IP 地址,强制连接到 Google 的内部网络,以便更快地进行数据交换。
运行以下命令,为 googleapis.com 域创建私有 DNS 区域:
gcloud dns managed-zones create ${prefix}-googleapis \ --visibility=private \ --networks=https://www.googleapis.com/compute/v1/projects/${project_id}/global/networks/${prefix}-vpc \ --description="Private Google Access" \ --dns-name=googleapis.com$ gcloud dns managed-zones create ${prefix}-googleapis \ --visibility=private \ --networks=https://www.googleapis.com/compute/v1/projects/${project_id}/global/networks/${prefix}-vpc \ --description="Private Google Access" \ --dns-name=googleapis.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令开始记录设置事务:
gcloud dns record-sets transaction start \ --zone=${prefix}-googleapis$ gcloud dns record-sets transaction start \ --zone=${prefix}-googleapisCopy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令,将 Google API 的 DNS 记录暂存在 googleapis.com 域下:
gcloud dns record-sets transaction add --name="*.googleapis.com." \ --type=CNAME restricted.googleapis.com. \ --zone=${prefix}-googleapis \ --ttl=300$ gcloud dns record-sets transaction add --name="*.googleapis.com." \ --type=CNAME restricted.googleapis.com. \ --zone=${prefix}-googleapis \ --ttl=300Copy to Clipboard Copied! Toggle word wrap Toggle overflow gcloud dns record-sets transaction add 199.36.153.4 199.36.153.5 199.36.153.6 199.36.153.7 \ --name=restricted.googleapis.com. \ --type=A \ --zone=${prefix}-googleapis \ --ttl=300$ gcloud dns record-sets transaction add 199.36.153.4 199.36.153.5 199.36.153.6 199.36.153.7 \ --name=restricted.googleapis.com. \ --type=A \ --zone=${prefix}-googleapis \ --ttl=300Copy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令应用上面启动的暂存记录设置事务:
gcloud dns record-sets transaction execute \ --zone=$prefix-googleapis$ gcloud dns record-sets transaction execute \ --zone=$prefix-googleapisCopy to Clipboard Copied! Toggle word wrap Toggle overflow