tomcat - Google Cloud VM 实例如何打开 IP 转发

标签 tomcat google-cloud-platform google-compute-engine

我在 Compute Engine 中设置了一个 Google Cloud VM 实例。我使用 Windows Server 2016 作为镜像。创建 VM 实例后,我可以看到相同的详细信息。在网络接口(interface)下的详细信息页面上,我可以看到我的外部 IP 和内部 IP。但是我看到 IP 转发已关闭。

enter image description here

如何开启它?

我想实现的目标如下:

  1. 在 Google Cloud VM 实例 Windows Server 上,我安装了 Tomcat 7。
  2. 我已经在 Tomcat 中部署了一个 war 文件 (REST API)。
  3. 我想从我的本地机器访问这个 REST API。
  4. 如果我错了请纠正我,但我正在尝试访问它 以下方式:

    4.1 From local machine access GC VM Instance External IP 
    
    4.2 Then using IP forwarding my request should be forwarded to GC VM Instance Internal IP port 8080
    
    4.3 On Internal IP port 8080 Tomcat serves the request
    

请告诉我我的方法是否正确以及如何实现?如果不是请建议我应该如何去做。如果可能的话,有人可以一步一步地指导我吗?

非常感谢任何帮助。

最佳答案

Compute Engines VM 实例位于一对一 NAT 之后。公共(public) IP 替换为 VM 的内部 IP。你所描述的应该有效。确保在 Compute Engine 防火墙和本地 Windows 防火墙中都允许连接到 tomcat 端口。

屏幕截图中的“IP 转发”是允许 VM 实例发送与其任何 IP 不匹配的接收数据包。例如,这用于将 VM 设置为 NAT 网关,来自文档:

Enabling IP forwarding for instances

By default, a Compute Engine instance cannot forward a packet unless the source IP address of packet matches the IP address of the instance. Similarly, Compute Engine won't deliver a packet whose destination IP address is different than the IP address of the instance receiving the packet. However, both capabilities are required if you want to use instances to help route packets. To disable this source and destination IP check, enable the canIpForward field, which allows an instance to send and receive packets with non-matching destination or source IPs.

https://cloud.google.com/vpc/docs/using-routes#canipforward

您不需要启用 IP 转发来运行 tomcat 服务器。

关于tomcat - Google Cloud VM 实例如何打开 IP 转发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45994148/

相关文章:

google-cloud-platform - 如何将 Airflow DataFlowPythonOperator 用于梁管道?

javascript - 如何在 Google Cloud Compute node.js getVMs 中使用正则表达式进行过滤

java - Tomcat 以 war 文件作为 url 部署到远程服务器

nginx - Nginx入口 Controller 如何在Kubernetes上工作?

r - 在 Google Cloud App Engine 上部署 Shiny 的应用程序会返回错误

google-compute-engine - 如何使用 GCE Node.js 客户端从实例模板创建新的 GCE VM 实例?

google-cloud-platform - gcp 实例可以与单个网络接口(interface)一起使用的最大带宽是多少?

tomcat - Tomcat的JVM添加-D参数

java - 我想读取tomcat context.xml的参数

forms - 需要为带有 oracle 数据库的 tomcat webapp 配置一个旧的 JDBCRealm