【问题标题】:Setting a static outbound / source IP address on Google Compute Engine在 Google Compute Engine 上设置静态出站/源 IP 地址
【发布时间】:2018-03-19 20:24:26
【问题描述】:

我为 Google Compute Engine VM 实例设置了一个静态外部 IP 地址,当我通过 SSH 连接到机器时,我的出站请求(例如 curl canhazip.com)来自静态外部 IP,但是当我启动 Google Cloud 时从控制台内或当我部署应用程序时(例如,通过 gcloud app deploy 的 Python 应用程序,IP 地址是不同的。关于如何使其保持一致的任何想法?我是否需要在 app.yaml 中指定某些内容?在其他换句话说,如果我想部署一个看起来像这样的 Python 应用程序:

import requests

print('requesting...')
res = requests.get("http://ip.jsontest.com/")
print(res.text)

如何将其配置为始终返回我已设置的相同静态外部 IP?

【问题讨论】:

    标签: python google-compute-engine


    【解决方案1】:

    Cloud Shell 和 App Engine 都没有直接的网络访问权限。

    • 对于 Cloud Shell,有 limitations to network access。由于 Cloud Shell 是 ephemeral instance,因此您无法进一步控制所使用的 IP 地址等内容。

    • App Engine 标准版在没有网络访问权限的情况下运行沙盒环境。应用程序必须使用Sockets or URLFetch API 来发出外部请求。 python 运行时修补套接字和 urllib,以便大多数 python 代码无需进一步修改即可使用这些 API。

    如果您需要一致的源 IP 地址用于传出连接,您可能会寻找egress NAT gateway。但是,此设置也不能在 Cloud Shell 或 App Engine Standard 中使用。

    【讨论】:

      猜你喜欢
      • 2020-09-18
      • 2019-06-21
      • 2016-01-18
      • 2021-04-14
      • 2018-07-25
      • 1970-01-01
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多