简体   繁体   English

如何在 Google Cloud 服务上找到 IPv4 地址?

[英]How do I find the IPv4 address on a Google Cloud service?

I have a Go service, deployed on Heroku, which pulls the IPv4 address from the request header successfully.我有一个 Go 服务,部署在 Heroku 上,它成功地从请求 header 中提取了 IPv4 地址。

ip := net.ParseIP(strings.Split(r.Header.Get("X-Forwarded-For"), ",")[0]).String()

I have deployed the identical code as a service to Google Cloud, and the IP addresses are frequently IPv6 in about 25% of the time.我已将相同的代码作为服务部署到 Google Cloud,IP 地址通常在大约 25% 的时间内是 IPv6。 After examining the full Request Header, there is no IPv4 address available anywhere, only IPv6.在检查完整的请求 Header 后,没有任何可用的 IPv4 地址,只有 IPv6。

Heroku's Request Header X-Forwarded-For ALWAYS contains the IPv4 address, yet Google Cloud doesn't. Heroku 的请求 Header X-Forwarded-For 始终包含 IPv4 地址,但 Google Cloud 不包含。 Does anyone know a way to force the IPv4 format for Request Headers in Google Cloud?有谁知道在谷歌云中为请求标头强制使用 IPv4 格式的方法?

Clients can connect via IPv4 or IPv6 but not both.客户端可以通过 IPv4 或 IPv6 连接,但不能同时连接。 Only one address family will be used by the client and only one IP address will be recorded by the proxy.客户端只会使用一个地址族,代理只会记录一个 IP 地址。

Additional information:附加信息:

  1. Heroku does not support IPv6 so clients are forced to connect using IPv4. Heroku 不支持 IPv6,因此客户端被迫使用 IPv4 进行连接。 reference 参考

  2. If you only want IPv4 connections, do not enable the IPv6 frontends.如果您只需要 IPv4 连接,请不要启用 IPv6 前端。 However, I recommend using IPv6 where possible.但是,我建议尽可能使用 IPv6。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定 AWS 中的 su.net IPv4 CIDR 地址 - How to determine subnet IPv4 CIDR address in AWS 如何更改与谷歌云项目关联的 email 地址? - How do I change the email address associated with a google cloud project? Google App Engine 上的 IPv6 到 IPv4 - IPv6 to IPv4 on Google App Engine 如何从 IPV6 地址连接到 GCP(谷歌云平台)云 SQL 实例? - How to connect to a GCP (Google Cloud Platform) Cloud SQL instance from an IPV6 address? 如何让我的 Google-service.json 在 Google Cloud Plataform 中与 Firestore 一起使用? - How do I get my Google-service.json working with Firestore inside Google Cloud Plataform? 如何使用 GORM 在 postgresql 中存储 ipv4 和 ipv6 地址 - How to store ipv4 and ipv6 addresses in postgresql using GORM 如何在 python 程序中定义我的 Google Cloud Platform 服务帐户的密钥? - How do I define my Google Cloud Platform service account's key in a python program? 在谷歌云 Kube.netes 集群中,我的 pod 有时会全部重启,我如何找到重启的原因? - in a google cloud Kubernetes cluster my pods sometimes all restart, how do I find the reason for the restart? 无法为 Google Cloud VM 的 IPv6 地址设置 PTR 记录 - Can't set PTR record for IPv6 address for Google Cloud VM Google Cloud Platform - 计费,如何找到正在收费的产品实例的名称? - Google Cloud Platform - Billing, how do I find the name of the instance of a product that is costing money?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM